Commit 8fb95034e84ded56bceb6b12d36a2864222582a4

Dean Herbert 2021-04-02T12:52:21

Avoid warping the cursor to the center of the window when not in relative_warp_mode When relative mode is enabled and not using warp mode, the cursor is being clipped to the window. Therefore there is no reason to restore the cursor position to the center. Avoiding the warp to center simplifies mouse position event flow, as we are no longer potentially receiving mouse events for the automated movement of the cursor and can be (mostly) assured that an incoming event from the windowing system is that of external means.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 67cf22a..a776bcc 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -819,11 +819,10 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
     mouse->scale_accum_y = 0.0f;
 
     if (enabled && focusWindow) {
-        /* Center it in the focused window to prevent clicks from going through
-         * to background windows.
-         */
         SDL_SetMouseFocus(focusWindow);
-        SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
+
+        if (mouse->relative_mode_warp)
+            SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
     }
 
     if (mouse->focus) {