Skip to content

Commit

Permalink
[macOS] Add exclusive fullscreen mode with Dock and Menu disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Nov 14, 2022
1 parent b05e1e7 commit 964d8b2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions doc/classes/DisplayServer.xml
Expand Up @@ -1638,8 +1638,9 @@
Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports [url=$DOCS_URL/tutorials/rendering/multiple_resolutions.html]multiple resolutions[/url] when enabling full screen mode.
</constant>
<constant name="WINDOW_MODE_EXCLUSIVE_FULLSCREEN" value="4" enum="WindowMode">
Exclusive full screen window mode. This mode is implemented on Windows only. On other platforms, it is equivalent to [constant WINDOW_MODE_FULLSCREEN].
Only one window in exclusive full screen mode can be visible on a given screen at a time. If multiple windows are in exclusive full screen mode for the same screen, the last one being set to this mode takes precedence.
Exclusive full screen window mode. This mode is implemented on Windows and macOS only. On other platforms, it is equivalent to [constant WINDOW_MODE_FULLSCREEN].
[b]On Windows:[/b] Only one window in exclusive full screen mode can be visible on a given screen at a time. If multiple windows are in exclusive full screen mode for the same screen, the last one being set to this mode takes precedence.
[b]On macOS:[/b] Exclusive full-screen mode prevents Dock and Menu from showing up when the mouse pointer is hovering the edge of the screen.
Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports [url=$DOCS_URL/tutorials/rendering/multiple_resolutions.html]multiple resolutions[/url] when enabling full screen mode.
</constant>
<constant name="WINDOW_FLAG_RESIZE_DISABLED" value="0" enum="WindowFlags">
Expand Down
1 change: 1 addition & 0 deletions platform/macos/display_server_macos.h
Expand Up @@ -106,6 +106,7 @@ class DisplayServerMacOS : public DisplayServer {

bool layered_window = false;
bool fullscreen = false;
bool exclusive_fullscreen = false;
bool on_top = false;
bool borderless = false;
bool resize_disabled = false;
Expand Down
20 changes: 19 additions & 1 deletion platform/macos/display_server_macos.mm
Expand Up @@ -2584,7 +2584,13 @@
[wd.window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
}
[wd.window_object toggleFullScreen:nil];

if (old_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
[NSApp setPresentationOptions:NSApplicationPresentationDefault];
}

wd.fullscreen = false;
wd.exclusive_fullscreen = false;
} break;
case WINDOW_MODE_MAXIMIZED: {
if ([wd.window_object isZoomed]) {
Expand All @@ -2609,7 +2615,15 @@
[wd.window_object setContentMinSize:NSMakeSize(0, 0)];
[wd.window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[wd.window_object toggleFullScreen:nil];

wd.fullscreen = true;
if (p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
const NSUInteger presentationOptions = NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
[NSApp setPresentationOptions:presentationOptions];
wd.exclusive_fullscreen = true;
} else {
wd.exclusive_fullscreen = false;
}
} break;
case WINDOW_MODE_MAXIMIZED: {
if (![wd.window_object isZoomed]) {
Expand All @@ -2626,7 +2640,11 @@
const WindowData &wd = windows[p_window];

if (wd.fullscreen) { // If fullscreen, it's not in another mode.
return WINDOW_MODE_FULLSCREEN;
if (wd.exclusive_fullscreen) {
return WINDOW_MODE_EXCLUSIVE_FULLSCREEN;
} else {
return WINDOW_MODE_FULLSCREEN;
}
}
if ([wd.window_object isZoomed] && !wd.resize_disabled) {
return WINDOW_MODE_MAXIMIZED;
Expand Down
5 changes: 5 additions & 0 deletions platform/macos/godot_window_delegate.mm
Expand Up @@ -147,7 +147,12 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification {
}

DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
if (wd.exclusive_fullscreen) {
[NSApp setPresentationOptions:NSApplicationPresentationDefault];
}

wd.fullscreen = false;
wd.exclusive_fullscreen = false;

[(GodotWindow *)wd.window_object setAnimDuration:-1.0f];

Expand Down

0 comments on commit 964d8b2

Please sign in to comment.