The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[PATCH] Fix for SDL_GetGlobalMouseState()
Dmitry Rekman
Guest

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;
             }
         }
[PATCH] Fix for SDL_GetGlobalMouseState()
Jeffrey Carpenter
Guest

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 wrote:

Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
[PATCH] Fix for SDL_GetGlobalMouseState()
Dmitry Rekman
Guest

Quote:
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,
Dmitry

On Wed, Oct 29, 2014 at 5:22 PM, Jeffrey Carpenter wrote:
Quote:
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 wrote:

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



Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org