diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-09-03 16:29:23 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-09-08 00:50:23 +0200 |
commit | 5fbb17c39785ed2c80219c9c0ea97879e371d490 (patch) | |
tree | 4291723eb163f50d3f20c93dd1bff47ef9676f1e /src/plugins/platforms/cocoa/qcocoawindow.mm | |
parent | b1af52f2b2e1d318fc7a5481659e8101bf2e18dd (diff) |
macOS: Don't assume we will get didBecomeKey for non-Qt NSWindows
The optimization resulted in losing out on window focus changes when
for example a native file dialog was shown, resulting in the cursor
blinking both in the parent window, and in the native file dialog.
Pick-to: 5.15
Pick-to: 5.12
Change-Id: I9c1f9df20fbc5c4b80f906ded70d9a2658b70438
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 824603be98..93b7169237 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1226,15 +1226,18 @@ void QCocoaWindow::windowDidResignKey() if (isForeignWindow()) return; - // Key window will be non-nil if another window became key, so do not - // set the active window to zero here -- the new key window's - // NSWindowDidBecomeKeyNotification hander will change the active window. - NSWindow *keyWindow = [NSApp keyWindow]; - if (!keyWindow || keyWindow == m_view.window) { - // No new key window, go ahead and set the active window to zero - if (!windowIsPopupType()) - QWindowSystemInterface::handleWindowActivated<QWindowSystemInterface::SynchronousDelivery>( - nullptr, Qt::ActiveWindowFocusReason); + // 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)]) + return; + + // Lost key window, go ahead and set the active window to zero + if (!windowIsPopupType()) { + QWindowSystemInterface::handleWindowActivated<QWindowSystemInterface::SynchronousDelivery>( + nullptr, Qt::ActiveWindowFocusReason); } } |