diff options
| author | Henrik Rydberg <rydberg@bitmath.org> | 2010-08-04 16:47:43 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-05 22:48:38 +0200 |
| commit | 697b5b5c7d2b1c46387061fcbed24cbee51d98ce (patch) | |
| tree | b8e8dbf02453f7c7dc31c691822a088123d21cd8 /src/grail-inserter.c | |
| parent | 642d7ee26f347152a106d48ddad37a8059d36fb1 (diff) | |
Introduce tapping
Simplify some common parts of the recognizer code and add tapping
to the gesture suite.
Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/grail-inserter.c')
| -rw-r--r-- | src/grail-inserter.c | 107 |
1 files changed, 75 insertions, 32 deletions
diff --git a/src/grail-inserter.c b/src/grail-inserter.c index 3927875..4bf78d3 100644 --- a/src/grail-inserter.c +++ b/src/grail-inserter.c | |||
| @@ -29,6 +29,24 @@ | |||
| 29 | 29 | ||
| 30 | static const int MAX_GESTURE_ID = 0xfff; | 30 | static const int MAX_GESTURE_ID = 0xfff; |
| 31 | 31 | ||
| 32 | struct gesture_inserter { | ||
| 33 | struct slot_state state[DIM_INSTANCE]; | ||
| 34 | grail_mask_t unused[DIM_INSTANCE_BYTES]; | ||
| 35 | grail_mask_t fresh[DIM_INSTANCE_BYTES]; | ||
| 36 | grail_mask_t used[DIM_INSTANCE_BYTES]; | ||
| 37 | grail_time_t time; | ||
| 38 | int gestureid; | ||
| 39 | }; | ||
| 40 | |||
| 41 | static int find_gslot(const struct gesture_inserter *gin, int gid) | ||
| 42 | { | ||
| 43 | int i; | ||
| 44 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) | ||
| 45 | if (gin->state[i].id == gid) | ||
| 46 | return i; | ||
| 47 | return -1; | ||
| 48 | } | ||
| 49 | |||
| 32 | static void send_event(struct grail *ge, struct slot_state *s, | 50 | static void send_event(struct grail *ge, struct slot_state *s, |
| 33 | const struct gesture_event *ev) | 51 | const struct gesture_event *ev) |
| 34 | { | 52 | { |
| @@ -151,7 +169,7 @@ void gin_frame_end(struct grail *ge, | |||
| 151 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) { | 169 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) { |
| 152 | struct slot_state *s = &gin->state[i]; | 170 | struct slot_state *s = &gin->state[i]; |
| 153 | if (!s->nclient || s->priority < discard) | 171 | if (!s->nclient || s->priority < discard) |
| 154 | gin_gesture_discard(gin, i); | 172 | gin_gid_discard(ge, s->id); |
| 155 | } | 173 | } |
| 156 | 174 | ||
| 157 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) { | 175 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) { |
| @@ -169,22 +187,22 @@ void gin_frame_end(struct grail *ge, | |||
| 169 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) { | 187 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) { |
| 170 | struct slot_state *s = &gin->state[i]; | 188 | struct slot_state *s = &gin->state[i]; |
| 171 | if (s->status == GRAIL_STATUS_END) | 189 | if (s->status == GRAIL_STATUS_END) |
| 172 | gin_gesture_discard(gin, i); | 190 | gin_gid_discard(ge, s->id); |
| 173 | } | 191 | } |
| 174 | 192 | ||
| 175 | if (grail_mask_count(span, sizeof(span))) | 193 | if (grail_mask_count(span, sizeof(span))) |
| 176 | grail_mask_set(filtered, EV_ABS); | 194 | grail_mask_set(filtered, EV_ABS); |
| 177 | } | 195 | } |
| 178 | 196 | ||
| 179 | int gin_gesture_begin(struct grail *ge, int type, int priority, | 197 | int gin_gid_begin_select(struct grail *ge, int type, int priority, |
| 180 | const grail_mask_t *span, int nspan) | 198 | const grail_mask_t *span, int nspan) |
| 181 | { | 199 | { |
| 182 | struct gesture_inserter *gin = ge->gin; | 200 | struct gesture_inserter *gin = ge->gin; |
| 183 | struct slot_state *s; | 201 | struct slot_state *s; |
| 184 | int geslot = grail_mask_get_first(gin->unused, sizeof(gin->unused)); | 202 | int i = grail_mask_get_first(gin->unused, sizeof(gin->unused)); |
| 185 | if (geslot < 0) | 203 | if (i < 0) |
| 186 | return -1; | 204 | return -1; |
| 187 | s = &gin->state[geslot]; | 205 | s = &gin->state[i]; |
| 188 | s->type = type; | 206 | s->type = type; |
| 189 | s->priority = priority; | 207 | s->priority = priority; |
| 190 | s->id = gin->gestureid++ & MAX_GESTURE_ID; | 208 | s->id = gin->gestureid++ & MAX_GESTURE_ID; |
| @@ -192,47 +210,72 @@ int gin_gesture_begin(struct grail *ge, int type, int priority, | |||
| 192 | s->nclient = 0; | 210 | s->nclient = 0; |
| 193 | memcpy(s->span, span, nspan); | 211 | memcpy(s->span, span, nspan); |
| 194 | gebuf_clear(&s->buf); | 212 | gebuf_clear(&s->buf); |
| 195 | grail_mask_clear(gin->unused, geslot); | 213 | grail_mask_clear(gin->unused, i); |
| 196 | grail_mask_set(gin->fresh, geslot); | 214 | grail_mask_set(gin->fresh, i); |
| 197 | grail_mask_set(gin->used, geslot); | 215 | grail_mask_set(gin->used, i); |
| 198 | return geslot; | 216 | return s->id; |
| 199 | } | ||
| 200 | |||
| 201 | void gin_gesture_end(struct gesture_inserter *gin, int geslot) | ||
| 202 | { | ||
| 203 | gin->state[geslot].status = GRAIL_STATUS_END; | ||
| 204 | } | 217 | } |
| 205 | 218 | ||
| 206 | void gin_gesture_discard(struct gesture_inserter *gin, int geslot) | 219 | int gin_gid_begin(struct grail *ge, int type, const struct touch_frame *frame) |
| 207 | { | 220 | { |
| 208 | gebuf_clear(&gin->state[geslot].buf); | 221 | return gin_gid_begin_select(ge, type, 1, |
| 209 | gin_gesture_end(gin, geslot); | 222 | frame->touches, sizeof(frame->touches)); |
| 210 | grail_mask_clear(gin->used, geslot); | ||
| 211 | grail_mask_set(gin->unused, geslot); | ||
| 212 | } | 223 | } |
| 213 | 224 | ||
| 214 | void gin_gesture_discard_type(struct gesture_inserter *gin, int type) | 225 | void gin_gid_discard(struct grail *ge, int gid) |
| 215 | { | 226 | { |
| 216 | int i; | 227 | struct gesture_inserter *gin = ge->gin; |
| 217 | grail_mask_foreach(i, gin->used, sizeof(gin->used)) | 228 | struct slot_state *s; |
| 218 | if (gin->state[i].type == type) | 229 | int i = find_gslot(gin, gid); |
| 219 | gin_gesture_discard(gin, i); | 230 | if (i < 0) |
| 231 | return; | ||
| 232 | s = &gin->state[i]; | ||
| 233 | gebuf_clear(&s->buf); | ||
| 234 | s->status = GRAIL_STATUS_END; | ||
| 235 | grail_mask_clear(gin->used, i); | ||
| 236 | grail_mask_set(gin->unused, i); | ||
| 220 | } | 237 | } |
| 221 | 238 | ||
| 222 | void gin_gesture_event(struct gesture_inserter *gin, int geslot, | 239 | void gin_gid_event(struct grail *ge, int gid, |
| 223 | float x, float y, int ntouch, | 240 | float x, float y, int ntouch, |
| 224 | const grail_prop_t *prop, int nprop) | 241 | const grail_prop_t *prop, int nprop, |
| 242 | int status) | ||
| 225 | { | 243 | { |
| 226 | struct slot_state *s = &gin->state[geslot]; | 244 | struct gesture_inserter *gin = ge->gin; |
| 227 | struct gesture_event ev; | 245 | struct gesture_event ev; |
| 246 | struct slot_state *s; | ||
| 247 | int i = find_gslot(gin, gid); | ||
| 248 | if (i < 0) | ||
| 249 | return; | ||
| 250 | s = &gin->state[i]; | ||
| 228 | ev.ntouch = ntouch; | 251 | ev.ntouch = ntouch; |
| 229 | ev.nprop = nprop; | 252 | ev.nprop = nprop; |
| 230 | ev.time = gin->time; | 253 | ev.time = gin->time; |
| 231 | ev.pos.x = x; | 254 | ev.pos.x = x; |
| 232 | ev.pos.y = y; | 255 | ev.pos.y = y; |
| 233 | memcpy(ev.prop, prop, nprop * sizeof(grail_prop_t)); | 256 | memcpy(ev.prop, prop, nprop * sizeof(grail_prop_t)); |
| 234 | if (s->status == GRAIL_STATUS_BEGIN) | ||
| 235 | s->status = GRAIL_STATUS_UPDATE; | ||
| 236 | gebuf_put(&s->buf, &ev); | 257 | gebuf_put(&s->buf, &ev); |
| 258 | if (s->status == GRAIL_STATUS_BEGIN) | ||
| 259 | s->status = status; | ||
| 237 | } | 260 | } |
| 238 | 261 | ||
| 262 | void gin_gid_end(struct grail *ge, int gid, | ||
| 263 | float x, float y, int ntouch) | ||
| 264 | { | ||
| 265 | struct gesture_inserter *gin = ge->gin; | ||
| 266 | struct gesture_event ev; | ||
| 267 | struct slot_state *s; | ||
| 268 | int i = find_gslot(gin, gid); | ||
| 269 | if (i < 0) | ||
| 270 | return; | ||
| 271 | s = &gin->state[i]; | ||
| 272 | if (s->status != GRAIL_STATUS_BEGIN) { | ||
| 273 | ev.ntouch = ntouch; | ||
| 274 | ev.nprop = 0; | ||
| 275 | ev.time = gin->time; | ||
| 276 | ev.pos.x = x; | ||
| 277 | ev.pos.y = y; | ||
| 278 | gebuf_put(&s->buf, &ev); | ||
| 279 | } | ||
| 280 | s->status = GRAIL_STATUS_END; | ||
| 281 | } | ||
