summaryrefslogtreecommitdiff
path: root/test/grail-gesture.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/grail-gesture.c')
-rw-r--r--test/grail-gesture.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/test/grail-gesture.c b/test/grail-gesture.c
new file mode 100644
index 0000000..f34bd6f
--- /dev/null
+++ b/test/grail-gesture.c
@@ -0,0 +1,114 @@
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.h>
26#include <string.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <fcntl.h>
30
31static grail_mask_t flag_mask[DIM_GRAIL_TYPE_BYTES];
32
33static int tp_get_clients(struct grail *ge,
34 struct grail_client_info *clients, int max_clients,
35 const struct grail_coord *coords, int num_coords,
36 const grail_mask_t *types, int type_bytes)
37{
38 memset(&clients[0], 0, sizeof(clients[0]));
39 clients[0].id.client = 345;
40 clients[0].id.root = 1;
41 clients[0].id.event = 2;
42 clients[0].id.child = 3;
43 memcpy(clients[0].mask, flag_mask, sizeof(flag_mask));
44 return 1;
45}
46
47static void tp_event(struct grail *ge, const struct input_event *ev)
48{
49 if (!grail_mask_get(flag_mask, GRAIL_TYPE_POINTER))
50 return;
51 fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value);
52}
53
54static void tp_gesture(struct grail *ge, const struct grail_event *ev)
55{
56 int i;
57 fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n",
58 ev->type, ev->id, ev->client_id.client, ev->client_id.event,
59 ev->pos.x, ev->pos.y, ev->ntouch,
60 ev->status);
61 for (i = 0; i < ev->nprop; i++)
62 fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]);
63}
64
65static void loop_device(struct grail *ge, int fd)
66{
67 while (!grail_idle(ge, fd, 5000)) {
68 grail_pull(ge, fd);
69 fprintf(stderr, "\r");
70 }
71}
72
73int main(int argc, char *argv[])
74{
75 struct grail ge;
76 int fd;
77
78 if (argc < 3) {
79 fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]);
80 return -1;
81 }
82
83 memset(&ge, 0, sizeof(ge));
84 ge.get_clients = tp_get_clients;
85 ge.event = tp_event;
86 ge.gesture = tp_gesture;
87
88 unsigned mask = atoi(argv[1]);
89 flag_mask[0] = (mask >> 0) & 255;
90 flag_mask[1] = (mask >> 8) & 255;
91 flag_mask[2] = (mask >> 16) & 255;
92 flag_mask[3] = (mask >> 24) & 255;
93
94 fd = open(argv[2], O_RDONLY | O_NONBLOCK);
95 if (fd < 0) {
96 fprintf(stderr, "error: could not open device\n");
97 return -1;
98 }
99 if (ioctl(fd, EVIOCGRAB, 1)) {
100 fprintf(stderr, "error: could not grab the device\n");
101 return -1;
102 }
103
104 if (grail_open(&ge, fd)) {
105 fprintf(stderr, "error: could not open touch device\n");
106 return -1;
107 }
108 loop_device(&ge, fd);
109 grail_close(&ge, fd);
110
111 ioctl(fd, EVIOCGRAB, 0);
112 close(fd);
113 return 0;
114}