From fa8f092e67fbf40cbd4cf5d89086a0bad1d4c182 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sat, 8 Sep 2012 01:14:06 +0200 Subject: [PATCH] Unset key modifiers when regaining focus to unset ALT There used to be a bug (discussed in #40), that ALT was still set after using ALT-Tab. Thus when next pressing enter fullscreen was toggled. This should now be fixed by unsetting the modifiers when focus is regained (SDL_ACTIVEEVENT or SDL_WINDOWEVENT_FOCUS_GAINED). --- neo/sys/events.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/neo/sys/events.cpp b/neo/sys/events.cpp index d557f593..eadc6118 100644 --- a/neo/sys/events.cpp +++ b/neo/sys/events.cpp @@ -422,6 +422,15 @@ sysEvent_t Sys_GetEvent() { case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: + // unset modifier, in case alt-tab was used to leave window and ALT is still set + // as that can cause fullscreen-toggling when pressing enter... + SDL_Keymod currentmod = SDL_GetModState(); + int newmod = KMOD_NONE; + if (currentmod & KMOD_CAPS) // preserve capslock + newmod |= KMOD_CAPS; + + SDL_SetModState((SDL_Keymod)newmod); + GLimp_GrabInput(GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR); break; case SDL_WINDOWEVENT_FOCUS_LOST: @@ -435,9 +444,19 @@ sysEvent_t Sys_GetEvent() { { int flags = 0; - if (ev.active.gain) + if (ev.active.gain) { flags = GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR; + // unset modifier, in case alt-tab was used to leave window and ALT is still set + // as that can cause fullscreen-toggling when pressing enter... + SDLMod currentmod = SDL_GetModState(); + int newmod = KMOD_NONE; + if (currentmod & KMOD_CAPS) // preserve capslock + newmod |= KMOD_CAPS; + + SDL_SetModState((SDLMod)newmod); + } + GLimp_GrabInput(flags); }