Fix: Use WIN_ClientPointToSDL for converting additional mouse coordinates
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
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index caba8b4..20acb8f 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -428,9 +428,13 @@ WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus)
/* In relative mode we are guaranteed to have mouse focus if we have keyboard focus */
if (!SDL_GetMouse()->relative_mode) {
+ SDL_Point point;
GetCursorPos(&cursorPos);
ScreenToClient(hwnd, &cursorPos);
- SDL_SendMouseMotion(window, 0, 0, cursorPos.x, cursorPos.y);
+ point.x = cursorPos.x;
+ point.y = cursorPos.y;
+ WIN_ClientPointToSDL(data->window, &point.x, &point.y);
+ SDL_SendMouseMotion(window, 0, 0, point.x, point.y);
}
WIN_CheckAsyncMouseRelease(data);
@@ -909,17 +913,21 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode && !IsIconic(hwnd)) {
SDL_Mouse *mouse;
POINT cursorPos;
+ SDL_Point point;
GetCursorPos(&cursorPos);
ScreenToClient(hwnd, &cursorPos);
+ point.x = cursorPos.x;
+ point.y = cursorPos.y;
+ WIN_ClientPointToSDL(data->window, &point.x, &point.y);
mouse = SDL_GetMouse();
if (!mouse->was_touch_mouse_events) { /* we're not a touch handler causing a mouse leave? */
- SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
+ SDL_SendMouseMotion(data->window, 0, 0, point.x, point.y);
} else { /* touch handling? */
mouse->was_touch_mouse_events = SDL_FALSE; /* not anymore */
if (mouse->touch_mouse_events) { /* convert touch to mouse events */
- SDL_SendMouseMotion(data->window, SDL_TOUCH_MOUSEID, 0, cursorPos.x, cursorPos.y);
+ SDL_SendMouseMotion(data->window, SDL_TOUCH_MOUSEID, 0, point.x, point.y);
} else { /* normal handling */
- SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
+ SDL_SendMouseMotion(data->window, 0, 0, point.x, point.y);
}
}
}
@@ -1679,13 +1687,17 @@ static void WIN_UpdateMouseCapture()
SDL_WindowData *data = (SDL_WindowData *) focusWindow->driverdata;
if (!data->mouse_tracked) {
- POINT pt;
+ POINT cursorPos;
- if (GetCursorPos(&pt) && ScreenToClient(data->hwnd, &pt)) {
+ if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) {
SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
SDL_MouseID mouseID = SDL_GetMouse()->mouseID;
+ SDL_Point point;
+ point.x = cursorPos.x;
+ point.y = cursorPos.y;
+ WIN_ClientPointToSDL(data->window, &point.x, &point.y);
- SDL_SendMouseMotion(data->window, mouseID, 0, (int)pt.x, (int)pt.y);
+ SDL_SendMouseMotion(data->window, mouseID, 0, point.x, point.y);
SDL_SendMouseButton(data->window, mouseID, GetAsyncKeyState(VK_LBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, !swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT);
SDL_SendMouseButton(data->window, mouseID, GetAsyncKeyState(VK_RBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, !swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT);
SDL_SendMouseButton(data->window, mouseID, GetAsyncKeyState(VK_MBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE);