Skip to content

Commit

Permalink
Fixed bug 3847 - Hit Test x coordinate wrong on secondary monitor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Sep 26, 2017
1 parent fb071a4 commit 5468578
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/video/windows/SDL_windowsevents.c
Expand Up @@ -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);
Expand Down

0 comments on commit 5468578

Please sign in to comment.