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 - Hit Test x coordinate wrong on secondary monitor
Summary: Hit Test x coordinate wrong on secondary monitor
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.5
Hardware: x86_64 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-25 19:35 UTC by Robert Turner
Modified: 2017-09-26 22:07 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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