From 15e02127dc077296dfcf3dfecccb267a6c5d9ae9 Mon Sep 17 00:00:00 2001 From: Sal Date: Fri, 6 Jan 2023 02:29:13 +0000 Subject: [PATCH] Merge branch 'fix-window-refocus' into 'master' SDL: only react to window focus changes if state actually changes See merge request KartKrew/Kart!859 --- 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 bf8ca28cc..ab02eb6d5 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -622,10 +622,13 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) 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: @@ -649,6 +652,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 @@ -688,7 +696,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) SDLdoUngrabMouse(); } } - +#undef FOCUSUNION } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)