X11: Fixed SDL_GetGlobalMouseState() to work better with multimonitor configs.
Fixes Bugzilla #2770.
Thanks to Epic Games for contributing this fix.
1.1 --- a/src/video/x11/SDL_x11mouse.c Wed Oct 29 22:44:35 2014 +0100
1.2 +++ b/src/video/x11/SDL_x11mouse.c Wed Oct 29 22:55:40 2014 -0400
1.3 @@ -382,8 +382,14 @@
1.4 retval |= (mask & Button1Mask) ? SDL_BUTTON_LMASK : 0;
1.5 retval |= (mask & Button2Mask) ? SDL_BUTTON_MMASK : 0;
1.6 retval |= (mask & Button3Mask) ? SDL_BUTTON_RMASK : 0;
1.7 - *x = data->x + rootx;
1.8 - *y = data->y + rooty;
1.9 + /* SDL_DisplayData->x,y point to screen origin, and adding them to mouse coordinates relative to root window doesn't do the right thing
1.10 + * (observed on dual monitor setup with primary display being the rightmost one - mouse was offset to the right).
1.11 + *
1.12 + * Adding root position to root-relative coordinates seems to be a better way to get absolute position. */
1.13 + XWindowAttributes root_attrs;
1.14 + X11_XGetWindowAttributes(display, root, &root_attrs);
1.15 + *x = root_attrs.x + rootx;
1.16 + *y = root_attrs.y + rooty;
1.17 return retval;
1.18 }
1.19 }