Commit adf3ce7c01002456dc567cf9bdb20f9166b4fb2c

Sam Lantinga 2022-07-05T21:42:24

Don't drop mouse focus on WM_MOUSELEAVE if the mouse is in relative mode; mouse-level is not meaningful for that case. Do drop mouse focus when keyboard focus is lost if the mouse is in relative mode.

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 8fbdccd..60e80a8 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -451,6 +451,10 @@ WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus)
         data->in_window_deactivation = SDL_TRUE;
 
         SDL_SetKeyboardFocus(NULL);
+        /* In relative mode we are guaranteed to not have mouse focus if we don't have keyboard focus */
+        if (SDL_GetMouse()->relative_mode) {
+            SDL_SetMouseFocus(NULL);
+        }
         WIN_ResetDeadKeys();
 
         if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
@@ -943,8 +947,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                }
             }
 
-            /* When WM_MOUSELEAVE is fired we can be assured that the cursor has left the window */
-            SDL_SetMouseFocus(NULL);
+            if (!SDL_GetMouse()->relative_mode) {
+                /* When WM_MOUSELEAVE is fired we can be assured that the cursor has left the window */
+                SDL_SetMouseFocus(NULL);
+            }
         }
 
         /* Once we get WM_MOUSELEAVE we're guaranteed that the window is no longer tracked */