summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-21 11:15:19 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-21 11:21:48 +0300
commitcdfa50dbe916439b043c95c37e08a69eeb58d0ab (patch)
treefc033e7fd4c068bd52402d990919f2157705cb23 /platform
parentc8a0912f3647367d8cee5216f50c28a93e9ffdb5 (diff)
[macOS] Improve "extended to title" transition to / from fullscreen.
Diffstat (limited to 'platform')
-rw-r--r--platform/macos/display_server_macos.h3
-rw-r--r--platform/macos/display_server_macos.mm47
-rw-r--r--platform/macos/godot_window_delegate.mm11
3 files changed, 43 insertions, 18 deletions
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index 576e7aa9ca..a27e0d5efa 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -85,7 +85,7 @@ public:
Size2i min_size;
Size2i max_size;
Size2i size;
- Vector2i wb_offset = Vector2i(16, 16);
+ Vector2i wb_offset = Vector2i(14, 14);
NSRect last_frame_rect;
@@ -230,6 +230,7 @@ public:
void window_update(WindowID p_window);
void window_destroy(WindowID p_window);
void window_resize(WindowID p_window, int p_width, int p_height);
+ void window_set_custom_window_buttons(WindowData &p_wd, bool p_enabled);
virtual bool has_feature(Feature p_feature) const override;
virtual String get_name() const override;
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index 2d67bcb44f..e1d0d99165 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -2671,6 +2671,30 @@ Vector2i DisplayServerMacOS::window_get_safe_title_margins(WindowID p_window) co
return Vector2i(max_x * screen_get_max_scale(), 0);
}
+void DisplayServerMacOS::window_set_custom_window_buttons(WindowData &p_wd, bool p_enabled) {
+ if (p_wd.window_button_view) {
+ [p_wd.window_button_view removeFromSuperview];
+ p_wd.window_button_view = nil;
+ }
+ if (p_enabled) {
+ float window_buttons_spacing = NSMinX([[p_wd.window_object standardWindowButton:NSWindowMiniaturizeButton] frame]) - NSMinX([[p_wd.window_object standardWindowButton:NSWindowCloseButton] frame]);
+
+ [p_wd.window_object setTitleVisibility:NSWindowTitleHidden];
+ [[p_wd.window_object standardWindowButton:NSWindowZoomButton] setHidden:YES];
+ [[p_wd.window_object standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
+ [[p_wd.window_object standardWindowButton:NSWindowCloseButton] setHidden:YES];
+
+ p_wd.window_button_view = [[GodotButtonView alloc] initWithFrame:NSZeroRect];
+ [p_wd.window_button_view initButtons:window_buttons_spacing offset:NSMakePoint(p_wd.wb_offset.x, p_wd.wb_offset.y)];
+ [p_wd.window_view addSubview:p_wd.window_button_view];
+ } else {
+ [p_wd.window_object setTitleVisibility:NSWindowTitleVisible];
+ [[p_wd.window_object standardWindowButton:NSWindowZoomButton] setHidden:NO];
+ [[p_wd.window_object standardWindowButton:NSWindowMiniaturizeButton] setHidden:NO];
+ [[p_wd.window_object standardWindowButton:NSWindowCloseButton] setHidden:NO];
+ }
+}
+
void DisplayServerMacOS::window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window) {
_THREAD_SAFE_METHOD_
@@ -2691,31 +2715,20 @@ void DisplayServerMacOS::window_set_flag(WindowFlags p_flag, bool p_enabled, Win
} break;
case WINDOW_FLAG_EXTEND_TO_TITLE: {
NSRect rect = [wd.window_object frame];
- if (wd.window_button_view) {
- [wd.window_button_view removeFromSuperview];
- wd.window_button_view = nil;
- }
if (p_enabled) {
[wd.window_object setTitlebarAppearsTransparent:YES];
- [wd.window_object setTitleVisibility:NSWindowTitleHidden];
[wd.window_object setStyleMask:[wd.window_object styleMask] | NSWindowStyleMaskFullSizeContentView];
- [[wd.window_object standardWindowButton:NSWindowZoomButton] setHidden:YES];
- [[wd.window_object standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
- [[wd.window_object standardWindowButton:NSWindowCloseButton] setHidden:YES];
- float window_buttons_spacing = NSMinX([[wd.window_object standardWindowButton:NSWindowMiniaturizeButton] frame]) - NSMinX([[wd.window_object standardWindowButton:NSWindowCloseButton] frame]);
-
- wd.window_button_view = [[GodotButtonView alloc] initWithFrame:NSZeroRect];
- [wd.window_button_view initButtons:window_buttons_spacing offset:NSMakePoint(wd.wb_offset.x, wd.wb_offset.y)];
- [wd.window_view addSubview:wd.window_button_view];
+ if (!wd.fullscreen) {
+ window_set_custom_window_buttons(wd, true);
+ }
} else {
[wd.window_object setTitlebarAppearsTransparent:NO];
- [wd.window_object setTitleVisibility:NSWindowTitleVisible];
[wd.window_object setStyleMask:[wd.window_object styleMask] & ~NSWindowStyleMaskFullSizeContentView];
- [[wd.window_object standardWindowButton:NSWindowZoomButton] setHidden:NO];
- [[wd.window_object standardWindowButton:NSWindowMiniaturizeButton] setHidden:NO];
- [[wd.window_object standardWindowButton:NSWindowCloseButton] setHidden:NO];
+ if (!wd.fullscreen) {
+ window_set_custom_window_buttons(wd, false);
+ }
}
[wd.window_object setFrame:rect display:YES];
} break;
diff --git a/platform/macos/godot_window_delegate.mm b/platform/macos/godot_window_delegate.mm
index f7f16b1e0e..94d40924b2 100644
--- a/platform/macos/godot_window_delegate.mm
+++ b/platform/macos/godot_window_delegate.mm
@@ -77,10 +77,16 @@
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
wd.fullscreen = true;
+
// Reset window size limits.
[wd.window_object setContentMinSize:NSMakeSize(0, 0)];
[wd.window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
+ // Reset custom window buttons.
+ if ([wd.window_object styleMask] & NSWindowStyleMaskFullSizeContentView) {
+ ds->window_set_custom_window_buttons(wd, false);
+ }
+
// Force window resize event.
[self windowDidResize:notification];
}
@@ -105,6 +111,11 @@
[wd.window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
}
+ // Restore custom window buttons.
+ if ([wd.window_object styleMask] & NSWindowStyleMaskFullSizeContentView) {
+ ds->window_set_custom_window_buttons(wd, true);
+ }
+
// Restore resizability state.
if (wd.resize_disabled) {
[wd.window_object setStyleMask:[wd.window_object styleMask] & ~NSWindowStyleMaskResizable];