# User Darren Salt <devspam@moreofthesa.me.uk>
authorSam Lantinga <slouken@libsdl.org>
Fri, 27 Sep 2013 23:35:17 -0700
changeset 77496073ad385c9b
parent 7748 3c9889bf2626
child 7750 48acb5c00c4b
# User Darren Salt <devspam@moreofthesa.me.uk>
# 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.)
src/video/x11/SDL_x11events.c
     1.1 --- a/src/video/x11/SDL_x11events.c	Fri Sep 27 23:29:05 2013 -0700
     1.2 +++ b/src/video/x11/SDL_x11events.c	Fri Sep 27 23:35:17 2013 -0700
     1.3 @@ -135,7 +135,9 @@
     1.4      XPointer arg)
     1.5  {
     1.6      XEvent *event = (XEvent *) arg;
     1.7 +    /* we only handle buttons 4 and 5 - false positive avoidance */
     1.8      if (chkev->type == ButtonRelease &&
     1.9 +        (event->xbutton.button == Button4 || event->xbutton.button == Button5) &&
    1.10          chkev->xbutton.button == event->xbutton.button &&
    1.11          chkev->xbutton.time == event->xbutton.time)
    1.12          return True;
    1.13 @@ -150,7 +152,12 @@
    1.14             however, mouse wheel events trigger a button press and a button release
    1.15             immediately. thus, checking if the same button was released at the same
    1.16             time as it was pressed, should be an adequate hack to derive a mouse
    1.17 -           wheel event. */
    1.18 +           wheel event.
    1.19 +           However, there is broken and unusual hardware out there...
    1.20 +           - False positive: a button for which a release event is
    1.21 +             generated (or synthesised) immediately.
    1.22 +           - False negative: a wheel which, when rolled, doesn't have
    1.23 +             a release event generated immediately. */
    1.24          if (XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent,
    1.25              (XPointer) event)) {
    1.26