Skip to content

Commit 4bbef7d

Browse files
committed
Merge pull request #106942 from bruvzg/macos_borderless_maximize
[macOS] Fix borderless window maximization.
2 parents 626a75a + 798a644 commit 4bbef7d

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

platform/macos/display_server_macos.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class DisplayServerMacOS : public DisplayServer {
111111
Size2i size;
112112
Vector2i wb_offset = Vector2i(14, 14);
113113

114-
NSRect last_frame_rect;
114+
NSRect last_frame_rect = NSMakeRect(0, 0, 0, 0);
115+
NSRect pre_zoom_rect = NSMakeRect(0, 0, 0, 0);
115116

116117
bool im_active = false;
117118
Size2i im_position;

platform/macos/display_server_macos.mm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,13 @@
25372537
} break;
25382538
case WINDOW_MODE_MAXIMIZED: {
25392539
if (NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
2540-
[wd.window_object zoom:nil];
2540+
if (wd.borderless) {
2541+
if (wd.pre_zoom_rect.size.width > 0 && wd.pre_zoom_rect.size.height > 0) {
2542+
[wd.window_object setFrame:wd.pre_zoom_rect display:NO animate:YES];
2543+
}
2544+
} else {
2545+
[wd.window_object zoom:nil];
2546+
}
25412547
}
25422548
} break;
25432549
}
@@ -2570,7 +2576,12 @@
25702576
} break;
25712577
case WINDOW_MODE_MAXIMIZED: {
25722578
if (!NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
2573-
[wd.window_object zoom:nil];
2579+
wd.pre_zoom_rect = [wd.window_object frame];
2580+
if (wd.borderless) {
2581+
[wd.window_object setFrame:[[wd.window_object screen] visibleFrame] display:NO animate:YES];
2582+
} else {
2583+
[wd.window_object zoom:nil];
2584+
}
25742585
}
25752586
} break;
25762587
}
@@ -2770,6 +2781,7 @@
27702781
[wd.window_object orderOut:nil];
27712782
}
27722783
wd.borderless = p_enabled;
2784+
bool was_maximized = (NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame]));
27732785
if (p_enabled) {
27742786
[wd.window_object setStyleMask:NSWindowStyleMaskBorderless];
27752787
[wd.window_object setHasShadow:NO];
@@ -2800,6 +2812,9 @@
28002812
[wd.window_object makeKeyAndOrderFront:nil];
28012813
}
28022814
}
2815+
if (was_maximized) {
2816+
[wd.window_object setFrame:[[wd.window_object screen] visibleFrame] display:NO];
2817+
}
28032818
} break;
28042819
case WINDOW_FLAG_ALWAYS_ON_TOP: {
28052820
wd.on_top = p_enabled;

platform/macos/godot_window_delegate.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification {
208208
[self windowDidResize:notification];
209209
}
210210

211+
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
212+
if (ds->has_window(window_id)) {
213+
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
214+
if (!wd.borderless && !(NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame]))) {
215+
wd.pre_zoom_rect = [wd.window_object frame];
216+
}
217+
}
218+
return YES;
219+
}
220+
211221
- (void)windowDidChangeBackingProperties:(NSNotification *)notification {
212222
if (!ds->has_window(window_id)) {
213223
return;

0 commit comments

Comments
 (0)