From 2608db9151f3280b1b621742d1b2da9794926444 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 16 Mar 2021 23:26:34 -0700 Subject: [PATCH] Directly toggle fullscreen if keybind pressed in key.Poll() This moves the responsibility of toggling fullscreen when any of the three toggle fullscreen keybinds are pressed (F11, Alt+Enter, Alt+F) directly into key.Poll() itself, and not its caller (which is main() - more specifically, fixedloop()). Furthermore, the fullscreen toggle itself has been moved to a separate function that key.Poll() just calls, to prevent cluttering key.Poll() with more business logic (the function is already quite big enough as it is). As part of my work in re-removing the 1-frame input delay in #535, I'm moving the callsite of key.Poll() around, and I don't want to have to lug this block of code around with it. I'd rather refactor it upfront than touch any more lines than necessary in that PR. --- desktop_version/src/KeyPoll.cpp | 26 ++++++++++++++++++++++++-- desktop_version/src/KeyPoll.h | 2 +- desktop_version/src/main.cpp | 14 -------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 4e9fa8c3..60abc843 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -41,7 +41,6 @@ KeyPoll::KeyPoll(void) leftbutton=0; rightbutton=0; middlebutton=0; mx=0; my=0; resetWindow = 0; - toggleFullscreen = false; pressedbackspace=false; useFullscreenSpaces = false; @@ -78,9 +77,27 @@ bool KeyPoll::textentry(void) return SDL_IsTextInputActive() == SDL_TRUE; } +void KeyPoll::toggleFullscreen(void) +{ + if (graphics.screenbuffer != NULL) + { + graphics.screenbuffer->toggleFullScreen(); + } + + keymap.clear(); /* we lost the input due to a new window. */ + if (game.glitchrunnermode) + { + game.press_left = false; + game.press_right = false; + game.press_action = true; + game.press_map = false; + } +} + void KeyPoll::Poll(void) { bool altpressed = false; + bool fullscreenkeybind = false; SDL_Event evt; while (SDL_PollEvent(&evt)) { @@ -106,7 +123,7 @@ void KeyPoll::Poll(void) bool f11pressed = evt.key.keysym.sym == SDLK_F11; if ((altpressed && (returnpressed || fpressed)) || f11pressed) { - toggleFullscreen = true; + fullscreenkeybind = true; } if (textentry()) @@ -321,6 +338,11 @@ void KeyPoll::Poll(void) break; } } + + if (fullscreenkeybind) + { + toggleFullscreen(); + } } bool KeyPoll::isDown(SDL_Keycode key) diff --git a/desktop_version/src/KeyPoll.h b/desktop_version/src/KeyPoll.h index d6eef915..9635aa3b 100644 --- a/desktop_version/src/KeyPoll.h +++ b/desktop_version/src/KeyPoll.h @@ -38,7 +38,7 @@ public: bool resetWindow; bool quitProgram; - bool toggleFullscreen; + void toggleFullscreen(void); int sensitivity; diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 8df39a09..528e7a15 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -454,20 +454,6 @@ static void inline fixedloop(void) NETWORK_update(); key.Poll(); - if(key.toggleFullscreen) - { - gameScreen.toggleFullScreen(); - key.toggleFullscreen = false; - - key.keymap.clear(); //we lost the input due to a new window. - if (game.glitchrunnermode) - { - game.press_left = false; - game.press_right = false; - game.press_action = true; - game.press_map = false; - } - } if(!key.isActive) {