1
/*****************************************************************************
3
* grail - Gesture Recognition And Instantiation Library
5
* Copyright (C) 2010 Canonical Ltd.
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.
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.
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/>.
21
* Henrik Rydberg <rydberg@bitmath.org>
23
****************************************************************************/
25
#include <gesture-client.h>
26
#include <gesture-buffer.h>
31
#define GESTURE_GAP (1000 * 60 * 60)
34
enum gesture_state state;
35
touch_time_t begin, end;
39
int client_init(struct gesture_client *client, void *priv)
41
struct client_impl *x;
42
memset(client, 0, sizeof(*client));
43
x = calloc(DIM_GESTURE_TYPE, sizeof(*x));
51
void client_flag(struct gesture_client *client,
52
const struct gesture_flag *flag)
54
if (client->priority[flag->type]) {
55
struct client_impl *x = &client->impl[flag->type];
58
x->begin = flag->time;
59
x->end = flag->time + GESTURE_GAP;
68
x->state = flag->state;
72
void client_event(struct gesture_client *client,
73
const struct gesture_event *ev)
75
if (client->priority[ev->type]) {
76
struct client_impl *x = &client->impl[ev->type];
77
gebuf_put(&x->buf, ev);
81
void client_sync(struct gesture_client *client)
83
struct gesture_event ev;
84
struct client_impl *x = client->impl;
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];
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);
104
for (i = 0; i < DIM_GESTURE_TYPE; i++)
105
if (x[i].state == GS_END)
106
x[i].begin = x[i].end;
109
void client_destroy(struct gesture_client *client)
112
memset(client, 0, sizeof(*client));