Skip to content

Commit 52a99c0

Browse files
committed
fix(win): work around Popup.Window bugs in context menu
On Windows the footer context menu uses Popup.Window, which trips two Qt bugs: * The "Progress in percent" MenuItem auto-toggles a second time from a spurious release event delivered while the popup is closing, leaving `checked` out of sync with the view-model. Resync `checked` from the view-model on `aboutToShow` and `closed`; the inline binding is dropped since it gets broken by the first user toggle anyway. * QTBUG-145585: Popup.Window ignores the `modal` property, so clicks pass through to widgets underneath. Add an overlay-level MpvqcFooterContextMenuClickGuard, modeled after the existing new- comment menu guard, that intercepts presses and closes the menu. Popup.Item platforms are unaffected.
1 parent 174a567 commit 52a99c0

5 files changed

Lines changed: 71 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ files = [
284284
"qt/qml/utility/MpvqcWindowUtility.qml",
285285
"qt/qml/utility/qmldir",
286286
"qt/qml/views/footer/MpvqcFooterContextMenu.qml",
287+
"qt/qml/views/footer/MpvqcFooterContextMenuClickGuard.qml",
287288
"qt/qml/views/footer/MpvqcFooterView.qml",
288289
"qt/qml/views/footer/qmldir",
289290
"qt/qml/views/footer/tst_MpvqcFooterView.qml",

qt/qml/views/footer/MpvqcFooterContextMenu.qml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,21 @@ MpvqcMenu {
7575
MenuSeparator {}
7676

7777
MenuItem {
78+
id: _percentMenuItem
7879
objectName: "percentMenuItem"
7980

8081
text: qsTranslate("MainWindow", "Progress in percent")
81-
checked: root.isPercentChecked
8282
checkable: true
8383

8484
onTriggered: root.percentToggled()
8585
}
86+
87+
// Workaround for QTBUG-145585: on Windows the Popup.Window menu can
88+
// deliver a spurious release event while closing, causing MenuItem to
89+
// auto-toggle a second time and leaving `checked` out of sync with the
90+
// view-model. Force-resync on both lifecycle edges:
91+
// - aboutToShow: pick up any external changes made while closed.
92+
// - closed: undo the spurious toggle delivered during close.
93+
onAboutToShow: _percentMenuItem.checked = root.isPercentChecked
94+
onClosed: _percentMenuItem.checked = root.isPercentChecked
8695
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-FileCopyrightText: mpvQC developers
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
// Workaround for QTBUG-145585: On Windows, Popup.Window menus do not respect
6+
// the modal property, allowing clicks to pass through to underlying items.
7+
// This item lives in the window overlay layer and intercepts every click
8+
// while the footer context menu is open, closing it and swallowing the event
9+
// so nothing underneath reacts.
10+
//
11+
// The _menuOpen flag is cleared via Qt.callLater instead of directly in
12+
// onClosed because the signal is delivered immediately; without the deferral
13+
// the overlay would be gone before the click arrives.
14+
//
15+
// TODO: Remove this file when Qt fixes QTBUG-145585.
16+
17+
import QtQuick
18+
import QtQuick.Controls
19+
20+
Item {
21+
id: root
22+
23+
required property var menu
24+
25+
property bool _menuOpen: false
26+
27+
parent: Overlay.overlay
28+
anchors.fill: parent
29+
visible: Qt.platform.os === "windows" && _menuOpen && root.menu !== null
30+
31+
Connections {
32+
target: root.menu
33+
34+
function onAboutToShow(): void {
35+
root._menuOpen = true;
36+
}
37+
38+
function onClosed(): void {
39+
Qt.callLater(() => {
40+
root._menuOpen = false;
41+
});
42+
}
43+
}
44+
45+
MouseArea {
46+
anchors.fill: parent
47+
acceptedButtons: Qt.LeftButton
48+
49+
onPressed: event => {
50+
event.accepted = true;
51+
root._menuOpen = false;
52+
root.menu.close();
53+
}
54+
}
55+
}

qt/qml/views/footer/MpvqcFooterView.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,8 @@ Item {
138138
onPercentToggled: root.viewModel.toggleStatusbarPercentage()
139139
}
140140
}
141+
142+
MpvqcFooterContextMenuClickGuard {
143+
menu: _contextMenuLoader.item
144+
}
141145
}

qt/qml/views/footer/qmldir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ module views.footer
77
MpvqcFooterView MpvqcFooterView.qml
88

99
internal MpvqcFooterContextMenu MpvqcFooterContextMenu.qml
10+
internal MpvqcFooterContextMenuClickGuard MpvqcFooterContextMenuClickGuard.qml

0 commit comments

Comments
 (0)