From 82793ac279d19b5bde8fc2bd62877b05ba5a76e0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 14 Oct 2021 14:26:21 -0700
Subject: [PATCH] Fixed mouse warping while in relative mode
We should get a mouse event with an absolute position and no relative motion and shouldn't change the OS cursor position at all
---
src/events/SDL_mouse.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 6bb8307b9d..a441965e11 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -384,6 +384,8 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
if (!mouse->has_position) {
xrel = 0;
yrel = 0;
+ mouse->x = x;
+ mouse->y = y;
mouse->has_position = SDL_TRUE;
} else if (!xrel && !yrel) { /* Drop events that don't change state */
#ifdef DEBUG_MOUSE
@@ -765,10 +767,14 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
return;
}
- if (mouse->WarpMouse) {
+ /* Ignore the previous position when we warp */
+ mouse->has_position = SDL_FALSE;
+
+ if (mouse->WarpMouse &&
+ (!mouse->relative_mode || mouse->relative_mode_warp)) {
mouse->WarpMouse(window, x, y);
} else {
- SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
+ SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
}
}