Skip to content

Commit bd60840

Browse files
committed
QMenu: Trigger on button releases without seeing pressed buttons before
On Wayland we can't make any assumptions about button state when we don't have pointer focus. Crucially when opening a popup (menu in this case), a pointer leave (focus out) event for the parent window and a pointer enter (focus in) event for the new menu window will be sent, and accordingly the platform backend resets the button state. However, this means QMenu might never see a move event with pressed buttons; and upon release, no action is triggered. If we see a release without having seen any pressed buttons: if the release happens over an action, activate it; otherwise do nothing, as before (it's just release of the press that opened the menu). Fixes: QTBUG-124920 Change-Id: Id86e81431621ce577101bf7cf45252dd1a02bfc4 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 7412278) Reviewed-by: David Redondo <qt@david-redondo.de>
1 parent 4a91973 commit bd60840

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/widgets/widgets/qmenu.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,15 +2921,19 @@ void QMenu::mouseReleaseEvent(QMouseEvent *e)
29212921
Q_D(QMenu);
29222922
if (d->aboutToHide || d->mouseEventTaken(e))
29232923
return;
2924-
if (QMenuPrivate::mouseDown != this) {
2924+
2925+
if (QMenuPrivate::mouseDown && QMenuPrivate::mouseDown != this) {
29252926
QMenuPrivate::mouseDown = nullptr;
29262927
return;
29272928
}
29282929

2930+
// If no mouse press was seen before this is the release event that caused the menu to open
2931+
const bool sawMousePress = QMenuPrivate::mouseDown;
29292932
QMenuPrivate::mouseDown = nullptr;
2933+
29302934
d->setSyncAction();
29312935

2932-
if (!d->hasMouseMoved(e->globalPosition().toPoint())) {
2936+
if (sawMousePress && !d->hasMouseMoved(e->globalPosition().toPoint())) {
29332937
// We don't want to trigger a menu item if the mouse hasn't moved
29342938
// since the popup was opened. Instead we want to close the menu.
29352939
d->hideUpToMenuBar();
@@ -2945,7 +2949,7 @@ void QMenu::mouseReleaseEvent(QMouseEvent *e)
29452949
#endif
29462950
d->activateAction(action, QAction::Trigger);
29472951
}
2948-
} else if (!action || (action->isEnabled() && !action->isSeparator())) {
2952+
} else if (sawMousePress && (!action || (action->isEnabled() && !action->isSeparator()))) {
29492953
d->hideUpToMenuBar();
29502954
}
29512955
}

0 commit comments

Comments
 (0)