Commit 91a55a02ded0900f60c8ee378992d091c4168dff

Sam Lantinga 2021-08-13T23:59:39

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index bf3d75b..6f4b5af 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;
                 }