We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3847

Summary: Hit Test x coordinate wrong on secondary monitor
Product: SDL Reporter: Robert Turner <rob.w.turner>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: 2.0.5   
Hardware: x86_64   
OS: Windows 10   

Description Robert Turner 2017-09-25 19:35:37 UTC
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.
Comment 1 Ozkan Sezer 2017-09-26 10:05:36 UTC
Is this a one liner at line 956 (like below)?

--- SDL2/src/video/windows/SDL_windowsevents.c.orig
+++ SDL2/src/video/windows/SDL_windowsevents.c
@@ -953,7 +953,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPAR
         {
             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);
Comment 2 Robert Turner 2017-09-26 10:12:33 UTC
Yes, that one line diff matches the change I made locally. I was only able to test on Windows 10, building with Visual Studio 2017, but in my environment that was enough to fix the x-coordinate value.
Comment 3 Ozkan Sezer 2017-09-26 10:15:00 UTC
> MSDN documentation suggests that ...

Indeed, the WM_NCHITTEST documentation supports your change
https://msdn.microsoft.com/en-us/library/windows/desktop/ms645618(v=vs.85).aspx
Comment 4 Sam Lantinga 2017-09-26 22:07:47 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/d4ac9c6d2528