Guarantee that we don't dispatch any mouse motion from before or including the last mouse warp
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index bb8504c..a099fa6 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -1550,6 +1550,16 @@ WIN_PumpEvents(_THIS)
g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
}
+ /* Don't dispatch any mouse motion queued prior to or including the last mouse warp */
+ if (msg.message == WM_MOUSEMOVE && SDL_last_warp_time) {
+ if (!SDL_TICKS_PASSED(msg.time, (SDL_last_warp_time + 1))) {
+ continue;
+ }
+
+ /* This mouse message happened after the warp */
+ SDL_last_warp_time = 0;
+ }
+
/* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
TranslateMessage(&msg);
DispatchMessage(&msg);
diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c
index 2492243..dd34bdc 100644
--- a/src/video/windows/SDL_windowsmouse.c
+++ b/src/video/windows/SDL_windowsmouse.c
@@ -27,6 +27,7 @@
#include "../../events/SDL_mouse_c.h"
+DWORD SDL_last_warp_time = 0;
HCURSOR SDL_cursor = NULL;
static SDL_Cursor *SDL_blank_cursor = NULL;
@@ -253,16 +254,11 @@ WIN_WarpMouse(SDL_Window * window, int x, int y)
SetCursorPos(pt.x, pt.y);
/* Flush any pending mouse motion and simulate motion for this warp */
- {
- SDL_Mouse *mouse = SDL_GetMouse();
- const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
- MSG msg;
-
- while (PeekMessage(&msg, data->hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)) {
- continue;
- }
- SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
+ SDL_last_warp_time = GetTickCount();
+ if (!SDL_last_warp_time) {
+ SDL_last_warp_time = 1;
}
+ SDL_SendMouseMotion(window, SDL_GetMouse()->mouseID, 0, x, y);
}
static int
diff --git a/src/video/windows/SDL_windowsmouse.h b/src/video/windows/SDL_windowsmouse.h
index f89a20b..68279a6 100644
--- a/src/video/windows/SDL_windowsmouse.h
+++ b/src/video/windows/SDL_windowsmouse.h
@@ -23,6 +23,7 @@
#ifndef SDL_windowsmouse_h_
#define SDL_windowsmouse_h_
+extern DWORD SDL_last_warp_time;
extern HCURSOR SDL_cursor;
extern void WIN_InitMouse(_THIS);