Relative mouse mode grab is based on the window with the input focus This fixes restoring the cursor clip rectangle after the mouse has moved off of the window. Also try to better synchronize cursor visibility with mouse position changes when changing relative mode. This doesn't work perfectly, but it seems to improve things on Windows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 184942e..aad433d 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -820,6 +820,11 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
mouse->scale_accum_x = 0.0f;
mouse->scale_accum_y = 0.0f;
+ if (enabled) {
+ /* Update cursor visibility before we potentially warp the mouse */
+ SDL_SetCursor(NULL);
+ }
+
if (enabled && focusWindow) {
SDL_SetMouseFocus(focusWindow);
@@ -827,21 +832,23 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
}
- if (mouse->focus) {
- SDL_UpdateWindowGrab(mouse->focus);
+ if (focusWindow) {
+ SDL_UpdateWindowGrab(focusWindow);
/* Put the cursor back to where the application expects it */
if (!enabled) {
- SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
+ SDL_WarpMouseInWindow(focusWindow, mouse->x, mouse->y);
}
}
+ if (!enabled) {
+ /* Update cursor visibility after we restore the mouse position */
+ SDL_SetCursor(NULL);
+ }
+
/* Flush pending mouse motion - ideally we would pump events, but that's not always safe */
SDL_FlushEvent(SDL_MOUSEMOTION);
- /* Update cursor visibility */
- SDL_SetCursor(NULL);
-
return 0;
}