SDL: Relative mouse motion is delivered to the window with keyboard focus

From 91a55a02ded0900f60c8ee378992d091c4168dff Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 13 Aug 2021 23:59:39 -0700
Subject: [PATCH] Relative mouse motion is delivered to the window with
 keyboard focus

This was the original intent (note SDL_UpdateWindowGrab() in SDL_OnWindowFocusGained() and SDL_OnWindowFocusLost()) and fixes a bug where relative motion unexpectedly stops if the task bar is covering the bottom of the game window and the mouse happens to move over it while relative mode is enabled.

Another alternative would be to confine the mouse when relative mode is enabled, but that generates mouse motion which would need to be ignored, and it's possible for the user moving the mouse to combine with the mouse moving into the confined area so you can't easily tell whether to ignore the mouse motion. See https://github.com/libsdl-org/SDL/issues/4165 for a case where this is problematic.
---
 src/video/windows/SDL_windowsevents.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index bf3d75b401..6f4b5afe8b 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -714,7 +714,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             const SDL_bool isRelative = mouse->relative_mode || mouse->relative_mode_warp;
             const SDL_bool isCapture = ((data->window->flags & SDL_WINDOW_MOUSE_CAPTURE) != 0);
 
-            if (!isRelative || mouse->focus != data->window) {
+            /* Relative mouse motion is delivered to the window with keyboard focus */
+            if (!isRelative || data->window != SDL_GetKeyboardFocus()) {
                 if (!isCapture) {
                     break;
                 }