From 88dada465e0fad35b5a535a042e0a93046ffff7c Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Wed, 4 Aug 2010 22:06:54 +0200 Subject: Cleanup tapping and gesture code Improved tapping quality with this patch. Signed-off-by: Henrik Rydberg --- src/gestures-combo.c | 15 ++++------- src/gestures-pan.c | 15 ++++------- src/gestures-pinch.c | 15 ++++------- src/gestures-rotate.c | 15 ++++------- src/gestures-tapping.c | 67 ++++++++++++++++++++++++-------------------------- src/grail-gestures.c | 20 +++++++-------- src/grail-gestures.h | 6 ++++- src/grail-inserter.c | 5 ++-- src/grail-inserter.h | 3 ++- 9 files changed, 71 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/gestures-combo.c b/src/gestures-combo.c index 82e7b42..8b4ad8c 100644 --- a/src/gestures-combo.c +++ b/src/gestures-combo.c @@ -33,7 +33,7 @@ int gru_combo(struct grail *ge, struct combo_model *state = &gru->combo; struct move_model *move = &gru->move; grail_prop_t prop[DIM_GRAIL_PROP]; - if (!move->motion) { + if (!move->multi) { if (state->active) { gru_end(ge, state->gid, move); state->active = 0; @@ -44,16 +44,11 @@ int gru_combo(struct grail *ge, !move->r.tickle && !move->a.tickle) return 0; if (!state->active) { - switch(move->ntouch) { - case 2: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_COMBO2, frame); - break; - case 3: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_COMBO3, frame); - break; - default: + int type = move->ntouch == 2 ? GRAIL_TYPE_COMBO2 : + move->ntouch == 3 ? GRAIL_TYPE_COMBO3 : 0; + if (!type) return 0; - } + state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame); state->active = 1; } if (!move->x.active && !move->y.active && diff --git a/src/gestures-pan.c b/src/gestures-pan.c index 541c502..6c34e5d 100644 --- a/src/gestures-pan.c +++ b/src/gestures-pan.c @@ -33,7 +33,7 @@ int gru_pan(struct grail *ge, struct combo_model *state = &gru->pan; struct move_model *move = &gru->move; grail_prop_t prop[DIM_GRAIL_PROP]; - if (!move->motion) { + if (!move->multi) { if (state->active) { gru_end(ge, state->gid, move); state->active = 0; @@ -43,16 +43,11 @@ int gru_pan(struct grail *ge, if (!move->x.tickle && !move->y.tickle) return 0; if (!state->active) { - switch(move->ntouch) { - case 2: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_PAN, frame); - break; - case 3: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_SWIPE, frame); - break; - default: + int type = move->ntouch == 2 ? GRAIL_TYPE_PAN : + move->ntouch == 3 ? GRAIL_TYPE_SWIPE : 0; + if (!type) return 0; - } + state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame); state->active = 1; } if (!move->x.active && !move->y.active) diff --git a/src/gestures-pinch.c b/src/gestures-pinch.c index 48e72bd..6c5392d 100644 --- a/src/gestures-pinch.c +++ b/src/gestures-pinch.c @@ -33,7 +33,7 @@ int gru_pinch(struct grail *ge, struct combo_model *state = &gru->pinch; struct move_model *move = &gru->move; grail_prop_t prop[DIM_GRAIL_PROP]; - if (!move->motion) { + if (!move->multi) { if (state->active) { gru_end(ge, state->gid, move); state->active = 0; @@ -43,16 +43,11 @@ int gru_pinch(struct grail *ge, if (!move->r.tickle) return 0; if (!state->active) { - switch(move->ntouch) { - case 2: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_PINCH, frame); - break; - case 3: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_SCALE, frame); - break; - default: + int type = move->ntouch == 2 ? GRAIL_TYPE_PINCH : + move->ntouch == 3 ? GRAIL_TYPE_SCALE : 0; + if (!type) return 0; - } + state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame); state->active = 1; } if (!move->r.active) diff --git a/src/gestures-rotate.c b/src/gestures-rotate.c index 011e9a0..90f9bdf 100644 --- a/src/gestures-rotate.c +++ b/src/gestures-rotate.c @@ -33,7 +33,7 @@ int gru_rotate(struct grail *ge, struct combo_model *state = &gru->rotate; struct move_model *move = &gru->move; grail_prop_t prop[DIM_GRAIL_PROP]; - if (!move->motion) { + if (!move->multi) { if (state->active) { gru_end(ge, state->gid, move); state->active = 0; @@ -43,16 +43,11 @@ int gru_rotate(struct grail *ge, if (!move->a.tickle) return 0; if (!state->active) { - switch(move->ntouch) { - case 2: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_ROTATE, frame); - break; - case 3: - state->gid = gin_gid_begin(ge, GRAIL_TYPE_TURN, frame); - break; - default: + int type = move->ntouch == 2 ? GRAIL_TYPE_ROTATE : + move->ntouch == 3 ? GRAIL_TYPE_TURN : 0; + if (!type) return 0; - } + state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame); state->active = 1; } if (!move->a.active) diff --git a/src/gestures-tapping.c b/src/gestures-tapping.c index 453f77c..1c07b6c 100644 --- a/src/gestures-tapping.c +++ b/src/gestures-tapping.c @@ -25,13 +25,12 @@ #include "grail-recognizer.h" #include -static const int TAP_INIT = 0; -static const int TAP_BEGIN = 1; -static const int TAP_END = 2; -static const int TAP_CANCEL = 3; +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 TAP_MAX_GAP_MS = 400; +static const int TAP_MAX_GAP_MS = 300; int gru_tapping(struct grail *ge, const struct touch_frame *frame) @@ -40,56 +39,54 @@ int gru_tapping(struct grail *ge, struct tapping_model *state = &gru->tapping; struct move_model *move = &gru->move; grail_prop_t prop[DIM_GRAIL_PROP]; - if (state->status == TAP_CANCEL) { - if (move->ntouch) + if (move->ntouch) { + if (state->status == TAP_CANCEL) return 0; - else - state->status = TAP_INIT; - } - if (move->ntouch > state->ntouch) { - if (!state->ntouch) { + state->status = TAP_BEGIN; + if (!state->ntouch) state->start = frame->time; - state->status = TAP_BEGIN; + if (move->ntouch > state->ntouch) { + state->ntouch = move->ntouch; + if (state->active) { + gin_gid_discard(ge, state->gid); + state->active = 0; + } } - state->ntouch = move->ntouch; - } else if (move->ntouch < state->ntouch) { - if (!move->ntouch) - state->status = TAP_END; - } - if (state->status == TAP_INIT) + if (!state->active) { + 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 (frame->time - state->start > TAP_MAX_GAP_MS) { + if (state->ntouch < 1 || state->ntouch > 5) + state->status = TAP_CANCEL; + if (frame->time - state->start > TAP_MAX_GAP_MS) state->status = TAP_CANCEL; - } if (state->status == TAP_END && - frame->time - state->start < TAP_MIN_GAP_MS) { + frame->time - state->start < TAP_MIN_GAP_MS) state->status = TAP_CANCEL; - } if (state->status == TAP_CANCEL) { if (state->active) { - gru_end(ge, state->gid, move); + gin_gid_discard(ge, state->gid); state->active = 0; } state->ntouch = 0; return 0; } - if (frame->time - state->start < TAP_MIN_GAP_MS) - return 0; - if (!state->active) { - int type = GRAIL_TYPE_TAP1 + state->ntouch - 1; - state->gid = gin_gid_begin(ge, type, frame); - state->active = 1; - } - if (state->status != TAP_END) + if (state->status != TAP_END || + frame->time - state->start < TAP_MIN_GAP_MS) return 0; prop[0] = frame->time - state->start; gin_gid_event(ge, state->gid, move->x.val, move->y.val, state->ntouch, prop, 1, GRAIL_STATUS_END); - state->status = TAP_INIT; + state->status = TAP_BEGIN; state->ntouch = 0; state->active = 0; return 1; diff --git a/src/grail-gestures.c b/src/grail-gestures.c index 27f160b..5ab12a8 100644 --- a/src/grail-gestures.c +++ b/src/grail-gestures.c @@ -134,7 +134,7 @@ void gru_init_motion(struct grail *ge, const struct touch_dev_caps *caps) state->y.bar = BAR_MOVE * state->y.fuzz; state->r.bar = BAR_ZOOM * state->r.fuzz; state->a.bar = BAR_ROTATE * state->a.fuzz; - state->motion = 0; + state->multi = 0; } void gru_motion(struct grail *ge, @@ -142,17 +142,16 @@ void gru_motion(struct grail *ge, { struct gesture_recognizer *gru = ge->gru; struct move_model *state = &gru->move; - int na = 0, nt = frame->nactive; float x, y, r, a; compute_position(&x, &y, frame); - if (nt < 2 || frame->ncreate || frame->ndestroy) { + if (frame->nactive < 2 || frame->ncreate || frame->ndestroy) { r = compute_radius(x, y, frame); a = 0; move_reset(&state->x, x); move_reset(&state->y, y); move_reset(&state->r, r); move_reset(&state->a, a); - state->motion = 0; + state->multi = 0; } else { x = move_filter(&state->x, x); y = move_filter(&state->y, y); @@ -160,14 +159,13 @@ void gru_motion(struct grail *ge, r = move_filter(&state->r, r); a = state->a.val + compute_rotation(x, y, r, &gru->frame, frame); //a = move_filter(&state->a, a); - na += move_update(&state->x, x); - na += move_update(&state->y, y); - na += move_update(&state->r, r); - na += move_update(&state->a, a); - state->motion = 1; + move_update(&state->x, x); + move_update(&state->y, y); + move_update(&state->r, r); + move_update(&state->a, a); + state->multi = 1; } - state->nactive = na; - state->ntouch = nt; + state->ntouch = frame->nactive; state->time = frame->time; } diff --git a/src/grail-gestures.h b/src/grail-gestures.h index b8f46d4..9da2693 100644 --- a/src/grail-gestures.h +++ b/src/grail-gestures.h @@ -27,6 +27,10 @@ #include "grail-inserter.h" +#define PRIO_POINTER 1 +#define PRIO_GESTURE 2 +#define PRIO_TAP 3 + struct filter_model { float delta, val, orig, fuzz, bar; int tickle, active; @@ -34,7 +38,7 @@ struct filter_model { struct move_model { struct filter_model x, y, r, a; - int motion, nactive, ntouch; + int multi, ntouch; float dx, dy, dr, da; grail_time_t time; }; diff --git a/src/grail-inserter.c b/src/grail-inserter.c index 4bf78d3..724052c 100644 --- a/src/grail-inserter.c +++ b/src/grail-inserter.c @@ -216,9 +216,10 @@ int gin_gid_begin_select(struct grail *ge, int type, int priority, return s->id; } -int gin_gid_begin(struct grail *ge, int type, const struct touch_frame *frame) +int gin_gid_begin(struct grail *ge, int type, int priority, + const struct touch_frame *frame) { - return gin_gid_begin_select(ge, type, 1, + return gin_gid_begin_select(ge, type, priority, frame->touches, sizeof(frame->touches)); } diff --git a/src/grail-inserter.h b/src/grail-inserter.h index c76c0e0..3ffacec 100644 --- a/src/grail-inserter.h +++ b/src/grail-inserter.h @@ -57,7 +57,8 @@ void gin_frame_end(struct grail *ge, grail_mask_t *filtered, int max_filtered, int gin_gid_begin_select(struct grail *ge, int type, int priority, const grail_mask_t *span, int nspan); -int gin_gid_begin(struct grail *ge, int type, const struct touch_frame *frame); +int gin_gid_begin(struct grail *ge, int type, int priority, + const struct touch_frame *frame); void gin_gid_discard(struct grail *ge, int gid); void gin_gid_event(struct grail *ge, int gid, -- cgit v1.2.3