Make XInput2 target return same mouse buttons as every other target.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 18 Nov 2011 02:54:50 -0500
changeset 118 0d0bd987e977
parent 117 a4676b3200fd
child 119 45c353d13c50
Make XInput2 target return same mouse buttons as every other target.
x11_xinput2.c
--- a/x11_xinput2.c	Fri Nov 18 02:45:35 2011 -0500
+++ b/x11_xinput2.c	Fri Nov 18 02:54:50 2011 -0500
@@ -382,6 +382,18 @@
 } /* get_next_x11_event */
 
 
+/* Everything else returns left (0), right (1), middle (2)...XI2 returns
+   right and middle in reverse, so swap them ourselves. */
+static inline int map_xi2_button(const int button)
+{
+    if (button == 2)
+        return 3;
+    else if (button == 3)
+        return 2;
+    return button;
+} /* map_xi2_button */
+
+
 static void pump_events(void)
 {
     ManyMouseEvent event;
@@ -442,7 +454,7 @@
                 mouse = find_mouse_by_devid(rawev->deviceid);
                 if (mouse != -1)
                 {
-                    const int button = rawev->detail;
+                    const int button = map_xi2_button(rawev->detail);
                     const int pressed = (xev.xcookie.evtype==XI_RawButtonPress);
 
                     /* gah, XInput2 still maps the wheel to buttons. */