From 011634a6f8df4fb6b6c24dc173680b96c7fb16f1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 1 Feb 2010 20:26:21 +0100 Subject: button: simplify button handling Make better use of the bit representation, reducing one layer of conversion. --- src/gestures.c | 10 ++-------- src/gestures.h | 2 +- src/multitouch.c | 13 +++++++------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/gestures.c b/src/gestures.c index 89dad1a..0b0ba1d 100644 --- a/src/gestures.c +++ b/src/gestures.c @@ -57,14 +57,8 @@ void extract_gestures(struct Gestures *gs, struct MTouch* mt) if (nsf == 3) mt->ns.button = BITMASK(MT_BUTTON_MIDDLE); } - for (i = 0; i < DIM_BUTTON; i++) { - if (GETBIT(mt->ns.button, i) != GETBIT(mt->os.button, i)) { - SETBIT(gs->type, GS_BUTTON); - gs->btix[gs->nbt] = i + 1; - gs->btval[gs->nbt] = GETBIT(mt->ns.button, i); - gs->nbt++; - } - } + gs->btmask = (mt->ns.button ^ mt->os.button) & BITONES(DIM_BUTTON); + gs->btdata = mt->ns.button & BITONES(DIM_BUTTON); mt->os = mt->ns; } diff --git a/src/gestures.h b/src/gestures.h index 4b2d948..f83cae2 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -37,7 +37,7 @@ struct Gestures { unsigned type; int dx, dy; - int nbt, btix[DIM_BUTTON], btval[DIM_BUTTON]; + button_t btmask, btdata; }; //////////////////////////////////////////////////////// diff --git a/src/multitouch.c b/src/multitouch.c index f6e5305..fa966ce 100644 --- a/src/multitouch.c +++ b/src/multitouch.c @@ -231,12 +231,13 @@ static void handle_gestures(LocalDevicePtr local, int hstep = 1 + hscroll_fraction * (caps->abs_position_x.maximum - caps->abs_position_x.minimum); - int i; - for (i = 0; i < gs->nbt; i++) { - xf86PostButtonEvent(local->dev, FALSE, - gs->btix[i], gs->btval[i], - 0, 0); - TRACE2("button: %d %d\n", gs->btix[i], gs->btval[i]); + int i; + for (i = 0; i < DIM_BUTTON; i++) { + if (GETBIT(gs->btmask, i)) { + xf86PostButtonEvent(local->dev, FALSE, + i + 1, GETBIT(gs->btdata, i), 0, 0); + TRACE2("button bit: %d %d\n", i, GETBIT(gs->btdata, i)); + } } if (GETBIT(gs->type, GS_MOVE)) { xf86PostMotionEvent(local->dev, 0, 0, 2, -- cgit v1.2.3