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>
This commit is contained in:
Tor Arne Vestbø 2020-09-03 16:29:23 +02:00
parent b1af52f2b2
commit 5fbb17c397

View File

@ -1226,15 +1226,18 @@ void QCocoaWindow::windowDidResignKey()
if (isForeignWindow()) if (isForeignWindow())
return; return;
// Key window will be non-nil if another window became key, so do not // The current key window will be non-nil if another window became key. If that
// set the active window to zero here -- the new key window's // window is a Qt window, we delay the window activation event until the didBecomeKey
// NSWindowDidBecomeKeyNotification hander will change the active window. // notification is delivered to the active window, to ensure an atomic update.
NSWindow *keyWindow = [NSApp keyWindow]; NSWindow *newKeyWindow = [NSApp keyWindow];
if (!keyWindow || keyWindow == m_view.window) { if (newKeyWindow && newKeyWindow != m_view.window
// No new key window, go ahead and set the active window to zero && [newKeyWindow conformsToProtocol:@protocol(QNSWindowProtocol)])
if (!windowIsPopupType()) return;
QWindowSystemInterface::handleWindowActivated<QWindowSystemInterface::SynchronousDelivery>(
nullptr, Qt::ActiveWindowFocusReason); // Lost key window, go ahead and set the active window to zero
if (!windowIsPopupType()) {
QWindowSystemInterface::handleWindowActivated<QWindowSystemInterface::SynchronousDelivery>(
nullptr, Qt::ActiveWindowFocusReason);
} }
} }