From 7f3e91bdf815f25b3508ba2e8ce4aa118232d99e Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 18 Nov 2011 02:54:50 -0500 Subject: [PATCH] Make XInput2 target return same mouse buttons as every other target. --- x11_xinput2.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/x11_xinput2.c b/x11_xinput2.c index 3069aa1..f287eae 100644 --- a/x11_xinput2.c +++ b/x11_xinput2.c @@ -382,6 +382,18 @@ static int get_next_x11_event(XEvent *xev) } /* 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 @@ static void pump_events(void) 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. */