Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fix restoring fullscreen window. #98631

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2187,23 +2187,28 @@ void DisplayServerWindows::window_set_mode(WindowMode p_mode, WindowID p_window)
ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];

bool was_fullscreen = wd.fullscreen;
wd.was_fullscreen_pre_min = false;

if (wd.fullscreen && p_mode != WINDOW_MODE_FULLSCREEN && p_mode != WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
RECT rect;

wd.fullscreen = false;
wd.multiwindow_fs = false;
wd.maximized = wd.was_maximized;

// Restore previous maximized state.
wd.maximized = wd.was_maximized_pre_fs;

_update_window_style(p_window, false);

// Restore window rect after exiting fullscreen.
if (wd.pre_fs_valid) {
rect = wd.pre_fs_rect;
} else {
rect.left = 0;
rect.right = wd.width;
rect.top = 0;
rect.bottom = wd.height;
wd.pre_fs_valid = true;
}

ShowWindow(wd.hWnd, SW_RESTORE);
Expand Down Expand Up @@ -2231,6 +2236,7 @@ void DisplayServerWindows::window_set_mode(WindowMode p_mode, WindowID p_window)
ShowWindow(wd.hWnd, SW_MINIMIZE);
wd.maximized = false;
wd.minimized = true;
wd.was_fullscreen_pre_min = was_fullscreen;
}

if (p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
Expand All @@ -2245,10 +2251,14 @@ void DisplayServerWindows::window_set_mode(WindowMode p_mode, WindowID p_window)
if (wd.minimized || wd.maximized) {
ShowWindow(wd.hWnd, SW_RESTORE);
}
wd.was_maximized = wd.maximized;

if (wd.pre_fs_valid) {
// Save previous maximized stare.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state*

wd.was_maximized_pre_fs = wd.maximized;

if (!was_fullscreen) {
// Save non-fullscreen rect before entering fullscreen.
GetWindowRect(wd.hWnd, &wd.pre_fs_rect);
wd.pre_fs_valid = true;
}

int cs = window_get_current_screen(p_window);
Expand Down Expand Up @@ -5139,6 +5149,22 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
ClientToScreen(window.hWnd, (POINT *)&crect.right);
ClipCursor(&crect);
}

if (!window.minimized && window.was_fullscreen_pre_min) {
// Restore fullscreen mode if window was in fullscreen before it was minimized.
int cs = window_get_current_screen(window_id);
Point2 pos = screen_get_position(cs) + _get_screens_origin();
Size2 size = screen_get_size(cs);

window.was_fullscreen_pre_min = false;
window.fullscreen = true;
window.maximized = false;
window.minimized = false;

_update_window_style(window_id, false);

MoveWindow(window.hWnd, pos.x, pos.y, size.width, size.height, TRUE);
}
}

// Return here to prevent WM_MOVE and WM_SIZE from being sent
Expand Down Expand Up @@ -5672,7 +5698,19 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
wd.multiwindow_fs = true;
}
}
if (p_mode != WINDOW_MODE_FULLSCREEN && p_mode != WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {

if (p_mode == WINDOW_MODE_FULLSCREEN || p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
// Save initial non-fullscreen rect.
Rect2i srect = screen_get_usable_rect(rq_screen);
Point2i wpos = p_rect.position;
if (srect != Rect2i()) {
wpos = wpos.clamp(srect.position, srect.position + srect.size - p_rect.size / 3);
}

wd.pre_fs_rect.left = wpos.x + offset.x;
wd.pre_fs_rect.right = wpos.x + p_rect.size.x + offset.x;
wd.pre_fs_rect.top = wpos.y + offset.y;
wd.pre_fs_rect.bottom = wpos.y + p_rect.size.y + offset.y;
wd.pre_fs_valid = true;
}

Expand Down
3 changes: 2 additions & 1 deletion platform/windows/display_server_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ class DisplayServerWindows : public DisplayServer {
bool resizable = true;
bool window_focused = false;
int activate_state = 0;
bool was_maximized = false;
bool was_maximized_pre_fs = false;
bool was_fullscreen_pre_min = false;
bool always_on_top = false;
bool no_focus = false;
bool exclusive = false;
Expand Down
Loading