From 78fa572df01e719a2af59859df6c74a2a741b0a0 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 4 Jan 2023 19:33:06 -0800 Subject: [PATCH] SDL: only react to window focus changes if state actually changes Because the state carries over for each call to Impl_HandleWindowEvent, once the window has been focused, events that do not change the focus state behave as if the window was just refocused, anyway. On linux i3wm, some such window events propogate constantly in fullscreen mode. --- src/sdl/i_video.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5cea8c65a..bdb522efb 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -572,10 +572,13 @@ static INT32 SDLJoyAxis(const Sint16 axis, UINT8 pid) static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { +#define FOCUSUNION (mousefocus | (kbfocus << 1)) static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; + const unsigned int oldfocus = FOCUSUNION; + switch (evt.event) { case SDL_WINDOWEVENT_ENTER: @@ -599,6 +602,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) window_y = evt.data2; } + if (FOCUSUNION == oldfocus) // No state change + { + return; + } + if (mousefocus && kbfocus) { // Tell game we got focus back, resume music if necessary @@ -639,7 +647,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) SDLdoUngrabMouse(); } } - +#undef FOCUSUNION } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)