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

win32: Keep the window on the last maximized display when leaving ful… #12254

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
29 changes: 29 additions & 0 deletions src/video/windows/SDL_windowswindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,35 @@ SDL_FullscreenResult WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window
&w, &h,
SDL_WINDOWRECT_FLOATING);
data->windowed_mode_was_maximized = false;

/* A window may have been maximized by dragging it to the top of another display, in which case the floating
* position may be out-of-date. If the window is being restored to maximized, and the maximized and floating
* position are on different displays, try to center the window on the maximized display for restoration, which
* mimics native Windows behavior.
*/
if (enterMaximized) {
const SDL_Point windowed_point = { window->windowed.x, window->windowed.y };
const SDL_Point floating_point = { window->floating.x, window->floating.y };
const SDL_DisplayID floating_display = SDL_GetDisplayForPoint(&floating_point);
const SDL_DisplayID windowed_display = SDL_GetDisplayForPoint(&windowed_point);

if (floating_display != windowed_display) {
SDL_Rect bounds;

SDL_zero(bounds);
SDL_GetDisplayUsableBounds(windowed_display, &bounds);
if (w < bounds.w) {
x = bounds.x + (bounds.w - w) / 2;
} else {
x = bounds.x;
}
if (h < bounds.h) {
y = bounds.y + (bounds.h - h) / 2;
} else {
y = bounds.y;
}
}
}
}

/* Always reset the window to the base floating size before possibly re-applying the maximized state,
Expand Down
Loading