From 428a29ac5dc8ebf6a1092c2d989fa020d79791af Mon Sep 17 00:00:00 2001 From: Arturo Castro Date: Wed, 14 Apr 2010 15:34:46 +0200 Subject: Extract pointing fingers Multi-finger clicks and taps are goverened by the number of pointing fingers on the trackpad. This number can be different from the actual number of fingers on the trackpad. For instance, a finger resting at the bottom of an integrated button, or a finger that accidentally touches the pad during a press, are not pointing fingers. This patch introduces extract_pointers(), which computes the number of pointing fingers on the trackpad, and uses that number to determine the logical button state. [rydberg@euromail.se: various cleanups] Signed-off-by: Arturo Castro Signed-off-by: Henrik Rydberg --- src/gestures.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/memory.h | 3 ++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/gestures.c b/src/gestures.c index d075356..915a521 100644 --- a/src/gestures.c +++ b/src/gestures.c @@ -29,6 +29,45 @@ static const int FINGER_ATTACK_MS = 70; static const int FINGER_DECAY_MS = 120; +static void extract_pointers(struct Gestures *gs, struct MTouch* mt) +{ + const struct FingerState *f = mt->state.finger; + int i; + + if (mt->state.nfinger < 2) { + mt->mem.pointing = mt->state.nfinger; + mt->mem.npoint = mt->state.nfinger; + mt->mem.ybar = mt->caps.abs_position_y.maximum; + return; + } + + if (mt->state.nfinger == mt->prev_state.nfinger) { + for (i = 0; i < mt->state.nfinger; i++) { + if (GETBIT(mt->mem.pointing, i)) + continue; + if (f[i].hw.position_y <= mt->mem.ybar) { + mt->mem.pointing = BITONES(mt->state.nfinger); + mt->mem.npoint = mt->state.nfinger; + return; + } + } + return; + } + + mt->mem.pointing = 0; + mt->mem.npoint = 0; + mt->mem.ybar = mt->caps.yclick; + for (i = 0; i < mt->state.nfinger; i++) { + if (f[i].hw.position_y > mt->caps.yclick) + continue; + if (!mt->mem.npoint || f[i].hw.position_y > mt->mem.ybar) + mt->mem.ybar = f[i].hw.position_y; + SETBIT(mt->mem.pointing, i); + mt->mem.npoint++; + } + +} + static void extract_movement(struct Gestures *gs, struct MTouch* mt) { const struct FingerState *prev[DIM_FINGER]; @@ -73,9 +112,9 @@ static void extract_buttons(struct Gestures *gs, struct MTouch* mt) { unsigned btdata = mt->state.button & BITONES(DIM_BUTTON); if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) { - if (mt->state.nfinger == 2) + if (mt->mem.npoint == 2) btdata = BITMASK(MT_BUTTON_RIGHT); - if (mt->state.nfinger == 3) + if (mt->mem.npoint == 3) btdata = BITMASK(MT_BUTTON_MIDDLE); } gs->btmask = (btdata ^ mt->mem.btdata) & BITONES(DIM_BUTTON); @@ -110,6 +149,7 @@ static void extract_type(struct Gestures *gs, struct MTouch* mt) void extract_gestures(struct Gestures *gs, struct MTouch* mt) { memset(gs, 0, sizeof(struct Gestures)); + extract_pointers(gs, mt); extract_movement(gs, mt); extract_buttons(gs, mt); extract_type(gs, mt); diff --git a/src/memory.h b/src/memory.h index 0ab4d04..3b947b9 100644 --- a/src/memory.h +++ b/src/memory.h @@ -25,7 +25,8 @@ #include "mtstate.h" struct Memory { - unsigned btdata; + unsigned btdata, pointing; + int npoint, ybar; mstime_t move_time; int move_x, move_y; }; -- cgit v1.2.3