Skip to content

Commit 16aeb8d

Browse files
committed
Guarantee that we don't dispatch any mouse motion from before or including the last mouse warp
1 parent 649466f commit 16aeb8d

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/video/windows/SDL_windowsevents.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,16 @@ WIN_PumpEvents(_THIS)
15501550
g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
15511551
}
15521552

1553+
/* Don't dispatch any mouse motion queued prior to or including the last mouse warp */
1554+
if (msg.message == WM_MOUSEMOVE && SDL_last_warp_time) {
1555+
if (!SDL_TICKS_PASSED(msg.time, (SDL_last_warp_time + 1))) {
1556+
continue;
1557+
}
1558+
1559+
/* This mouse message happened after the warp */
1560+
SDL_last_warp_time = 0;
1561+
}
1562+
15531563
/* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
15541564
TranslateMessage(&msg);
15551565
DispatchMessage(&msg);

src/video/windows/SDL_windowsmouse.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "../../events/SDL_mouse_c.h"
2828

2929

30+
DWORD SDL_last_warp_time = 0;
3031
HCURSOR SDL_cursor = NULL;
3132
static SDL_Cursor *SDL_blank_cursor = NULL;
3233

@@ -253,16 +254,11 @@ WIN_WarpMouse(SDL_Window * window, int x, int y)
253254
SetCursorPos(pt.x, pt.y);
254255

255256
/* Flush any pending mouse motion and simulate motion for this warp */
256-
{
257-
SDL_Mouse *mouse = SDL_GetMouse();
258-
const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
259-
MSG msg;
260-
261-
while (PeekMessage(&msg, data->hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)) {
262-
continue;
263-
}
264-
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
257+
SDL_last_warp_time = GetTickCount();
258+
if (!SDL_last_warp_time) {
259+
SDL_last_warp_time = 1;
265260
}
261+
SDL_SendMouseMotion(window, SDL_GetMouse()->mouseID, 0, x, y);
266262
}
267263

268264
static int

src/video/windows/SDL_windowsmouse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#ifndef SDL_windowsmouse_h_
2424
#define SDL_windowsmouse_h_
2525

26+
extern DWORD SDL_last_warp_time;
2627
extern HCURSOR SDL_cursor;
2728

2829
extern void WIN_InitMouse(_THIS);

0 commit comments

Comments
 (0)