Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: [PATCH] Linux: fix broken relative mouse movement distances  (Read 628 times)

mfranz

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 5
    • View Profile

Relative mouse distances are currently unreliable, because the code doesn't consider that the "while (XPending(display) > 0)" loop handles several XMotionEvents in one go. After such a set the abs values are correct, but the rel values only contain the relative distances of the last event! So all the relative distances don't add up to the absolute coordinates and are, thus, completely useless. Any application using them anyway faces the following problems: (a) The mouse seems to move much slower than it actually does, because events are effectively dropped in the rel value. (b) The window loses X11 focus at a time when the mouse still appears to be in the window. This creates the illusion of invisible barriers in the window, which can't easily be overcome.

The following patch fixes it. Please apply and consider making a new release. This is quite a serious bug!

Code: [Select]
--- LinuxMouse.cpp      (revision 13)
+++ LinuxMouse.cpp      (working copy)
@@ -172,15 +172,17 @@
                        }
 
                        //Compute this frames Relative X & Y motion
-                       mState.X.rel = event.xmotion.x - oldXMouseX;
-                       mState.Y.rel = event.xmotion.y - oldXMouseY;
+                       int dx = event.xmotion.x - oldXMouseX;
+                       int dy = event.xmotion.y - oldXMouseY;
 
                        //Store old values for next time to compute relative motion
                        oldXMouseX = event.xmotion.x;
                        oldXMouseY = event.xmotion.y;
 
-                       mState.X.abs += mState.X.rel;
-                       mState.Y.abs += mState.Y.rel;
+                       mState.X.abs += dx;
+                       mState.Y.abs += dy;
+                       mState.X.rel += dx;
+                       mState.Y.rel += dy;
 
                        //Check to see if we are grabbing the mouse to the window (requires clipping and warping)
                        if( grabMouse )
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: [PATCH] Linux: fix broken relative mouse movement distances
« Reply #1 on: July 25, 2010, 05:35:03 PM »

Added this patch to svn. As with the other, will test this more tomorrow. There are also some Windows mouse handling patches to look into.

As for a release, I'm shooting for August 9th'ish - I will be on vacation then and have some time to prepare.
Logged