[macOS] Improve "extended to title" transition to / from fullscreen.
This commit is contained in:
parent
c8a0912f36
commit
cdfa50dbe9
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue