From c322ae131e599562aee019ebec0fbc384fed0095 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 4 Mar 2020 18:28:39 -0800 Subject: [PATCH] Fix unfocusing the game while in fullscreen mode If you Alt+Tabbed while in fullscreen mode, the game would stay in fullscreen instead of switching to windowed, but there was a chance it would EITHER use the same internal resolution which would mismatch the window resolution (don't know when exactly this happens, but still) and stay being in an actual windowed mode, OR switch between fullscreen/windowed every other time you re-focused the window, which is annoying. Now, whenever you Alt+Tab in fullscreen, the game will be in windowed mode, and then when you re-focus it will go back to fullscreen. Consistently. --- desktop_version/src/KeyPoll.cpp | 4 ++++ desktop_version/src/main.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 75992cb0..a9cccbe7 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -248,6 +248,7 @@ void KeyPoll::Poll() SDL_SetWindowFullscreen(window, 0); } SDL_DisableScreenSaver(); + resetWindow = true; } else if (evt.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { @@ -260,16 +261,19 @@ void KeyPoll::Poll() ); } SDL_EnableScreenSaver(); + resetWindow = true; } /* Mouse Focus */ else if (evt.window.event == SDL_WINDOWEVENT_ENTER) { SDL_DisableScreenSaver(); + resetWindow = true; } else if (evt.window.event == SDL_WINDOWEVENT_LEAVE) { SDL_EnableScreenSaver(); + resetWindow = true; } } diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index d634427c..a631f5a4 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -553,11 +553,11 @@ int main(int argc, char *argv[]) Mix_Volume(-1,MIX_MAX_VOLUME); } - if(key.resetWindow) - { - key.resetWindow = false; - gameScreen.ResizeScreen(-1, -1); - } + if (key.resetWindow) + { + key.resetWindow = false; + gameScreen.ResizeScreen(-1, -1); + } music.processmusic(); graphics.processfade();