Fix window_set_current_screen for maximized windows.

This commit is contained in:
bruvzg 2024-10-03 10:38:32 +03:00
parent 2e14492879
commit d2f3725120
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
3 changed files with 18 additions and 1 deletions

View file

@ -2055,7 +2055,7 @@ void DisplayServerX11::window_set_current_screen(int p_screen, WindowID p_window
return; return;
} }
if (window_get_mode(p_window) == WINDOW_MODE_FULLSCREEN) { if (window_get_mode(p_window) == WINDOW_MODE_FULLSCREEN || window_get_mode(p_window) == WINDOW_MODE_MAXIMIZED) {
Point2i position = screen_get_position(p_screen); Point2i position = screen_get_position(p_screen);
Size2i size = screen_get_size(p_screen); Size2i size = screen_get_size(p_screen);

View file

@ -1893,6 +1893,12 @@ void DisplayServerMacOS::window_set_current_screen(int p_screen, WindowID p_wind
was_fullscreen = true; was_fullscreen = true;
} }
bool was_maximized = false;
if (!was_fullscreen && NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
[wd.window_object zoom:nil];
was_maximized = true;
}
Rect2i srect = screen_get_usable_rect(p_screen); Rect2i srect = screen_get_usable_rect(p_screen);
Point2i wpos = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window)); Point2i wpos = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window));
Size2i wsize = window_get_size(p_window); Size2i wsize = window_get_size(p_window);
@ -1901,6 +1907,10 @@ void DisplayServerMacOS::window_set_current_screen(int p_screen, WindowID p_wind
wpos = wpos.clamp(srect.position, srect.position + srect.size - wsize / 3); wpos = wpos.clamp(srect.position, srect.position + srect.size - wsize / 3);
window_set_position(wpos, p_window); window_set_position(wpos, p_window);
if (was_maximized) {
[wd.window_object zoom:nil];
}
if (was_fullscreen) { if (was_fullscreen) {
// Re-enter fullscreen mode. // Re-enter fullscreen mode.
[wd.window_object toggleFullScreen:nil]; [wd.window_object toggleFullScreen:nil];

View file

@ -1813,6 +1813,13 @@ void DisplayServerWindows::window_set_current_screen(int p_screen, WindowID p_wi
Size2 size = screen_get_size(p_screen); Size2 size = screen_get_size(p_screen);
MoveWindow(wd.hWnd, pos.x, pos.y, size.width, size.height, TRUE); MoveWindow(wd.hWnd, pos.x, pos.y, size.width, size.height, TRUE);
} else if (wd.maximized) {
Point2 pos = screen_get_position(p_screen) + _get_screens_origin();
Size2 size = screen_get_size(p_screen);
ShowWindow(wd.hWnd, SW_RESTORE);
MoveWindow(wd.hWnd, pos.x, pos.y, size.width, size.height, TRUE);
ShowWindow(wd.hWnd, SW_MAXIMIZE);
} else { } else {
Rect2i srect = screen_get_usable_rect(p_screen); Rect2i srect = screen_get_usable_rect(p_screen);
Point2i wpos = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window)); Point2i wpos = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window));