summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/grail-types.h28
-rw-r--r--src/Makefile.am1
-rw-r--r--src/gestures-touch.c94
-rw-r--r--src/grail-gestures.h4
-rw-r--r--src/grail-inserter.c22
-rw-r--r--src/grail-inserter.h1
-rw-r--r--src/grail-recognizer.c2
-rw-r--r--src/grail-recognizer.h2
8 files changed, 146 insertions, 8 deletions
diff --git a/include/grail-types.h b/include/grail-types.h
index f274963..840ece3 100644
--- a/include/grail-types.h
+++ b/include/grail-types.h
@@ -59,11 +59,20 @@
59 59
60#define GRAIL_TYPE_SYSFLAG1 26 /* reserved system flag */ 60#define GRAIL_TYPE_SYSFLAG1 26 /* reserved system flag */
61 61
62#define GRAIL_TYPE_TOUCH1 32 /* one-finger touch */
63#define GRAIL_TYPE_TOUCH2 33 /* two-finger touch */
64#define GRAIL_TYPE_TOUCH3 34 /* three-finger touch */
65#define GRAIL_TYPE_TOUCH4 35 /* four-finger touch */
66#define GRAIL_TYPE_TOUCH5 36 /* five-finger touch */
67#define GRAIL_TYPE_ETOUCH 37 /* three-finger environment touch */
68#define GRAIL_TYPE_MTOUCH 38 /* four-finger meta touch */
69
62#define GRAIL_MAIN_DRAG 0 70#define GRAIL_MAIN_DRAG 0
63#define GRAIL_MAIN_PINCH 1 71#define GRAIL_MAIN_PINCH 1
64#define GRAIL_MAIN_ROTATE 2 72#define GRAIL_MAIN_ROTATE 2
65#define GRAIL_MAIN_TAP 3 73#define GRAIL_MAIN_TAP 3
66#define GRAIL_MAIN_SYSFLAG 4 74#define GRAIL_MAIN_SYSFLAG 4
75#define GRAIL_MAIN_TOUCH 5
67 76
68#define GRAIL_PROP_DRAG_DX 0 /* horizontal position delta */ 77#define GRAIL_PROP_DRAG_DX 0 /* horizontal position delta */
69#define GRAIL_PROP_DRAG_DY 1 /* vertical position delta */ 78#define GRAIL_PROP_DRAG_DY 1 /* vertical position delta */
@@ -160,5 +169,24 @@
160#define GRAIL_PROP_TAP_X_T4 20 169#define GRAIL_PROP_TAP_X_T4 20
161#define GRAIL_PROP_TAP_Y_T4 21 170#define GRAIL_PROP_TAP_Y_T4 21
162 171
172#define GRAIL_PROP_TOUCH_X1 0 /* bounding box x1 */
173#define GRAIL_PROP_TOUCH_Y1 1 /* bounding box y1 */
174#define GRAIL_PROP_TOUCH_X2 2 /* bounding box x2 */
175#define GRAIL_PROP_TOUCH_Y2 3 /* bounding box y2 */
176#define GRAIL_PROP_TOUCH_ID_T0 4 /* first touch id */
177#define GRAIL_PROP_TOUCH_X_T0 5 /* first touch horizontal position */
178#define GRAIL_PROP_TOUCH_Y_T0 6 /* first touch vertical position */
179#define GRAIL_PROP_TOUCH_ID_T1 7
180#define GRAIL_PROP_TOUCH_X_T1 8
181#define GRAIL_PROP_TOUCH_Y_T1 9
182#define GRAIL_PROP_TOUCH_ID_T2 10
183#define GRAIL_PROP_TOUCH_X_T2 11
184#define GRAIL_PROP_TOUCH_Y_T2 12
185#define GRAIL_PROP_TOUCH_ID_T3 13
186#define GRAIL_PROP_TOUCH_X_T3 14
187#define GRAIL_PROP_TOUCH_Y_T3 15
188#define GRAIL_PROP_TOUCH_ID_T4 16
189#define GRAIL_PROP_TOUCH_X_T4 17
190#define GRAIL_PROP_TOUCH_Y_T4 18
163 191
164#endif 192#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 855d428..da1a46e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,7 @@ libutouch_grail_la_SOURCES = \
17 grail-inserter.h \ 17 grail-inserter.h \
18 grail-gestures.c \ 18 grail-gestures.c \
19 grail-gestures.h \ 19 grail-gestures.h \
20 gestures-touch.c \
20 gestures-drag.c \ 21 gestures-drag.c \
21 gestures-pinch.c \ 22 gestures-pinch.c \
22 gestures-rotate.c \ 23 gestures-rotate.c \
diff --git a/src/gestures-touch.c b/src/gestures-touch.c
new file mode 100644
index 0000000..b6a2706
--- /dev/null
+++ b/src/gestures-touch.c
@@ -0,0 +1,94 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ****************************************************************************/
22
23#include "grail-recognizer.h"
24#include <math.h>
25#include <stdio.h>
26
27static const int getype[DIM_TOUCH + 1] = {
28 -1,
29 GRAIL_TYPE_TOUCH1,
30 GRAIL_TYPE_TOUCH2,
31 GRAIL_TYPE_TOUCH3,
32 GRAIL_TYPE_TOUCH4,
33 GRAIL_TYPE_TOUCH5,
34};
35
36int gru_touch(struct grail *ge,
37 const struct utouch_frame *frame)
38{
39 struct gesture_recognizer *gru = ge->gru;
40 struct combo_model *state = &gru->touch;
41 struct move_model *move = &gru->move;
42 if (frame->slot_revision != frame->prev->slot_revision) {
43 if (state->active) {
44 gru_end(ge, state->gid, move,
45 state->prop, state->nprop);
46 state->active = 0;
47 }
48 }
49 if (!state->active) {
50 int type = getype[move->ntouch];
51 if (type <= 0)
52 return 0;
53 state->gid = gin_gid_begin(ge, type, -PRIO_GESTURE, frame);
54 state->active = 1;
55 }
56 state->nprop = gin_add_contact_props(ge->gin, state->prop, frame);
57 gru_event(ge, state->gid, move, state->prop, state->nprop);
58 return 1;
59}
60
61int gru_wintouch(struct grail *ge,
62 const struct utouch_frame *frame)
63{
64 struct gesture_recognizer *gru = ge->gru;
65 struct combo_model *state = &gru->wintouch;
66 struct move_model *move = &gru->move;
67 if (frame->slot_revision != frame->prev->slot_revision) {
68 if (state->active && out_of_bounds(state, move)) {
69 gru_end(ge, state->gid, move,
70 state->prop, state->nprop);
71 state->active = 0;
72 }
73 }
74 if (!state->active) {
75 if (move->ntouch == 4) {
76 state->gid = gin_gid_begin(ge, GRAIL_TYPE_MTOUCH,
77 -PRIO_META, frame);
78 state->mintouch = 1;
79 state->maxtouch = 4;
80 state->active = 1;
81 } else if (move->ntouch == 3) {
82 state->gid = gin_gid_begin(ge, GRAIL_TYPE_ETOUCH,
83 -PRIO_ENV, frame);
84 state->mintouch = 1;
85 state->maxtouch = 3;
86 state->active = 1;
87 } else {
88 return 0;
89 }
90 }
91 state->nprop = gin_add_contact_props(ge->gin, state->prop, frame);
92 gru_event(ge, state->gid, move, state->prop, state->nprop);
93 return 1;
94}
diff --git a/src/grail-gestures.h b/src/grail-gestures.h
index d92a24b..a24bbbd 100644
--- a/src/grail-gestures.h
+++ b/src/grail-gestures.h
@@ -77,6 +77,8 @@ struct combo_model {
77 grail_prop_t prop[DIM_GRAIL_PROP]; 77 grail_prop_t prop[DIM_GRAIL_PROP];
78}; 78};
79 79
80int gru_touch(struct grail *ge,
81 const struct utouch_frame *frame);
80int gru_drag(struct grail *ge, 82int gru_drag(struct grail *ge,
81 const struct utouch_frame *frame); 83 const struct utouch_frame *frame);
82int gru_pinch(struct grail *ge, 84int gru_pinch(struct grail *ge,
@@ -90,6 +92,8 @@ static inline int out_of_bounds(const struct combo_model *s,
90 return m->ntouch < s->mintouch || m->ntouch > s->maxtouch; 92 return m->ntouch < s->mintouch || m->ntouch > s->maxtouch;
91} 93}
92 94
95int gru_wintouch(struct grail *ge,
96 const struct utouch_frame *frame);
93int gru_windrag(struct grail *ge, 97int gru_windrag(struct grail *ge,
94 const struct utouch_frame *frame); 98 const struct utouch_frame *frame);
95int gru_winpinch(struct grail *ge, 99int gru_winpinch(struct grail *ge,
diff --git a/src/grail-inserter.c b/src/grail-inserter.c
index ff4f0b6..1ee8e5a 100644
--- a/src/grail-inserter.c
+++ b/src/grail-inserter.c
@@ -119,7 +119,7 @@ void gin_frame_begin(struct grail *ge, const struct utouch_frame *frame)
119void gin_frame_end(struct grail *ge, const struct utouch_frame *frame) 119void gin_frame_end(struct grail *ge, const struct utouch_frame *frame)
120{ 120{
121 struct gesture_inserter *gin = ge->gin; 121 struct gesture_inserter *gin = ge->gin;
122 int i, hold = 0, discard = 0; 122 int i, hold[2] = { 0, 0 }, discard[2] = { 0, 0 };
123 123
124 setup_new_gestures(ge, frame); 124 setup_new_gestures(ge, frame);
125 125
@@ -127,17 +127,17 @@ void gin_frame_end(struct grail *ge, const struct utouch_frame *frame)
127 struct slot_state *s = &gin->state[i]; 127 struct slot_state *s = &gin->state[i];
128 if (!s->nclient) 128 if (!s->nclient)
129 continue; 129 continue;
130 if (s->priority > hold) 130 if (s->priority > hold[s->slice])
131 hold = s->priority; 131 hold[s->slice] = s->priority;
132 if (s->status != GRAIL_STATUS_UPDATE) 132 if (s->status != GRAIL_STATUS_UPDATE)
133 continue; 133 continue;
134 if (s->priority > discard) 134 if (s->priority > discard[s->slice])
135 discard = s->priority; 135 discard[s->slice] = s->priority;
136 } 136 }
137 137
138 grail_mask_foreach(i, gin->used, sizeof(gin->used)) { 138 grail_mask_foreach(i, gin->used, sizeof(gin->used)) {
139 struct slot_state *s = &gin->state[i]; 139 struct slot_state *s = &gin->state[i];
140 if (!s->nclient || s->priority < discard) 140 if (!s->nclient || s->priority < discard[s->slice])
141 gin_gid_discard(ge, s->id); 141 gin_gid_discard(ge, s->id);
142 } 142 }
143 143
@@ -145,7 +145,7 @@ void gin_frame_end(struct grail *ge, const struct utouch_frame *frame)
145 struct slot_state *s = &gin->state[i]; 145 struct slot_state *s = &gin->state[i];
146 struct gesture_event ev; 146 struct gesture_event ev;
147 grail_mask_set(gin->types, s->type); 147 grail_mask_set(gin->types, s->type);
148 if (s->priority < hold) 148 if (s->priority < hold[s->slice])
149 continue; 149 continue;
150 while (!gebuf_empty(&s->buf)) { 150 while (!gebuf_empty(&s->buf)) {
151 gebuf_get(&s->buf, &ev); 151 gebuf_get(&s->buf, &ev);
@@ -171,7 +171,13 @@ int gin_gid_begin(struct grail *ge, int type, int priority,
171 return -1; 171 return -1;
172 s = &gin->state[i]; 172 s = &gin->state[i];
173 s->type = type; 173 s->type = type;
174 s->priority = priority; 174 if (priority < 0) {
175 s->priority = -priority;
176 s->slice = 1;
177 } else {
178 s->priority = priority;
179 s->slice = 0;
180 }
175 s->id = gin->gestureid++ & MAX_GESTURE_ID; 181 s->id = gin->gestureid++ & MAX_GESTURE_ID;
176 s->status = GRAIL_STATUS_BEGIN; 182 s->status = GRAIL_STATUS_BEGIN;
177 s->nclient = 0; 183 s->nclient = 0;
diff --git a/src/grail-inserter.h b/src/grail-inserter.h
index fb944dd..12d0dc9 100644
--- a/src/grail-inserter.h
+++ b/src/grail-inserter.h
@@ -37,6 +37,7 @@
37struct slot_state { 37struct slot_state {
38 int type; 38 int type;
39 int priority; 39 int priority;
40 int slice;
40 int id; 41 int id;
41 int status; 42 int status;
42 int nclient; 43 int nclient;
diff --git a/src/grail-recognizer.c b/src/grail-recognizer.c
index fb0ae85..5bc27ff 100644
--- a/src/grail-recognizer.c
+++ b/src/grail-recognizer.c
@@ -47,9 +47,11 @@ void gru_recognize(struct grail *ge, const struct utouch_frame *frame)
47 if (!ge->gin || !ge->gru) 47 if (!ge->gin || !ge->gru)
48 return; 48 return;
49 gru_motion(ge, frame); 49 gru_motion(ge, frame);
50 gru_touch(ge, frame);
50 gru_drag(ge, frame); 51 gru_drag(ge, frame);
51 gru_pinch(ge, frame); 52 gru_pinch(ge, frame);
52 gru_rotate(ge, frame); 53 gru_rotate(ge, frame);
54 gru_wintouch(ge, frame);
53 gru_windrag(ge, frame); 55 gru_windrag(ge, frame);
54 gru_winpinch(ge, frame); 56 gru_winpinch(ge, frame);
55 gru_winrotate(ge, frame); 57 gru_winrotate(ge, frame);
diff --git a/src/grail-recognizer.h b/src/grail-recognizer.h
index 56e5b8d..3844511 100644
--- a/src/grail-recognizer.h
+++ b/src/grail-recognizer.h
@@ -27,9 +27,11 @@
27 27
28struct gesture_recognizer { 28struct gesture_recognizer {
29 struct move_model move; 29 struct move_model move;
30 struct combo_model touch;
30 struct combo_model drag; 31 struct combo_model drag;
31 struct combo_model pinch; 32 struct combo_model pinch;
32 struct combo_model rotate; 33 struct combo_model rotate;
34 struct combo_model wintouch;
33 struct combo_model windrag; 35 struct combo_model windrag;
34 struct combo_model winpinch; 36 struct combo_model winpinch;
35 struct combo_model winrotate; 37 struct combo_model winrotate;