From 0b118594f90acad1350120269ac7f5a1204ea676 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Sun, 8 Dec 2019 18:29:31 +0200 Subject: [PATCH 1/7] [macOS] Send resize event without actually resizing window on backing change. Co-authored-by: Haoyu Qiu --- platform/osx/os_osx.mm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 3c79515465e..3992cb2ea00 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -221,12 +221,8 @@ static bool mouse_down_control = false; //Update context if (OS_OSX::singleton->main_loop) { - [OS_OSX::singleton->context update]; - - //Force window resize ??? - NSRect frame = [OS_OSX::singleton->window_object frame]; - [OS_OSX::singleton->window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, 1, 1) display:YES]; - [OS_OSX::singleton->window_object setFrame:frame display:YES]; + //Force window resize event + [self windowDidResize:notification]; } } } From 31d84838ac77bb112f9ceac0d1cae64bc9c85c16 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Sat, 23 Feb 2019 20:06:33 +0200 Subject: [PATCH 2/7] [macOS] Make `move_window_to_foreground` to take focus in addition to moving window to front. --- platform/osx/os_osx.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 3992cb2ea00..636b4fc8d02 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1734,7 +1734,8 @@ bool OS_OSX::is_window_maximized() const { void OS_OSX::move_window_to_foreground() { - [window_object orderFrontRegardless]; + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; + [window_object makeKeyAndOrderFront:nil]; } void OS_OSX::set_window_always_on_top(bool p_enabled) { From 91f7af48eb799dc872803fe862de31f1874fbb7a Mon Sep 17 00:00:00 2001 From: Daniel Ting Date: Fri, 3 Jul 2020 23:00:48 -0500 Subject: [PATCH 3/7] Fix opening URLS with special characters in macOS The Online Tutorials section of InputMap in the editor's built-in documentation viewer contains this link: docs.godotengine.org/en/latest/tutorials/inputs/inputevent.html#inputmap The macOS implementation for opening a link percent-encodes it before sending it to the browser, resulting in a 404. This is to fix #13422 where filenames with special characters could not be opened in Finder. However, this breaks URLS so I added a check to see if the resource scheme is file:// and if so, only then is it escaped. This allows other schemes like `http`, `ftp`, and `mailto` to be used. --- platform/osx/os_osx.mm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 636b4fc8d02..e990ffa2118 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1419,8 +1419,13 @@ void OS_OSX::make_rendering_thread() { } Error OS_OSX::shell_open(String p_uri) { - - [[NSWorkspace sharedWorkspace] openURL:[[NSURL alloc] initWithString:[NSString stringWithUTF8String:p_uri.utf8().get_data()]]]; + NSString *string = [NSString stringWithUTF8String:p_uri.utf8().get_data()]; + NSURL *uri = [[NSURL alloc] initWithString:string]; + // Escape special characters in filenames + if (!uri || !uri.scheme || [uri.scheme isEqual:@"file"]) { + uri = [[NSURL alloc] initWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]]; + } + [[NSWorkspace sharedWorkspace] openURL:uri]; return OK; } From 457dc5056d2a2a48db22997546c0f6240076b296 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 9 Apr 2020 20:06:43 +0300 Subject: [PATCH 4/7] Ignore process serial number (`-psn_...`) command line argument passed by macOS Gatekeeper. --- main/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main/main.cpp b/main/main.cpp index b08fa12f9f1..27fd0420ab8 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -286,6 +286,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph #endif while (I) { +#ifdef OSX_ENABLED + // Ignore the process serial number argument passed by macOS Gatekeeper. + // Otherwise, Godot would try to open a non-existent project on the first start and abort. + if (I->get().begins_with("-psn_")) { + I = I->next(); + continue; + } +#endif List::Element *N = I->next(); From 45f4300eddd9871c06a0961457cc5537b5af7262 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 25 Nov 2019 15:55:17 +0200 Subject: [PATCH 5/7] [macOS] Fix locale detection. --- platform/osx/os_osx.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index e990ffa2118..e1a85ad8105 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1430,7 +1430,7 @@ Error OS_OSX::shell_open(String p_uri) { } String OS_OSX::get_locale() const { - NSString *locale_code = [[NSLocale currentLocale] localeIdentifier]; + NSString *locale_code = [[NSLocale preferredLanguages] objectAtIndex:0]; return [locale_code UTF8String]; } From f2b51815c75a48ad314464f5da2da250e7e86767 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 2 Mar 2018 18:38:42 +0200 Subject: [PATCH 6/7] Hack to force macOS window activation for non-bundled app. --- platform/osx/os_osx.mm | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index e1a85ad8105..0532a965d31 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -138,10 +138,44 @@ static bool mouse_down_control = false; @end @interface GodotApplicationDelegate : NSObject +- (void)forceUnbundledWindowActivationHackStep1; +- (void)forceUnbundledWindowActivationHackStep2; +- (void)forceUnbundledWindowActivationHackStep3; @end @implementation GodotApplicationDelegate +- (void)forceUnbundledWindowActivationHackStep1 { + // Step1: Switch focus to macOS Dock. + // Required to perform step 2, TransformProcessType will fail if app is already the in focus. + for (NSRunningApplication *app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) { + [app activateWithOptions:NSApplicationActivateIgnoringOtherApps]; + break; + } + [self performSelector:@selector(forceUnbundledWindowActivationHackStep2) withObject:nil afterDelay:0.02]; +} + +- (void)forceUnbundledWindowActivationHackStep2 { + // Step 2: Register app as foreground process. + ProcessSerialNumber psn = { 0, kCurrentProcess }; + (void)TransformProcessType(&psn, kProcessTransformToForegroundApplication); + + [self performSelector:@selector(forceUnbundledWindowActivationHackStep3) withObject:nil afterDelay:0.02]; +} + +- (void)forceUnbundledWindowActivationHackStep3 { + // Step 3: Switch focus back to app window. + [[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps]; +} + +- (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). + [self performSelector:@selector(forceUnbundledWindowActivationHackStep1) withObject:nil afterDelay:0.02]; + } +} + - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { if (OS_OSX::singleton->get_main_loop()) OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); @@ -2043,7 +2077,7 @@ OS_OSX::OS_OSX() { NSMenuItem *menu_item; NSString *title; - NSString *nsappname = [[[NSBundle mainBundle] performSelector:@selector(localizedInfoDictionary)] objectForKey:@"CFBundleName"]; + NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; if (nsappname == nil) nsappname = [[NSProcessInfo processInfo] processName]; From 834f427cf5f35a2eb0a80c27cc207a6ad8a2bc69 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 26 Mar 2018 16:55:57 +0300 Subject: [PATCH 7/7] [macOS] Return exit code specified by `OS.exit_code` parameter. --- platform/osx/godot_main_osx.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/osx/godot_main_osx.mm b/platform/osx/godot_main_osx.mm index 90501d01c46..18bbcc86f4a 100644 --- a/platform/osx/godot_main_osx.mm +++ b/platform/osx/godot_main_osx.mm @@ -84,5 +84,5 @@ int main(int argc, char **argv) { os.run(); // it is actually the OS that decides how to run Main::cleanup(); - return 0; + return os.get_exit_code(); };