From 93929be2c13d6593b826e81b4b5b3864ccad9275 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Fri, 1 Nov 2019 13:29:01 +0100 Subject: [PATCH] SDL: Use the current screen resolution when switching to fullscreen Previously we used the resolution of the first screen. Fixes being unable to switch to fullscreen when using two screens with different resolutions. --- backends/graphics/sdl/resvm-sdl-graphics.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backends/graphics/sdl/resvm-sdl-graphics.cpp b/backends/graphics/sdl/resvm-sdl-graphics.cpp index 1a21a1370b1..9cbbe12ef9a 100644 --- a/backends/graphics/sdl/resvm-sdl-graphics.cpp +++ b/backends/graphics/sdl/resvm-sdl-graphics.cpp @@ -72,6 +72,24 @@ Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() { uint preferredWidth = _capabilities.desktopWidth; uint preferredHeight = _capabilities.desktopHeight; +#if SDL_VERSION_ATLEAST(2, 0, 0) + // When using SDL2, we can query the desktop resolution for the screen our window sits in + int displayIndex = -1; + + SDL_Window *sdlWindow = _window->getSDLWindow(); + if (sdlWindow) { + displayIndex = SDL_GetWindowDisplayIndex(sdlWindow); + } + + if (displayIndex >= 0) { + SDL_DisplayMode displayMode; + if (!SDL_GetDesktopDisplayMode(displayIndex, &displayMode)) { + preferredWidth = displayMode.w; + preferredHeight = displayMode.h; + } + } +#endif + // ... unless the user has set a resolution in the configuration file const Common::String &fsres = ConfMan.get("fullscreen_res"); if (fsres != "desktop") {