macOS: Don't try to bring all app windows to front on macOS < 14
Most QWindows are shown in main(), at which point the app is not active yet. When the app is then activated by the OS only the key and main window is brought to the front, leaving auxiliary windows behind other applications. This differs from the behavior of showing windows once the application is active, in which case all windows will end up in front of other applications. To remedy this, we bring all of the app's windows to the front when the app finishes launching. But the way we do this fails on macOS < 14 due to a bug in macOS, where the OS will deactivate the app as part of activating all windows, resulting in losing the original key (focused) window. To fix the immediate issue we skip the workaround of bringing all the app windows to the front on macOS < 14. Longer term we should consider other methods to bring all the windows to the front, e.g. manual orderFront calls, or deferring the original orderFront that happened when setVisible was called from main(). Amends b49211c12543c3369b286b507c4277c66ef9fdef. Fixes: QTBUG-126043 Pick-to: 6.7 6.5 Change-Id: Ia9bc07a41daeb9e5b5b3306df08e5d97fa38f96f Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 2fcab872bc28b39b549d941ec6bb71bd25f20593) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
e880bf86fe
commit
5fc66f68da
@ -207,13 +207,20 @@ QT_USE_NAMESPACE
|
||||
[NSApplication.sharedApplication activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
// Qt windows are typically shown in main(), at which point the application
|
||||
// is not active yet. When the application is activated, either externally
|
||||
// or via the override above, it will only bring the main and key windows
|
||||
// forward, which differs from the behavior if these windows had been shown
|
||||
// once the application was already active. To work around this, we explicitly
|
||||
// activate the current application again, bringing all windows to the front.
|
||||
[currentApplication activateWithOptions:NSApplicationActivateAllWindows];
|
||||
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSSonoma) {
|
||||
// Qt windows are typically shown in main(), at which point the application
|
||||
// is not active yet. When the application is activated, either externally
|
||||
// or via the override above, it will only bring the main and key windows
|
||||
// forward, which differs from the behavior if these windows had been shown
|
||||
// once the application was already active. To work around this, we explicitly
|
||||
// activate the current application again, bringing all windows to the front.
|
||||
// We only do this on Sonoma and up, as earlier macOS versions have a bug where
|
||||
// the app will deactivate as part of activating, even if it's active app,
|
||||
// which in turn results in losing key window status for the key window.
|
||||
// FIXME: Consider bringing our windows to the front via orderFront instead,
|
||||
// or deferring the orderFront during setVisible until the app is active.
|
||||
[currentApplication activateWithOptions:NSApplicationActivateAllWindows];
|
||||
}
|
||||
}
|
||||
|
||||
QCocoaMenuBar::insertWindowMenu();
|
||||
|
Loading…
x
Reference in New Issue
Block a user