From 72d812852023450b7c3850b8e87b63575df041ee Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Wed, 19 May 2021 18:47:56 +0200 Subject: [PATCH] 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 129eec4aa..5027562c8 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1598,6 +1598,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;