diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-08-18 21:04:36 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-08-22 20:10:13 +0200 |
commit | 5afb04d79ba246d9dca30c666511ce7505113ac5 (patch) | |
tree | edee7cd916400c43b9bc123e3d6f3a94c1dbdb03 /src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | |
parent | 03144190dfa329444d8941781d20265dfe7ce59c (diff) |
Mac: close popups opened on inactive application on relevant user action
On macOS, users can right-click into an inactive application to open a
context menu without activating the application. Qt handles a number of
events to close open popups (window deactivating or a mouse press
outside the popup), but none of those will get called when the
application is already inactive. So the popup might stay open (and on
top of the window stack) when the user clicks into other applications,
or activates another window.
To fix this we need to watch for events outside of the Qt application on
which we need to close the popup: when the user presses a mouse button,
or activates another application using Cmd-Tab. But we don't want to
monitor for key events, as that requires user permission. Use a global
event monitor to watch for mouse presses, and an notification observer
to watch for application activations, and respond by closing all popups
(and removing the monitor and observer again).
Use the monitor as well to watch for mouse moves, and pass only those
events through the Qt event system so that mouse tracking in the menu
works even if the application is inactive. This change brings back a
version of the global event monitor we had in Qt 5.15.
However, a press into our own menu will trigger the activation observer
after the application became active, which would now close the menu. We
don't want that, so we also need to remove the observer when the
application becomes active (which makes sense anyway, as we will get
regular events from then on).
Pick-to: 6.4 6.3 6.2
Fixes: QTBUG-105474
Change-Id: I18573fcda09a46c27730bd670a795f4d467aab01
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 07ac6023c0..b13ec3bee8 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -232,6 +232,11 @@ QT_USE_NAMESPACE - (void)applicationDidBecomeActive:(NSNotification *)notification { + if (QCocoaWindow::s_applicationActivationObserver) { + [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:QCocoaWindow::s_applicationActivationObserver]; + QCocoaWindow::s_applicationActivationObserver = nil; + } + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate applicationDidBecomeActive:notification]; |