From 1b9ca90240fc547c140de76d7e2abb51ee4f8d0a Mon Sep 17 00:00:00 2001 From: Arturo Castro Date: Sun, 11 Apr 2010 00:21:38 +0200 Subject: Delay movement after a finger configuration change The current code responds to finger movement immediately after a finger has been placed on the trackpad, even if the touch is accidental. This patch delays the effect of the finger by 70 ms, resulting in fewer accidental movements. Signed-off-by: Arturo Castro Signed-off-by: Henrik Rydberg --- src/gestures.c | 28 ++++++++++++++++++++-------- src/memory.h | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/gestures.c b/src/gestures.c index e032214..b04c679 100644 --- a/src/gestures.c +++ b/src/gestures.c @@ -21,11 +21,14 @@ #include "gestures.h" +/* timer for cursor stability on finger touch/release */ +static const int AFTER_FINGER_CHANGE_MS = 70; + static void extract_movement(struct Gestures *gs, struct MTouch* mt) { const struct FingerState *prev[DIM_FINGER]; const struct FingerState *f = mt->state.finger; - int same_fingers, i; + int same_fingers, i, x = 0, y = 0; if (mt->state.nfinger == 0) return; @@ -36,16 +39,25 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt) same_fingers = same_fingers && prev[i]; } - if (!same_fingers) - return; - for (i = 0; i < mt->state.nfinger; i++) { - gs->dx += f[i].hw.position_x - prev[i]->hw.position_x; - gs->dy += f[i].hw.position_y - prev[i]->hw.position_y; + x += f[i].hw.position_x; + y += f[i].hw.position_y; + } + x /= mt->state.nfinger; + y /= mt->state.nfinger; + + if (!same_fingers) { + mt->mem.move_time = mt->state.evtime + AFTER_FINGER_CHANGE_MS; + } else if (mt->state.evtime >= mt->mem.move_time) { + gs->dx = x - mt->mem.move_x; + gs->dy = y - mt->mem.move_y; + } else { + /* accumulate all movement during delay */ + return; } - gs->dx /= mt->state.nfinger; - gs->dy /= mt->state.nfinger; + mt->mem.move_x = x; + mt->mem.move_y = y; } static void extract_buttons(struct Gestures *gs, struct MTouch* mt) diff --git a/src/memory.h b/src/memory.h index a6c51ec..0ab4d04 100644 --- a/src/memory.h +++ b/src/memory.h @@ -26,6 +26,8 @@ struct Memory { unsigned btdata; + mstime_t move_time; + int move_x, move_y; }; void init_memory(struct Memory *mem); -- cgit v1.2.3