From 16bb18c4530795cb0b20e9319333c9752936afa1 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 11 Jan 2022 20:43:29 +0200 Subject: [PATCH] [macOS] Improve window activation hack. (cherry picked from commit 927105692fe42fb0192a190f20e662c94060194c) --- platform/osx/os_osx.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index e53797f8f4e..e06f880757d 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -170,9 +170,9 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) { @implementation GodotApplicationDelegate - (void)forceUnbundledWindowActivationHackStep1 { - // Step1: Switch focus to macOS Dock. + // Step 1: Switch focus to macOS SystemUIServer process. // Required to perform step 2, TransformProcessType will fail if app is already the in focus. - for (NSRunningApplication *app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) { + for (NSRunningApplication *app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.systemuiserver"]) { [app activateWithOptions:NSApplicationActivateIgnoringOtherApps]; break; } @@ -194,8 +194,8 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) { - (void)applicationDidFinishLaunching:(NSNotification *)notice { NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; - if (nsappname == nil) { - // If executable is not a bundled, macOS WindowServer won't register and activate app window correctly (menu and title bar are grayed out and input ignored). + if (nsappname == nil || isatty(STDOUT_FILENO) || isatty(STDIN_FILENO) || isatty(STDERR_FILENO)) { + // If the executable is started from terminal or is not bundled, macOS WindowServer won't register and activate app window correctly (menu and title bar are grayed out and input ignored). [self performSelector:@selector(forceUnbundledWindowActivationHackStep1) withObject:nil afterDelay:0.02]; } }