From 5bd8a96c3accd1f1aed4e8af3eab460cff73b545 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Wed, 19 May 2021 18:47:56 +0200 Subject: [PATCH 1/2] Improve SDL_CreateWindow() fullscreen support on Windows .. and maybe other platforms as well (though X11 was not affected)? The issue was that passing a higher resolution than the current desktop resolution to SDL_CreateWindow() with SDL_WINDOW_FULLSCREEN didn't switch to that resolution (even though it did switch to lower resolutions). When creating a fullscreen window, window->fullscreen wasn't even set at all (only zeroed out), setting it only happened if the user explicitly called SDL_SetWindowDisplayMode(). So without that, SDL_CreateWindow() -> SDL_UpdateFullscreenMode() -> SDL_GetWindowDisplayMode() used the resolution from window->windowed.w/h which were limited to the desktop size due to some weird combination of WIN_AdjustWindowRectWithStyle() and WIN_WindowProc() being called after a call to SetWindowPos(). fixes #3313 --- src/video/SDL_video.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index a5cbe69629e41..271ef18b1537d 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1589,6 +1589,22 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) displayIndex = SDL_GetIndexOfDisplay(display); SDL_GetDisplayBounds(displayIndex, &bounds); + /* for real fullscreen we might switch the resolution, so get width and height + * from closest supported mode and use that instead of current resolution + */ + if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP + && (bounds.w != w || bounds.h != h)) { + SDL_DisplayMode fullscreen_mode, closest_mode; + SDL_zero(fullscreen_mode); + fullscreen_mode.w = w; + fullscreen_mode.h = h; + if(SDL_GetClosestDisplayModeForDisplay(display, &fullscreen_mode, &closest_mode) != NULL) { + bounds.w = closest_mode.w; + bounds.h = closest_mode.h; + } + } + window->fullscreen_mode.w = bounds.w; + window->fullscreen_mode.h = bounds.h; window->x = bounds.x; window->y = bounds.y; window->w = bounds.w; From 158a0822c216a974d8598b92b72c3df7fa6a8951 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Fri, 21 May 2021 13:48:14 +0200 Subject: [PATCH 2/2] SDL_SetWindowDisplayMode(): If already fullscreen, adjust window size Otherwise only the display resolution is changed, but the SDL window size (and for example the window-surface size) aren't adjusted accordingly and thus don't fill the whole screen. See #3313 --- src/video/SDL_video.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 271ef18b1537d..08e7089007650 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1154,6 +1154,12 @@ SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode) SDL_DisplayMode fullscreen_mode; if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { SDL_SetDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode); + /* make sure the window size (and internals like window-surface size) are adjusted */ + if (window->w != fullscreen_mode.w || window->h != fullscreen_mode.h) { + window->w = fullscreen_mode.w; + window->h = fullscreen_mode.h; + SDL_OnWindowResized(window); + } } } return 0;