From 241c5ec03f649dedc617686cd3163f131c2b4ce9 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Thu, 26 Aug 2010 16:29:01 +0200 Subject: Introduce tapping from any finger configuration The current code only emits taps from zero fingers to N fingers. This patch introduces tapping from any prior finger configuration. A tap is defined as an increased number of fingers followed by a decrease within the tap timeout. A tap is reported as the maximum number of fingers present during the tap sequence. Signed-off-by: Henrik Rydberg --- src/gestures-tapping.c | 82 ++++++++++++++++++++------------------------------ src/grail-gestures.h | 2 +- 2 files changed, 34 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/gestures-tapping.c b/src/gestures-tapping.c index 371dbde..fe7b7fe 100644 --- a/src/gestures-tapping.c +++ b/src/gestures-tapping.c @@ -23,10 +23,6 @@ #include "grail-recognizer.h" #include -static const int TAP_BEGIN = 0; -static const int TAP_END = 1; -static const int TAP_CANCEL = 2; - static const int TAP_MIN_GAP_MS = 25; static const int fm_mask = 0x03; @@ -48,61 +44,49 @@ int gru_tapping(struct grail *ge, struct gesture_recognizer *gru = ge->gru; struct tapping_model *state = &gru->tapping; struct move_model *move = &gru->move; - if (move->ntouch) { - if (state->status == TAP_CANCEL) - return 0; - state->status = TAP_BEGIN; - if (!state->ntouch) - state->start = move->time; - if (move->ntouch >= state->ntouch) { - set_props(ge->gin, state, move, frame); - } - if (move->ntouch > state->ntouch) { - state->ntouch = move->ntouch; - if (state->active) { - gin_gid_discard(ge, state->gid); - state->active = 0; - } + if (move->ntouch > state->ntouch) { + if (state->active) { + gin_gid_discard(ge, state->gid); + state->active = 0; } - if (!state->active) { + state->start = move->time; + state->ntouch = move->ntouch; + set_props(ge->gin, state, move, frame); + if (state->ntouch <= 5) { int type = GRAIL_TYPE_TAP1 + state->ntouch - 1; state->gid = gin_gid_begin(ge, type, PRIO_TAP, frame); state->active = 1; } - } else if (state->status == TAP_BEGIN && state->ntouch) { - state->status = TAP_END; - } else { - state->status = TAP_BEGIN; - state->ntouch = 0; return 0; } - if (state->ntouch < 1 || state->ntouch > 5) - state->status = TAP_CANCEL; - if (move->time - state->start > move->fm[FM_X].bar_ms) - state->status = TAP_CANCEL; - if (state->status == TAP_END && - move->time - state->start < TAP_MIN_GAP_MS) - state->status = TAP_CANCEL; - if (move->active & fm_mask) - state->status = TAP_CANCEL; - if (state->status == TAP_CANCEL) { - if (state->active) { + if (!state->active) { + state->ntouch = move->ntouch; + return 0; + } + if (move->ntouch < state->ntouch) { + int x = state->prop[GRAIL_PROP_TAP_X]; + int y = state->prop[GRAIL_PROP_TAP_Y]; + int t = move->time - state->start; + if (t < TAP_MIN_GAP_MS) { gin_gid_discard(ge, state->gid); + state->ntouch = move->ntouch; state->active = 0; + return 0; } - state->ntouch = 0; - return 0; + state->prop[GRAIL_PROP_TAP_DT] = t; + gin_gid_event(ge, state->gid, x, y, state->ntouch, + state->prop, state->nprop, 1); + state->ntouch = move->ntouch; + state->active = 0; + return 1; } - if (state->status != TAP_END || - move->time - state->start < TAP_MIN_GAP_MS) + if (!move->ntouch) return 0; - state->prop[GRAIL_PROP_TAP_DT] = move->time - state->start; - gin_gid_event(ge, state->gid, - state->prop[GRAIL_PROP_TAP_X], - state->prop[GRAIL_PROP_TAP_Y], state->ntouch, - state->prop, state->nprop, 1); - state->status = TAP_BEGIN; - state->ntouch = 0; - state->active = 0; - return 1; + set_props(ge->gin, state, move, frame); + if ((move->active & fm_mask) || + move->time - state->start > move->fm[FM_X].bar_ms) { + gin_gid_discard(ge, state->gid); + state->active = 0; + } + return 0; } diff --git a/src/grail-gestures.h b/src/grail-gestures.h index e716757..5a242d9 100644 --- a/src/grail-gestures.h +++ b/src/grail-gestures.h @@ -98,7 +98,7 @@ int gru_winrotate(struct grail *ge, struct tapping_model { grail_time_t start; - int status, ntouch; + int ntouch; int active, gid; int nprop; grail_prop_t prop[DIM_GRAIL_PROP]; -- cgit v1.2.3