Browse Source

# User Darren Salt <[email protected]>
# Date 1379621782 -3600
# Thu Sep 19 21:16:22 2013 +0100
Work around a false-positive in the X11 mouse wheel code

This false positive occurs when one particular button on my mouse is
pressed. The kernel which I'm using is patched to cause a release event to
be synthesised immediately when the mouse says that this button is pressed
because the mouse doesn't signal release until the button is next pressed.

(Also documents a false negative, observed with the horizontal scroll wheel
on the same mouse.)

Sam Lantinga 12 years ago
parent
commit
b9567776d7
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/video/x11/SDL_x11events.c

+ 8 - 1
src/video/x11/SDL_x11events.c

@@ -135,7 +135,9 @@ static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev,
     XPointer arg)
     XPointer arg)
 {
 {
     XEvent *event = (XEvent *) arg;
     XEvent *event = (XEvent *) arg;
+    /* we only handle buttons 4 and 5 - false positive avoidance */
     if (chkev->type == ButtonRelease &&
     if (chkev->type == ButtonRelease &&
+        (event->xbutton.button == Button4 || event->xbutton.button == Button5) &&
         chkev->xbutton.button == event->xbutton.button &&
         chkev->xbutton.button == event->xbutton.button &&
         chkev->xbutton.time == event->xbutton.time)
         chkev->xbutton.time == event->xbutton.time)
         return True;
         return True;
@@ -150,7 +152,12 @@ static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks)
            however, mouse wheel events trigger a button press and a button release
            however, mouse wheel events trigger a button press and a button release
            immediately. thus, checking if the same button was released at the same
            immediately. thus, checking if the same button was released at the same
            time as it was pressed, should be an adequate hack to derive a mouse
            time as it was pressed, should be an adequate hack to derive a mouse
-           wheel event. */
+           wheel event.
+           However, there is broken and unusual hardware out there...
+           - False positive: a button for which a release event is
+             generated (or synthesised) immediately.
+           - False negative: a wheel which, when rolled, doesn't have
+             a release event generated immediately. */
         if (XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent,
         if (XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent,
             (XPointer) event)) {
             (XPointer) event)) {