summaryrefslogtreecommitdiff
path: root/src/gesture-client.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-07-29 15:54:31 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commite0eb1015bf30fd0913db571b000ba6a83ea22660 (patch)
treea3d62152066cfb8521c80806596a4fb0fe322014 /src/gesture-client.c
parentb76660d71e2ea77752025089bd71deffad64e325 (diff)
Split the code into recognizer and inserter
Refactor code to make more room for gesture recognition. Also simplify public headers. Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/gesture-client.c')
-rw-r--r--src/gesture-client.c113
1 files changed, 0 insertions, 113 deletions
diff --git a/src/gesture-client.c b/src/gesture-client.c
deleted file mode 100644
index 91f1530..0000000
--- a/src/gesture-client.c
+++ /dev/null
@@ -1,113 +0,0 @@
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 <grail-gesture.h>
26#include <malloc.h>
27#include <string.h>
28#include <errno.h>
29#include "gebuf.h"
30
31#define GESTURE_GAP (1000 * 60 * 60)
32
33struct client_impl {
34 enum gesture_state state;
35 touch_time_t begin, end;
36 struct gebuf buf;
37};
38
39int 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
51void 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
72void 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
81void 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
109void client_destroy(struct gesture_client *client)
110{
111 free(client->impl);
112 memset(client, 0, sizeof(*client));
113}