Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_GetGlobalMouseState() returns incorrect mouse coordinates on certain dual monitor setup (X11) #1679

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 1 comment

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.3
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2014-10-29 22:19:06 +0000, Dmitry 'RCL' Rekman wrote:

If the primary X11 screen has a non-zero offset (e.g. X=2560,Y=0) as returned by SDL_GetDisplayBounds(), mouse coordinates returned by SDL_GetGlobalMouseState() will be incorrect (the said offset of the primary screen will be added to them).

The patch below (also mailed to sdl@lists.libsdl.org - http://lists.libsdl.org/pipermail/sdl-libsdl.org/2014-October/096764.html) fixes that:

diff -r bfdc18891a60 src/video/x11/SDL_x11mouse.c
--- a/src/video/x11/SDL_x11mouse.c Mon Oct 27 19:53:44 2014 -0400
+++ b/src/video/x11/SDL_x11mouse.c Wed Oct 29 16:33:25 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;
           }
       }
    

On 2014-10-30 17:15:08 +0000, Ryan C. Gordon wrote:

This patch is now https://hg.libsdl.org/SDL/rev/f20d288435bd, thanks!

--ryan.

@slajerek
Copy link

My users reported that this is still happening in 2.0.18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants