summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoawindow.mm
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-09-28 17:06:44 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-09-30 18:35:12 +0200
commitb1b75326f4779c5a8d4ce65626ef8a80079ff994 (patch)
tree2c6499837c6181a96e0506a55c8ec2c77f59da91 /src/plugins/platforms/cocoa/qcocoawindow.mm
parent07cfab07a2a489e021b56226824a2d9b1211fad7 (diff)
macOS: fix window deactivation when a popup is open
On macOS, we get explicit notifications when a window becomes or resigns the key, before we have had a chance to close open popups. The popup is then closed later, but the delivery of the WindowDeactivate event has already been aborted as QApplication interprets such notifications while in popup mode as delayed focus events. This leaves the focus widget still displaying focus even though its window is no longer active. Trying to activate the window again then does not correctly transfer focus. To fix this, close all popup explicitly when a window resigns key. Task-number: QTBUG-78750 Fixes: QTBUG-66513 Fixes: QTBUG-69710 Pick-to: 6.2 Change-Id: I590757c7d3532dbe4b5358a8e121ce8aa871a699 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 5b23bb3174..02ed0c37f2 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1208,13 +1208,18 @@ void QCocoaWindow::windowDidResignKey()
if (isForeignWindow())
return;
+ // Make sure popups are closed before we deliver activation changes, which are
+ // otherwise ignored by QApplication.
+ QGuiApplicationPrivate::instance()->closeAllPopups();
+
// The current key window will be non-nil if another window became key. If that
// window is a Qt window, we delay the window activation event until the didBecomeKey
// notification is delivered to the active window, to ensure an atomic update.
NSWindow *newKeyWindow = [NSApp keyWindow];
if (newKeyWindow && newKeyWindow != m_view.window
- && [newKeyWindow conformsToProtocol:@protocol(QNSWindowProtocol)])
+ && [newKeyWindow conformsToProtocol:@protocol(QNSWindowProtocol)]) {
return;
+ }
// Lost key window, go ahead and set the active window to zero
if (!windowIsPopupType()) {