mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-01-19 07:51:54 +00:00
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).
This commit is contained in:
parent
844cd2d8a8
commit
fa8f092e67
1 changed files with 20 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue