diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index caa7e4d..48fb4d1 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -133,6 +133,30 @@ static void IN_EndIgnoringMouseEvents(void) #endif } +static SDL_EventFilter prevFilter = NULL; + +static void IN_BeginIgnoringMouseEvents2(void) +{ +#if defined(USE_SDL2) + void *userdata = NULL; + SDL_GetEventFilter(&prevFilter, &userdata); + SDL_SetEventFilter(IN_SDL2_FilterMouseEvents, NULL); + (void) userdata; +#else + prevFilter = SDL_GetEventFilter(); + SDL_SetEventFilter(IN_FilterMouseEvents); +#endif +} + +static void IN_RestoreMouseEvents(void) +{ +#if defined(USE_SDL2) + SDL_SetEventFilter(prevFilter, NULL); +#else + SDL_SetEventFilter(prevFilter); +#endif +} + #ifdef MACOS_X_ACCELERATION_HACK static cvar_t in_disablemacosxmouseaccel = {"in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE}; static double originalMouseSpeed = -1.0; @@ -1014,17 +1038,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_BeginIgnoringMouseEvents2(); 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_BeginIgnoringMouseEvents2(); + S_BlockSound(); + } } break; #endif