summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gestures-combo.c15
-rw-r--r--src/gestures-pan.c15
-rw-r--r--src/gestures-pinch.c15
-rw-r--r--src/gestures-rotate.c15
-rw-r--r--src/gestures-tapping.c67
-rw-r--r--src/grail-gestures.c20
-rw-r--r--src/grail-gestures.h6
-rw-r--r--src/grail-inserter.c5
-rw-r--r--src/grail-inserter.h3
9 files changed, 71 insertions, 90 deletions
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,
33 struct combo_model *state = &gru->combo; 33 struct combo_model *state = &gru->combo;
34 struct move_model *move = &gru->move; 34 struct move_model *move = &gru->move;
35 grail_prop_t prop[DIM_GRAIL_PROP]; 35 grail_prop_t prop[DIM_GRAIL_PROP];
36 if (!move->motion) { 36 if (!move->multi) {
37 if (state->active) { 37 if (state->active) {
38 gru_end(ge, state->gid, move); 38 gru_end(ge, state->gid, move);
39 state->active = 0; 39 state->active = 0;
@@ -44,16 +44,11 @@ int gru_combo(struct grail *ge,
44 !move->r.tickle && !move->a.tickle) 44 !move->r.tickle && !move->a.tickle)
45 return 0; 45 return 0;
46 if (!state->active) { 46 if (!state->active) {
47 switch(move->ntouch) { 47 int type = move->ntouch == 2 ? GRAIL_TYPE_COMBO2 :
48 case 2: 48 move->ntouch == 3 ? GRAIL_TYPE_COMBO3 : 0;
49 state->gid = gin_gid_begin(ge, GRAIL_TYPE_COMBO2, frame); 49 if (!type)
50 break;
51 case 3:
52 state->gid = gin_gid_begin(ge, GRAIL_TYPE_COMBO3, frame);
53 break;
54 default:
55 return 0; 50 return 0;
56 } 51 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
57 state->active = 1; 52 state->active = 1;
58 } 53 }
59 if (!move->x.active && !move->y.active && 54 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,
33 struct combo_model *state = &gru->pan; 33 struct combo_model *state = &gru->pan;
34 struct move_model *move = &gru->move; 34 struct move_model *move = &gru->move;
35 grail_prop_t prop[DIM_GRAIL_PROP]; 35 grail_prop_t prop[DIM_GRAIL_PROP];
36 if (!move->motion) { 36 if (!move->multi) {
37 if (state->active) { 37 if (state->active) {
38 gru_end(ge, state->gid, move); 38 gru_end(ge, state->gid, move);
39 state->active = 0; 39 state->active = 0;
@@ -43,16 +43,11 @@ int gru_pan(struct grail *ge,
43 if (!move->x.tickle && !move->y.tickle) 43 if (!move->x.tickle && !move->y.tickle)
44 return 0; 44 return 0;
45 if (!state->active) { 45 if (!state->active) {
46 switch(move->ntouch) { 46 int type = move->ntouch == 2 ? GRAIL_TYPE_PAN :
47 case 2: 47 move->ntouch == 3 ? GRAIL_TYPE_SWIPE : 0;
48 state->gid = gin_gid_begin(ge, GRAIL_TYPE_PAN, frame); 48 if (!type)
49 break;
50 case 3:
51 state->gid = gin_gid_begin(ge, GRAIL_TYPE_SWIPE, frame);
52 break;
53 default:
54 return 0; 49 return 0;
55 } 50 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
56 state->active = 1; 51 state->active = 1;
57 } 52 }
58 if (!move->x.active && !move->y.active) 53 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,
33 struct combo_model *state = &gru->pinch; 33 struct combo_model *state = &gru->pinch;
34 struct move_model *move = &gru->move; 34 struct move_model *move = &gru->move;
35 grail_prop_t prop[DIM_GRAIL_PROP]; 35 grail_prop_t prop[DIM_GRAIL_PROP];
36 if (!move->motion) { 36 if (!move->multi) {
37 if (state->active) { 37 if (state->active) {
38 gru_end(ge, state->gid, move); 38 gru_end(ge, state->gid, move);
39 state->active = 0; 39 state->active = 0;
@@ -43,16 +43,11 @@ int gru_pinch(struct grail *ge,
43 if (!move->r.tickle) 43 if (!move->r.tickle)
44 return 0; 44 return 0;
45 if (!state->active) { 45 if (!state->active) {
46 switch(move->ntouch) { 46 int type = move->ntouch == 2 ? GRAIL_TYPE_PINCH :
47 case 2: 47 move->ntouch == 3 ? GRAIL_TYPE_SCALE : 0;
48 state->gid = gin_gid_begin(ge, GRAIL_TYPE_PINCH, frame); 48 if (!type)
49 break;
50 case 3:
51 state->gid = gin_gid_begin(ge, GRAIL_TYPE_SCALE, frame);
52 break;
53 default:
54 return 0; 49 return 0;
55 } 50 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
56 state->active = 1; 51 state->active = 1;
57 } 52 }
58 if (!move->r.active) 53 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,
33 struct combo_model *state = &gru->rotate; 33 struct combo_model *state = &gru->rotate;
34 struct move_model *move = &gru->move; 34 struct move_model *move = &gru->move;
35 grail_prop_t prop[DIM_GRAIL_PROP]; 35 grail_prop_t prop[DIM_GRAIL_PROP];
36 if (!move->motion) { 36 if (!move->multi) {
37 if (state->active) { 37 if (state->active) {
38 gru_end(ge, state->gid, move); 38 gru_end(ge, state->gid, move);
39 state->active = 0; 39 state->active = 0;
@@ -43,16 +43,11 @@ int gru_rotate(struct grail *ge,
43 if (!move->a.tickle) 43 if (!move->a.tickle)
44 return 0; 44 return 0;
45 if (!state->active) { 45 if (!state->active) {
46 switch(move->ntouch) { 46 int type = move->ntouch == 2 ? GRAIL_TYPE_ROTATE :
47 case 2: 47 move->ntouch == 3 ? GRAIL_TYPE_TURN : 0;
48 state->gid = gin_gid_begin(ge, GRAIL_TYPE_ROTATE, frame); 48 if (!type)
49 break;
50 case 3:
51 state->gid = gin_gid_begin(ge, GRAIL_TYPE_TURN, frame);
52 break;
53 default:
54 return 0; 49 return 0;
55 } 50 state->gid = gin_gid_begin(ge, type, PRIO_GESTURE, frame);
56 state->active = 1; 51 state->active = 1;
57 } 52 }
58 if (!move->a.active) 53 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 @@
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;
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)
134 state->y.bar = BAR_MOVE * state->y.fuzz; 134 state->y.bar = BAR_MOVE * state->y.fuzz;
135 state->r.bar = BAR_ZOOM * state->r.fuzz; 135 state->r.bar = BAR_ZOOM * state->r.fuzz;
136 state->a.bar = BAR_ROTATE * state->a.fuzz; 136 state->a.bar = BAR_ROTATE * state->a.fuzz;
137 state->motion = 0; 137 state->multi = 0;
138} 138}
139 139
140void gru_motion(struct grail *ge, 140void gru_motion(struct grail *ge,
@@ -142,17 +142,16 @@ void gru_motion(struct grail *ge,
142{ 142{
143 struct gesture_recognizer *gru = ge->gru; 143 struct gesture_recognizer *gru = ge->gru;
144 struct move_model *state = &gru->move; 144 struct move_model *state = &gru->move;
145 int na = 0, nt = frame->nactive;
146 float x, y, r, a; 145 float x, y, r, a;
147 compute_position(&x, &y, frame); 146 compute_position(&x, &y, frame);
148 if (nt < 2 || frame->ncreate || frame->ndestroy) { 147 if (frame->nactive < 2 || frame->ncreate || frame->ndestroy) {
149 r = compute_radius(x, y, frame); 148 r = compute_radius(x, y, frame);
150 a = 0; 149 a = 0;
151 move_reset(&state->x, x); 150 move_reset(&state->x, x);
152 move_reset(&state->y, y); 151 move_reset(&state->y, y);
153 move_reset(&state->r, r); 152 move_reset(&state->r, r);
154 move_reset(&state->a, a); 153 move_reset(&state->a, a);
155 state->motion = 0; 154 state->multi = 0;
156 } else { 155 } else {
157 x = move_filter(&state->x, x); 156 x = move_filter(&state->x, x);
158 y = move_filter(&state->y, y); 157 y = move_filter(&state->y, y);
@@ -160,14 +159,13 @@ void gru_motion(struct grail *ge,
160 r = move_filter(&state->r, r); 159 r = move_filter(&state->r, r);
161 a = state->a.val + compute_rotation(x, y, r, &gru->frame, frame); 160 a = state->a.val + compute_rotation(x, y, r, &gru->frame, frame);
162 //a = move_filter(&state->a, a); 161 //a = move_filter(&state->a, a);
163 na += move_update(&state->x, x); 162 move_update(&state->x, x);
164 na += move_update(&state->y, y); 163 move_update(&state->y, y);
165 na += move_update(&state->r, r); 164 move_update(&state->r, r);
166 na += move_update(&state->a, a); 165 move_update(&state->a, a);
167 state->motion = 1; 166 state->multi = 1;
168 } 167 }
169 state->nactive = na; 168 state->ntouch = frame->nactive;
170 state->ntouch = nt;
171 state->time = frame->time; 169 state->time = frame->time;
172} 170}
173 171
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 @@
27 27
28#include "grail-inserter.h" 28#include "grail-inserter.h"
29 29
30#define PRIO_POINTER 1
31#define PRIO_GESTURE 2
32#define PRIO_TAP 3
33
30struct filter_model { 34struct filter_model {
31 float delta, val, orig, fuzz, bar; 35 float delta, val, orig, fuzz, bar;
32 int tickle, active; 36 int tickle, active;
@@ -34,7 +38,7 @@ struct filter_model {
34 38
35struct move_model { 39struct move_model {
36 struct filter_model x, y, r, a; 40 struct filter_model x, y, r, a;
37 int motion, nactive, ntouch; 41 int multi, ntouch;
38 float dx, dy, dr, da; 42 float dx, dy, dr, da;
39 grail_time_t time; 43 grail_time_t time;
40}; 44};
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,
216 return s->id; 216 return s->id;
217} 217}
218 218
219int gin_gid_begin(struct grail *ge, int type, const struct touch_frame *frame) 219int gin_gid_begin(struct grail *ge, int type, int priority,
220 const struct touch_frame *frame)
220{ 221{
221 return gin_gid_begin_select(ge, type, 1, 222 return gin_gid_begin_select(ge, type, priority,
222 frame->touches, sizeof(frame->touches)); 223 frame->touches, sizeof(frame->touches));
223} 224}
224 225
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,
57 57
58int gin_gid_begin_select(struct grail *ge, int type, int priority, 58int gin_gid_begin_select(struct grail *ge, int type, int priority,
59 const grail_mask_t *span, int nspan); 59 const grail_mask_t *span, int nspan);
60int gin_gid_begin(struct grail *ge, int type, const struct touch_frame *frame); 60int gin_gid_begin(struct grail *ge, int type, int priority,
61 const struct touch_frame *frame);
61void gin_gid_discard(struct grail *ge, int gid); 62void gin_gid_discard(struct grail *ge, int gid);
62 63
63void gin_gid_event(struct grail *ge, int gid, 64void gin_gid_event(struct grail *ge, int gid,