diff options
Diffstat (limited to 'src/gestures-touch.c')
| -rw-r--r-- | src/gestures-touch.c | 94 |
1 files changed, 94 insertions, 0 deletions
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 | |||
| 27 | static 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 | |||
| 36 | int 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 | |||
| 61 | int 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 | } | ||
