From dc30a00a26e00b5ef85e5312c33c01ae19e6c1f4 Mon Sep 17 00:00:00 2001
From: expikr <[EMAIL REDACTED]>
Date: Fri, 25 Apr 2025 02:42:50 +0800
Subject: [PATCH] use GetMessagePos instead of GetCursorPos
(cherry picked from commit a82f70dc21a061473eb5eada165e05daa9dd512c)
---
src/video/windows/SDL_windowsevents.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index f83dfcc59f4e3..8a07ac117a591 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -1498,8 +1498,10 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
if (!(data->window->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode && !IsIconic(hwnd)) {
SDL_Mouse *mouse;
+ DWORD pos = GetMessagePos();
POINT cursorPos;
- GetCursorPos(&cursorPos);
+ cursorPos.x = GET_X_LPARAM(pos);
+ cursorPos.y = GET_Y_LPARAM(pos);
ScreenToClient(hwnd, &cursorPos);
mouse = SDL_GetMouse();
if (!mouse->was_touch_mouse_events) { // we're not a touch handler causing a mouse leave?
@@ -1638,7 +1640,7 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
// Reference: https://gamedev.net/forums/topic/672094-keeping-things-moving-during-win32-moveresize-events/5254386/
if (SendMessage(hwnd, WM_NCHITTEST, wParam, lParam) == HTCAPTION) {
POINT cursorPos;
- GetCursorPos(&cursorPos);
+ GetCursorPos(&cursorPos); // want the most current pos so as to not cause position change
ScreenToClient(hwnd, &cursorPos);
PostMessage(hwnd, WM_MOUSEMOVE, 0, cursorPos.x | (((Uint32)((Sint16)cursorPos.y)) << 16));
}