From 192dfd51eeda01d348ea60e948ee6fc0f8736fbd Mon Sep 17 00:00:00 2001 From: myk002 Date: Fri, 6 Aug 2021 07:10:42 -0700 Subject: [PATCH] clear modstate on window focus this fixes the issue where the alt modstate was getting stuck on systems that don't send standard keyup events after alt-tab. for example, in KDE Plasma (on Gentoo, at least), the keyup event when alt is released after alt-tab contains an incorrect keycode (NUMLOCK instead of L_ALT), which was preventing us from correctly clearing the alt modstate. --- library/Core.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 353b1262f..7648d6e58 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2472,13 +2472,20 @@ int UnicodeAwareSym(const SDL::KeyboardEvent& ke) //MEMO: return false if event is consumed int Core::DFH_SDL_Event(SDL::Event* ev) { - //static bool alt = 0; - // do NOT process events before we are ready. if(!started) return true; if(!ev) return true; - if(ev && (ev->type == SDL::ET_KEYDOWN || ev->type == SDL::ET_KEYUP)) + + if(ev->type == SDL::ET_ACTIVEEVENT && ev->active.gain) + { + // clear modstate when gaining focus in case alt-tab was used when + // losing focus and modstate is now incorrectly set + modstate = 0; + return true; + } + + if(ev->type == SDL::ET_KEYDOWN || ev->type == SDL::ET_KEYUP) { auto ke = (SDL::KeyboardEvent *)ev;