diff options
Diffstat (limited to 'src/grail-recognizer.c')
| -rw-r--r-- | src/grail-recognizer.c | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/src/grail-recognizer.c b/src/grail-recognizer.c index 9ede059..1e7a8bf 100644 --- a/src/grail-recognizer.c +++ b/src/grail-recognizer.c | |||
| @@ -22,24 +22,21 @@ | |||
| 22 | * | 22 | * |
| 23 | ****************************************************************************/ | 23 | ****************************************************************************/ |
| 24 | 24 | ||
| 25 | #include "grail-inserter.h" | 25 | #include "grail-recognizer.h" |
| 26 | #include <string.h> | 26 | #include <string.h> |
| 27 | #include <malloc.h> | 27 | #include <malloc.h> |
| 28 | #include <errno.h> | 28 | #include <errno.h> |
| 29 | 29 | ||
| 30 | struct gesture_recognizer { | 30 | static const touch_time_t DROP_TIMEOUT_MS = 100; |
| 31 | struct touch_frame frame; | ||
| 32 | touch_time_t scroll_time; | ||
| 33 | int scroll_active; | ||
| 34 | int scroll_gslot; | ||
| 35 | int scroll_slots[2]; | ||
| 36 | }; | ||
| 37 | 31 | ||
| 38 | int gru_init(struct grail *ge) | 32 | int gru_init(struct grail *ge, const struct touch_dev_caps *caps) |
| 39 | { | 33 | { |
| 40 | ge->gru = calloc(1, sizeof(struct gesture_recognizer)); | 34 | struct gesture_recognizer *gru; |
| 41 | if (!ge->gru) | 35 | gru = calloc(1, sizeof(struct gesture_recognizer)); |
| 36 | if (!gru) | ||
| 42 | return -ENOMEM; | 37 | return -ENOMEM; |
| 38 | ge->gru = gru; | ||
| 39 | gru_init_motion(ge, caps); | ||
| 43 | return 0; | 40 | return 0; |
| 44 | } | 41 | } |
| 45 | 42 | ||
| @@ -49,49 +46,32 @@ void gru_destroy(struct grail *ge) | |||
| 49 | ge->gru = NULL; | 46 | ge->gru = NULL; |
| 50 | } | 47 | } |
| 51 | 48 | ||
| 49 | static void reset_gru_state(struct grail *ge, const struct touch_frame *frame) | ||
| 50 | { | ||
| 51 | gru_reset_combo(ge, frame); | ||
| 52 | gru_reset_rotate(ge, frame); | ||
| 53 | gru_reset_zoom(ge, frame); | ||
| 54 | gru_reset_scroll(ge, frame); | ||
| 55 | gru_reset_motion(ge, frame); | ||
| 56 | } | ||
| 57 | |||
| 52 | void gru_recognize(struct grail *ge, const struct touch_frame *frame) | 58 | void gru_recognize(struct grail *ge, const struct touch_frame *frame) |
| 53 | { | 59 | { |
| 54 | struct gesture_inserter *gin = ge->gin; | ||
| 55 | struct gesture_recognizer *gru = ge->gru; | 60 | struct gesture_recognizer *gru = ge->gru; |
| 56 | grail_prop_t prop[DIM_GRAIL_PROP]; | 61 | struct move_model *move = &gru->move; |
| 57 | grail_mask_t span[16]; | 62 | if (!ge->gin || !ge->gru) |
| 58 | int slot, nslot, x, y, dx, dy; | ||
| 59 | if (!gru) | ||
| 60 | return; | ||
| 61 | if (frame->ncreate || frame->ndestroy) { | ||
| 62 | gin_gesture_end_all(gin); | ||
| 63 | gru->scroll_active = 0; | ||
| 64 | return; | 63 | return; |
| 65 | } | 64 | if (frame->nactive < move->ntouch && |
| 66 | if (frame->ntouch != 2) | 65 | frame->time < gru->frame.time + DROP_TIMEOUT_MS) |
| 67 | return; | 66 | return; |
| 68 | memset(span, 0, sizeof(span)); | 67 | if (frame->nactive < 2 || frame->ncreate || frame->ndestroy) { |
| 69 | nslot = 0; | 68 | reset_gru_state(ge, frame); |
| 70 | x = y = dx = dy = 0; | ||
| 71 | for (slot = frame->slot; slot >= 0; slot = next_slot(frame, slot)) { | ||
| 72 | struct touch *ot = &gru->frame.touch[slot]; | ||
| 73 | const struct touch *t = &frame->touch[slot]; | ||
| 74 | gru->scroll_slots[nslot] = slot; | ||
| 75 | grail_set_mask(span, slot); | ||
| 76 | x += t->prop[TP_POS_X]; | ||
| 77 | y += t->prop[TP_POS_Y]; | ||
| 78 | dx += t->prop[TP_POS_X] - ot->prop[TP_POS_X]; | ||
| 79 | dy += t->prop[TP_POS_Y] - ot->prop[TP_POS_Y]; | ||
| 80 | nslot++; | ||
| 81 | } | ||
| 82 | x /= nslot; | ||
| 83 | y /= nslot; | ||
| 84 | dx /= nslot; | ||
| 85 | dy /= nslot; | ||
| 86 | if (!dy) | ||
| 87 | return; | 69 | return; |
| 88 | if (!gru->scroll_active) { | ||
| 89 | gru->scroll_gslot = gin_gesture_begin(ge, frame, | ||
| 90 | GRAIL_TYPE_VSCROLL, | ||
| 91 | x, y, span); | ||
| 92 | gru->scroll_active = 1; | ||
| 93 | } | 70 | } |
| 94 | prop[0] = dy; | 71 | gru_compute_motion(ge, frame); |
| 95 | gin_gesture_event(gin, gru->scroll_gslot, prop); | 72 | gru_scroll(ge, frame); |
| 73 | gru_zoom(ge, frame); | ||
| 74 | gru_rotate(ge, frame); | ||
| 75 | gru_combo(ge, frame); | ||
| 96 | gru->frame = *frame; | 76 | gru->frame = *frame; |
| 97 | } | 77 | } |
