Skip to content

Commit

Permalink
MacOS: headless UX improvements
Browse files Browse the repository at this point in the history
don't show the application in the dock or task switcher unless:
- we create a non-headless display driver or
- an alert must be shown
  • Loading branch information
ogapo committed Apr 29, 2024
1 parent 780e1a5 commit fd0c8d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions misc/dist/macos_tools.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<key>x86_64</key>
<string>10.12</string>
</dict>
<key>LSUIElement</key>
<true/>
<key>NSHighResolutionCapable</key>
<true/>
<key>CFBundleDocumentTypes</key>
Expand Down
3 changes: 3 additions & 0 deletions platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,9 @@

CGEventSourceSetLocalEventsSuppressionInterval(event_source, 0.0);

// Now that we are sure we're not headless, display our icon in the dock/task switcher.
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

int screen_count = get_screen_count();
for (int i = 0; i < screen_count; i++) {
display_max_scale = fmax(display_max_scale, screen_get_scale(i));
Expand Down
6 changes: 3 additions & 3 deletions platform/macos/os_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
}

void OS_MacOS::alert(const String &p_alert, const String &p_title) {
// Make sure we are shown in the dock/task switcher now (even if we were headless).
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

NSAlert *window = [[NSAlert alloc] init];
NSString *ns_title = [NSString stringWithUTF8String:p_title.utf8().get_data()];
NSString *ns_alert = [NSString stringWithUTF8String:p_alert.utf8().get_data()];
Expand Down Expand Up @@ -820,9 +823,6 @@
// Implicitly create shared NSApplication instance.
[GodotApplication sharedApplication];

// In case we are unbundled, make us a proper UI application.
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

// Menu bar setup must go between sharedApplication above and
// finishLaunching below, in order to properly emulate the behavior
// of NSApplicationMain.
Expand Down

0 comments on commit fd0c8d7

Please sign in to comment.