[PATCH] Fix for SDL_GetGlobalMouseState()

Hi,

what follows is a proposed patch to SDL_GetGlobalMouseState() that fixes it
on dual monitor X11 setups. Without it, returned mouse coordinates aren’t
correct if the primary screen is not the leftmost one (or in general, has a
non-zero X/Y offset).

This was discussed (on IRC) and tentatively Okay’ed by both icculus and
Plagman.

Regards,
Dmitry

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;
           }
       }

Hello, there!

(Just trying to help the SDL2 development team) Could you please also file this bug report at https://bugzilla.libsdl.org/ ? This ought to help keep this message from getting misplaced, and lets Sam & co better organize it all.

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/10/ 29, at 15:35, Dmitry Rekman <dmitry.rekman at epicgames.com> wrote:

Hi,

what follows is a proposed patch to SDL_GetGlobalMouseState() that fixes it on dual monitor X11 setups. Without it, returned mouse coordinates aren’t correct if the primary screen is not the leftmost one (or in general, has a non-zero X/Y offset).

This was discussed (on IRC) and tentatively Okay’ed by both icculus and Plagman.

Regards,
Dmitry

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;
           }
       }
    

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Could you please also file this bug report at https://bugzilla.libsdl.org/
?

Sure. Filed bug #2770 (https://bugzilla.libsdl.org/show_bug.cgi?id=2770).

Regards,
DmitryOn Wed, Oct 29, 2014 at 5:22 PM, Jeffrey Carpenter wrote:

Hello, there!

(Just trying to help the SDL2 development team) Could you please also file
this bug report at https://bugzilla.libsdl.org/ ? This ought to help keep
this message from getting misplaced, and lets Sam & co better organize it
all.

Cheers,
Jeffrey Carpenter

On 2014/10/ 29, at 15:35, Dmitry Rekman <@Dmitry_Rekman> wrote:

Hi,

what follows is a proposed patch to SDL_GetGlobalMouseState() that fixes
it on dual monitor X11 setups. Without it, returned mouse coordinates
aren’t correct if the primary screen is not the leftmost one (or in
general, has a non-zero X/Y offset).

This was discussed (on IRC) and tentatively Okay’ed by both icculus and
Plagman.

Regards,
Dmitry

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;
           }
       }
    

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org