diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index d6421159262..81cd16a78c6 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -192,9 +192,8 @@ QT_USE_NAMESPACE inLaunch = false; if (qEnvironmentVariableIsEmpty("QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM")) { - auto frontmostApplication = NSWorkspace.sharedWorkspace.frontmostApplication; auto currentApplication = NSRunningApplication.currentApplication; - if (frontmostApplication != currentApplication) { + if (!currentApplication.active) { // Move the application to front to avoid launching behind the terminal. // Ignoring other apps is necessary (we must ignore the terminal), but makes // Qt apps play slightly less nice with other apps when launching from Finder @@ -202,6 +201,7 @@ QT_USE_NAMESPACE // being non-active here because another application stole activation in the // time it took us to launch from Finder, and being non-active because we were // launched from Terminal or something that doesn't activate us at all. + auto frontmostApplication = NSWorkspace.sharedWorkspace.frontmostApplication; qCDebug(lcQpaApplication) << "Launched with" << frontmostApplication << "as frontmost application. Activating" << currentApplication << "instead."; [NSApplication.sharedApplication activateIgnoringOtherApps:YES];