From b9567776d7ce15b2b5bb7b6eb0e124353fe42b44 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 27 Sep 2013 23:35:17 -0700 Subject: [PATCH] # User Darren Salt # 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 0b577ecb44c96..c260019c67c6e 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -135,7 +135,9 @@ static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev, XPointer arg) { XEvent *event = (XEvent *) arg; + /* we only handle buttons 4 and 5 - false positive avoidance */ if (chkev->type == ButtonRelease && + (event->xbutton.button == Button4 || event->xbutton.button == Button5) && chkev->xbutton.button == event->xbutton.button && chkev->xbutton.time == event->xbutton.time) 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 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 - 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, (XPointer) event)) {