From 010ac2bcf46ac0184c4e330d9b515d6d613b8d4e Mon Sep 17 00:00:00 2001 From: Matias N Date: Mon, 2 Nov 2020 18:06:45 -0300 Subject: [PATCH] sim: correctly handle X11 button state/events --- arch/sim/src/sim/up_x11eventloop.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/arch/sim/src/sim/up_x11eventloop.c b/arch/sim/src/sim/up_x11eventloop.c index 8cd8d25968..12c290548b 100644 --- a/arch/sim/src/sim/up_x11eventloop.c +++ b/arch/sim/src/sim/up_x11eventloop.c @@ -58,11 +58,13 @@ extern Display *g_display; * Name: up_buttonmap ****************************************************************************/ -static int up_buttonmap(int state) +static int up_buttonmap(int state, int button) { int buttons = 0; - /* Remove any X11 dependencies. Just maps ButtonNMask to bit N. */ + /* "state" is a bitmask representing the state prior to the event, so + * translate that first to our button bitmap + */ if ((state & Button1Mask) != 0) { @@ -79,6 +81,23 @@ static int up_buttonmap(int state) buttons |= 4; } + /* button represents the button which changed state, so change the + * corresponding bit now + */ + + switch(button) + { + case Button1: + buttons ^= 1; + break; + case Button2: + buttons ^= 2; + break; + case Button3: + buttons ^= 4; + break; + } + return buttons; } @@ -115,7 +134,7 @@ void up_x11events(void) case MotionNotify : /* Enabled by ButtonMotionMask */ { up_buttonevent(event.xmotion.x, event.xmotion.y, - up_buttonmap(event.xmotion.state)); + up_buttonmap(event.xmotion.state, 0)); } break; @@ -123,7 +142,8 @@ void up_x11events(void) case ButtonRelease: /* Enabled by ButtonReleaseMask */ { up_buttonevent(event.xbutton.x, event.xbutton.y, - up_buttonmap(event.xbutton.state)); + up_buttonmap(event.xbutton.state, + event.xbutton.button)); } break;