diff options
| author | Henrik Rydberg <rydberg@bitmath.org> | 2010-07-13 11:26:46 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@bitmath.org> | 2010-07-13 11:26:46 +0200 |
| commit | 3b837806891de6cf77d4d74d04567e7e68c82fc0 (patch) | |
| tree | 88073a81fa5be071f52a0999134fbd93d2881819 /src/gesture-client.c | |
Gesture Recognition And Instantiation Library (grail)
The aim of this first commit is to get down to hard testing of concepts,
and the library currently has two test programs, touch and grail,
which can be run on commandline. Touch tests the touch interface,
and grail tests the gesture interface.
Expect thinking errors and some glitches. Other than that, the code
runs fine.
Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/gesture-client.c')
| -rw-r--r-- | src/gesture-client.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/gesture-client.c b/src/gesture-client.c new file mode 100644 index 0000000..3b8eb5d --- /dev/null +++ b/src/gesture-client.c | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * grail - Gesture Recognition And Instantiation Library | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Canonical Ltd. | ||
| 6 | * | ||
| 7 | * This program is free software: you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the | ||
| 9 | * Free Software Foundation, either version 3 of the License, or (at your | ||
| 10 | * option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, but | ||
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License along | ||
| 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | * Authors: | ||
| 21 | * Henrik Rydberg <rydberg@bitmath.org> | ||
| 22 | * | ||
| 23 | ****************************************************************************/ | ||
| 24 | |||
| 25 | #include <gesture-client.h> | ||
| 26 | #include <gesture-buffer.h> | ||
| 27 | #include <malloc.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <errno.h> | ||
| 30 | |||
| 31 | #define GESTURE_GAP (1000 * 60 * 60) | ||
| 32 | |||
| 33 | struct client_impl { | ||
| 34 | enum gesture_state state; | ||
| 35 | touch_time_t begin, end; | ||
| 36 | struct gebuf buf; | ||
| 37 | }; | ||
| 38 | |||
| 39 | int client_init(struct gesture_client *client, void *priv) | ||
| 40 | { | ||
| 41 | struct client_impl *x; | ||
| 42 | memset(client, 0, sizeof(*client)); | ||
| 43 | x = calloc(DIM_GESTURE_TYPE, sizeof(*x)); | ||
| 44 | if (!x) | ||
| 45 | return -ENOMEM; | ||
| 46 | client->impl = x; | ||
| 47 | client->priv = priv; | ||
| 48 | return 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | void client_flag(struct gesture_client *client, | ||
| 52 | const struct gesture_flag *flag) | ||
| 53 | { | ||
| 54 | if (client->priority[flag->type]) { | ||
| 55 | struct client_impl *x = &client->impl[flag->type]; | ||
| 56 | switch(flag->state) { | ||
| 57 | case GS_BEGIN: | ||
| 58 | x->begin = flag->time; | ||
| 59 | x->end = flag->time + GESTURE_GAP; | ||
| 60 | break; | ||
| 61 | case GS_CANCEL: | ||
| 62 | x->end = x->begin; | ||
| 63 | break; | ||
| 64 | case GS_END: | ||
| 65 | x->end = flag->time; | ||
| 66 | break; | ||
| 67 | } | ||
| 68 | x->state = flag->state; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | void client_event(struct gesture_client *client, | ||
| 73 | const struct gesture_event *ev) | ||
| 74 | { | ||
| 75 | if (client->priority[ev->type]) { | ||
| 76 | struct client_impl *x = &client->impl[ev->type]; | ||
| 77 | gebuf_put(&x->buf, ev); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | void client_sync(struct gesture_client *client) | ||
| 82 | { | ||
| 83 | struct gesture_event ev; | ||
| 84 | struct client_impl *x = client->impl; | ||
| 85 | int i, prio = 0; | ||
| 86 | for (i = 0; i < DIM_GESTURE_TYPE; i++) { | ||
| 87 | if (x[i].begin != x[i].end) { | ||
| 88 | if (client->priority[i] > prio) | ||
| 89 | prio = client->priority[i]; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | for (i = 0; i < DIM_GESTURE_TYPE; i++) { | ||
| 93 | if (client->priority[i] < prio) { | ||
| 94 | gebuf_clear(&x[i].buf); | ||
| 95 | } else if (prio && client->gesture) { | ||
| 96 | if (x[i].state == GS_END) { | ||
| 97 | while (!gebuf_empty(&x[i].buf)) { | ||
| 98 | gebuf_get(&x[i].buf, &ev); | ||
| 99 | client->gesture(client, &ev); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | for (i = 0; i < DIM_GESTURE_TYPE; i++) | ||
| 105 | if (x[i].state == GS_END) | ||
| 106 | x[i].begin = x[i].end; | ||
| 107 | } | ||
| 108 | |||
| 109 | void client_destroy(struct gesture_client *client) | ||
| 110 | { | ||
| 111 | free(client->impl); | ||
| 112 | memset(client, 0, sizeof(*client)); | ||
| 113 | } | ||
