| Summary: | Hit Test x coordinate wrong on secondary monitor | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Robert Turner <rob.w.turner> |
| Component: | video | Assignee: | 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 | ||
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);
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. > 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 Fixed, thanks! https://hg.libsdl.org/SDL/rev/d4ac9c6d2528 |
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.