133 |
133 |
134 static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev, |
134 static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev, |
135 XPointer arg) |
135 XPointer arg) |
136 { |
136 { |
137 XEvent *event = (XEvent *) arg; |
137 XEvent *event = (XEvent *) arg; |
|
138 /* we only handle buttons 4 and 5 - false positive avoidance */ |
138 if (chkev->type == ButtonRelease && |
139 if (chkev->type == ButtonRelease && |
|
140 (event->xbutton.button == Button4 || event->xbutton.button == Button5) && |
139 chkev->xbutton.button == event->xbutton.button && |
141 chkev->xbutton.button == event->xbutton.button && |
140 chkev->xbutton.time == event->xbutton.time) |
142 chkev->xbutton.time == event->xbutton.time) |
141 return True; |
143 return True; |
142 return False; |
144 return False; |
143 } |
145 } |
148 if (XPending(display)) { |
150 if (XPending(display)) { |
149 /* according to the xlib docs, no specific mouse wheel events exist. |
151 /* according to the xlib docs, no specific mouse wheel events exist. |
150 however, mouse wheel events trigger a button press and a button release |
152 however, mouse wheel events trigger a button press and a button release |
151 immediately. thus, checking if the same button was released at the same |
153 immediately. thus, checking if the same button was released at the same |
152 time as it was pressed, should be an adequate hack to derive a mouse |
154 time as it was pressed, should be an adequate hack to derive a mouse |
153 wheel event. */ |
155 wheel event. |
|
156 However, there is broken and unusual hardware out there... |
|
157 - False positive: a button for which a release event is |
|
158 generated (or synthesised) immediately. |
|
159 - False negative: a wheel which, when rolled, doesn't have |
|
160 a release event generated immediately. */ |
154 if (XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent, |
161 if (XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent, |
155 (XPointer) event)) { |
162 (XPointer) event)) { |
156 |
163 |
157 /* by default, X11 only knows 5 buttons. on most 3 button + wheel mouse, |
164 /* by default, X11 only knows 5 buttons. on most 3 button + wheel mouse, |
158 Button4 maps to wheel up, Button5 maps to wheel down. */ |
165 Button4 maps to wheel up, Button5 maps to wheel down. */ |