X11: Fixed SDL_GetGlobalMouseState() to work better with multimonitor configs.
authorDmitry Rekman <dmitry.rekman@epicgames.com>
Wed, 29 Oct 2014 22:55:40 -0400
changeset 9206 f20d288435bd
parent 9205 5302aee2916a
child 9207 10f4459a8b9a
X11: Fixed SDL_GetGlobalMouseState() to work better with multimonitor configs. Fixes Bugzilla #2770. Thanks to Epic Games for contributing this fix.
src/video/x11/SDL_x11mouse.c
--- a/src/video/x11/SDL_x11mouse.c	Wed Oct 29 22:44:35 2014 +0100
+++ b/src/video/x11/SDL_x11mouse.c	Wed Oct 29 22:55:40 2014 -0400
@@ -382,8 +382,14 @@
                 retval |= (mask & Button1Mask) ? SDL_BUTTON_LMASK : 0;
                 retval |= (mask & Button2Mask) ? SDL_BUTTON_MMASK : 0;
                 retval |= (mask & Button3Mask) ? SDL_BUTTON_RMASK : 0;
-                *x = data->x + rootx;
-                *y = data->y + rooty;
+                /* SDL_DisplayData->x,y point to screen origin, and adding them to mouse coordinates relative to root window doesn't do the right thing
+                 * (observed on dual monitor setup with primary display being the rightmost one - mouse was offset to the right).
+                 *
+                 * Adding root position to root-relative coordinates seems to be a better way to get absolute position. */
+                XWindowAttributes root_attrs;
+                X11_XGetWindowAttributes(display, root, &root_attrs);
+                *x = root_attrs.x + rootx;
+                *y = root_attrs.y + rooty;
                 return retval;
             }
         }