From 54685787ca7677d711cabe355a29d78627362223 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Sep 2017 15:07:35 -0700 Subject: [PATCH] Fixed bug 3847 - Hit Test x coordinate wrong on secondary monitor Robert Turner SDL_windowsevents.c contains code to retrieve the x and y coordinate for a requested hit test. It does this as follows: POINT winpoint = { (int) LOWORD(lParam), (int) HIWORD(lParam) }; LOWORD(lParam) does not correctly mask off high bits that are set if the point is on a second (or third, etc.) monitor. This effectively offsets the x-coordinate by a large value. MSDN documentation suggests that LOWORD() and HIWORD() are the wrong macros for the task, instead suggesting we should be doing something like the following: POINT winpoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; Testing this change on my Windows 10 machine with 2 monitors gives the correct results. --- src/video/windows/SDL_windowsevents.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 015ae88e2..b73e9df8b 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -961,7 +961,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { SDL_Window *window = data->window; if (window->hit_test) { - POINT winpoint = { (int) LOWORD(lParam), (int) HIWORD(lParam) }; + POINT winpoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; if (ScreenToClient(hwnd, &winpoint)) { const SDL_Point point = { (int) winpoint.x, (int) winpoint.y }; const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);