Skip to content

Commit 649466f

Browse files
committed
Flush any pending mouse motion when warping the mouse cursor
Fixes #4165
1 parent ad52057 commit 649466f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/video/windows/SDL_windowsmouse.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,18 @@ WIN_WarpMouse(SDL_Window * window, int x, int y)
251251
pt.y = y;
252252
ClientToScreen(hwnd, &pt);
253253
SetCursorPos(pt.x, pt.y);
254+
255+
/* 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);
265+
}
254266
}
255267

256268
static int

0 commit comments

Comments
 (0)