diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index caa7e4d..0f02a38 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -98,6 +98,7 @@ static int SDLCALL IN_FilterMouseEvents (const SDL_Event *event) return 1; } +static SDL_EventFilter currentFilter = NULL; #if defined(USE_SDL2) static int SDLCALL IN_SDL2_FilterMouseEvents (void *userdata, SDL_Event *event) { @@ -108,28 +109,48 @@ static int SDLCALL IN_SDL2_FilterMouseEvents (void *userdata, SDL_Event *event) static void IN_BeginIgnoringMouseEvents(void) { #if defined(USE_SDL2) - SDL_EventFilter currentFilter = NULL; void *currentUserdata = NULL; SDL_GetEventFilter(¤tFilter, ¤tUserdata); if (currentFilter != IN_SDL2_FilterMouseEvents) + { SDL_SetEventFilter(IN_SDL2_FilterMouseEvents, NULL); + currentFilter = IN_SDL2_FilterMouseEvents; + } #else - if (SDL_GetEventFilter() != IN_FilterMouseEvents) + currentFilter = SDL_GetEventFilter(); + if (currentFilter != IN_FilterMouseEvents) + { SDL_SetEventFilter(IN_FilterMouseEvents); + currentFilter = IN_FilterMouseEvents; + } #endif } static void IN_EndIgnoringMouseEvents(void) { #if defined(USE_SDL2) - SDL_EventFilter currentFilter; void *currentUserdata; if (SDL_GetEventFilter(¤tFilter, ¤tUserdata) == SDL_TRUE) + { + currentFilter = NULL; SDL_SetEventFilter(NULL, NULL); + } #else if (SDL_GetEventFilter() != NULL) + { + currentFilter = NULL; SDL_SetEventFilter(NULL); + } +#endif +} + +static void IN_RestoreMouseEvents(void) +{ +#if defined(USE_SDL2) + SDL_SetEventFilter(currentFilter, NULL); +#else + SDL_SetEventFilter(currentFilter); #endif } @@ -1014,17 +1035,30 @@ void IN_SendKeyEvents (void) #if defined(USE_SDL2) case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) + { + IN_RestoreMouseEvents(); S_UnblockSound(); + } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) + { + IN_BeginIgnoringMouseEvents(); S_BlockSound(); + } break; #else case SDL_ACTIVEEVENT: if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE)) { if (event.active.gain) + { + IN_RestoreMouseEvents(); S_UnblockSound(); - else S_BlockSound(); + } + else + { + IN_BeginIgnoringMouseEvents(); + S_BlockSound(); + } } break; #endif