summaryrefslogtreecommitdiff
path: root/src/gestures-tapping.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-08-04 22:06:54 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commit88dada465e0fad35b5a535a042e0a93046ffff7c (patch)
treec191b61c7b55fb5cfb08b8baae6bc11a25062ca6 /src/gestures-tapping.c
parent697b5b5c7d2b1c46387061fcbed24cbee51d98ce (diff)
Cleanup tapping and gesture code
Improved tapping quality with this patch. Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/gestures-tapping.c')
-rw-r--r--src/gestures-tapping.c67
1 files changed, 32 insertions, 35 deletions
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 @@
25#include "grail-recognizer.h" 25#include "grail-recognizer.h"
26#include <math.h> 26#include <math.h>
27 27
28static const int TAP_INIT = 0; 28static const int TAP_BEGIN = 0;
29static const int TAP_BEGIN = 1; 29static const int TAP_END = 1;
30static const int TAP_END = 2; 30static const int TAP_CANCEL = 2;
31static const int TAP_CANCEL = 3;
32 31
33static const int TAP_MIN_GAP_MS = 25; 32static const int TAP_MIN_GAP_MS = 25;
34static const int TAP_MAX_GAP_MS = 400; 33static const int TAP_MAX_GAP_MS = 300;
35 34
36int gru_tapping(struct grail *ge, 35int gru_tapping(struct grail *ge,
37 const struct touch_frame *frame) 36 const struct touch_frame *frame)
@@ -40,56 +39,54 @@ int gru_tapping(struct grail *ge,
40 struct tapping_model *state = &gru->tapping; 39 struct tapping_model *state = &gru->tapping;
41 struct move_model *move = &gru->move; 40 struct move_model *move = &gru->move;
42 grail_prop_t prop[DIM_GRAIL_PROP]; 41 grail_prop_t prop[DIM_GRAIL_PROP];
43 if (state->status == TAP_CANCEL) { 42 if (move->ntouch) {
44 if (move->ntouch) 43 if (state->status == TAP_CANCEL)
45 return 0; 44 return 0;
46 else 45 state->status = TAP_BEGIN;
47 state->status = TAP_INIT; 46 if (!state->ntouch)
48 }
49 if (move->ntouch > state->ntouch) {
50 if (!state->ntouch) {
51 state->start = frame->time; 47 state->start = frame->time;
52 state->status = TAP_BEGIN; 48 if (move->ntouch > state->ntouch) {
49 state->ntouch = move->ntouch;
50 if (state->active) {
51 gin_gid_discard(ge, state->gid);
52 state->active = 0;
53 }
53 } 54 }
54 state->ntouch = move->ntouch; 55 if (!state->active) {
55 } else if (move->ntouch < state->ntouch) { 56 int type = GRAIL_TYPE_TAP1 + state->ntouch - 1;
56 if (!move->ntouch) 57 state->gid = gin_gid_begin(ge, type, PRIO_TAP, frame);
57 state->status = TAP_END; 58 state->active = 1;
58 } 59 }
59 if (state->status == TAP_INIT) 60 } else if (state->status == TAP_BEGIN && state->ntouch) {
61 state->status = TAP_END;
62 } else {
63 state->status = TAP_BEGIN;
64 state->ntouch = 0;
60 return 0; 65 return 0;
61 if (state->ntouch < 1 || state->ntouch > 5) {
62 state->status = TAP_CANCEL;
63 } 66 }
64 if (frame->time - state->start > TAP_MAX_GAP_MS) { 67 if (state->ntouch < 1 || state->ntouch > 5)
68 state->status = TAP_CANCEL;
69 if (frame->time - state->start > TAP_MAX_GAP_MS)
65 state->status = TAP_CANCEL; 70 state->status = TAP_CANCEL;
66 }
67 if (state->status == TAP_END && 71 if (state->status == TAP_END &&
68 frame->time - state->start < TAP_MIN_GAP_MS) { 72 frame->time - state->start < TAP_MIN_GAP_MS)
69 state->status = TAP_CANCEL; 73 state->status = TAP_CANCEL;
70 }
71 if (state->status == TAP_CANCEL) { 74 if (state->status == TAP_CANCEL) {
72 if (state->active) { 75 if (state->active) {
73 gru_end(ge, state->gid, move); 76 gin_gid_discard(ge, state->gid);
74 state->active = 0; 77 state->active = 0;
75 } 78 }
76 state->ntouch = 0; 79 state->ntouch = 0;
77 return 0; 80 return 0;
78 } 81 }
79 if (frame->time - state->start < TAP_MIN_GAP_MS) 82 if (state->status != TAP_END ||
80 return 0; 83 frame->time - state->start < TAP_MIN_GAP_MS)
81 if (!state->active) {
82 int type = GRAIL_TYPE_TAP1 + state->ntouch - 1;
83 state->gid = gin_gid_begin(ge, type, frame);
84 state->active = 1;
85 }
86 if (state->status != TAP_END)
87 return 0; 84 return 0;
88 prop[0] = frame->time - state->start; 85 prop[0] = frame->time - state->start;
89 gin_gid_event(ge, state->gid, 86 gin_gid_event(ge, state->gid,
90 move->x.val, move->y.val, state->ntouch, 87 move->x.val, move->y.val, state->ntouch,
91 prop, 1, GRAIL_STATUS_END); 88 prop, 1, GRAIL_STATUS_END);
92 state->status = TAP_INIT; 89 state->status = TAP_BEGIN;
93 state->ntouch = 0; 90 state->ntouch = 0;
94 state->active = 0; 91 state->active = 0;
95 return 1; 92 return 1;