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.c126
1 files changed, 0 insertions, 126 deletions
diff --git a/test/grail-gesture.c b/test/grail-gesture.c
deleted file mode 100644
index 614bf1a..0000000
--- a/test/grail-gesture.c
+++ /dev/null
@@ -1,126 +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.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 fprintf(stderr, "%lu.%06u %04x %04x %d\n",
50 ev->time.tv_sec, (unsigned)ev->time.tv_usec,
51 ev->type, ev->code, ev->value);
52}
53
54static void tp_gesture(struct grail *ge, const struct grail_event *ev)
55{
56 struct grail_contact touch[32];
57 int i, ntouch;
58 fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n",
59 ev->type, ev->id, ev->client_id.client, ev->client_id.event,
60 ev->pos.x, ev->pos.y, ev->ntouch,
61 ev->status);
62 ntouch = grail_get_contacts(ge, touch, 32);
63 for (i = 0; i < ntouch; i++) {
64 const struct grail_contact *t = &touch[i];
65 fprintf(stderr, "\t%d: %d %d\n", i, t->id, t->tool_type);
66 fprintf(stderr, "\t %f %f\n", t->pos.x, t->pos.y);
67 fprintf(stderr, "\t %f %f %f %f\n", t->touch_major,
68 t->touch_minor, t->width_major, t->width_minor);
69 fprintf(stderr, "\t %f %f\n", t->angle, t->pressure);
70 }
71 for (i = 0; i < ev->nprop; i++)
72 fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]);
73}
74
75static void loop_device(struct grail *ge, int fd)
76{
77 while (!grail_idle(ge, fd, 5000))
78 grail_pull(ge, fd);
79}
80
81int main(int argc, char *argv[])
82{
83 struct grail ge;
84 int i, fd;
85
86 if (argc < 3) {
87 fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]);
88 return -1;
89 }
90
91 memset(&ge, 0, sizeof(ge));
92 ge.get_clients = tp_get_clients;
93 ge.event = tp_event;
94 ge.gesture = tp_gesture;
95
96 unsigned long mask = strtoull(argv[1], 0, 0);
97 for (i = 0; i < DIM_GRAIL_TYPE; i++)
98 if ((mask >> i) & 1)
99 grail_mask_set(flag_mask, i);
100
101 fd = open(argv[2], O_RDONLY | O_NONBLOCK);
102 if (fd < 0) {
103 fprintf(stderr, "error: could not open device\n");
104 return -1;
105 }
106 if (ioctl(fd, EVIOCGRAB, 1)) {
107 fprintf(stderr, "error: could not grab the device\n");
108 return -1;
109 }
110
111 if (grail_open(&ge, fd)) {
112 fprintf(stderr, "error: could not open touch device\n");
113 return -1;
114 }
115 //grail_filter_abs_events(&ge, 1);
116
117 struct grail_coord min = { -2, -1 }, max = { 2, 1 };
118 grail_set_bbox(&ge, &min, &max);
119
120 loop_device(&ge, fd);
121 grail_close(&ge, fd);
122
123 ioctl(fd, EVIOCGRAB, 0);
124 close(fd);
125 return 0;
126}