summaryrefslogtreecommitdiff
path: root/test/grail.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/grail.c')
-rw-r--r--test/grail.c154
1 files changed, 35 insertions, 119 deletions
diff --git a/test/grail.c b/test/grail.c
index e22ffd8..85c5bd4 100644
--- a/test/grail.c
+++ b/test/grail.c
@@ -22,146 +22,60 @@
22 * 22 *
23 ****************************************************************************/ 23 ****************************************************************************/
24 24
25#include <grail-gesture.h> 25#include <grail.h>
26#include <string.h> 26#include <string.h>
27#include <stdio.h> 27#include <stdio.h>
28#include <unistd.h> 28#include <unistd.h>
29#include <fcntl.h> 29#include <fcntl.h>
30 30
31struct gesture_handler { 31static int tp_get_clients(struct grail *ge,
32 struct touch_frame frame; 32 struct grail_client_info *clients, int max_clients,
33 struct gesture_client client; 33 const struct grail_coord *coords, int num_coords,
34 struct gesture_dev dev; 34 const grail_mask_t *types)
35 touch_time_t last_scroll;
36};
37
38static void gh_gesture(struct gesture_client *client,
39 const struct gesture_event *ev)
40{
41 int i;
42 fprintf(stderr, "gesture %d %lld\n",
43 ev->type, ev->time);
44 switch (ev->type) {
45 case GE_MOVE:
46 fprintf(stderr, " %d\n", ev->prop[0]);
47 fprintf(stderr, " %d\n", ev->prop[1]);
48 break;
49 case GE_VSCROLL:
50 fprintf(stderr, " %d\n", ev->prop[0]);
51 break;
52 }
53}
54
55static void gh_init(struct gesture_handler *gh)
56{ 35{
57 memset(gh, 0, sizeof(*gh)); 36 memset(&clients[0], 0, sizeof(clients[0]));
58 gedev_init(&gh->dev, 0); 37 clients[0].id.client = 345;
59 client_init(&gh->client, gh); 38 clients[0].id.root = 1;
60 gh->client.gesture = gh_gesture; 39 clients[0].id.event = 2;
61 gh->client.priority[GE_MOVE] = 1; 40 clients[0].id.child = 3;
62 gh->client.priority[GE_VSCROLL] = 2; 41 clients[0].mask[0] = 3;
63 gedev_attach_client(&gh->dev, &gh->client); 42 return 1;
64} 43}
65 44
66static void gh_handle(struct gesture_handler *gh, 45static void tp_event(struct grail *ge, const struct input_event *ev)
67 const struct touch_frame *frame,
68 touch_time_t time)
69{ 46{
70 struct gesture_flag flag; 47 fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value);
71 struct gesture_event ev;
72 if (frame->ntouch == 1 || frame->ntouch == 2) {
73 flag.type = GE_MOVE;
74 flag.time = time;
75 flag.state = GS_BEGIN;
76 gedev_flag(&gh->dev, &flag);
77
78 ev.type = GE_MOVE;
79 ev.time = time;
80 ev.prop[0] =
81 frame->touch[0].prop[TP_POS_X] -
82 gh->frame.touch[0].prop[TP_POS_X];
83 ev.prop[1] =
84 frame->touch[0].prop[TP_POS_Y] -
85 gh->frame.touch[0].prop[TP_POS_Y];
86 if (ev.prop[0] || ev.prop[1])
87 gedev_event(&gh->dev, &ev);
88
89 flag.time = time + 1;
90 flag.state = GS_END;
91 gedev_flag(&gh->dev, &flag);
92 }
93 if (frame->ntouch == 2) {
94 flag.type = GE_VSCROLL;
95 flag.time = time;
96 flag.state = GS_BEGIN;
97 gedev_flag(&gh->dev, &flag);
98
99 ev.type = GE_VSCROLL;
100 ev.time = time;
101 ev.prop[0] =
102 frame->touch[0].prop[TP_POS_Y] -
103 gh->frame.touch[0].prop[TP_POS_Y];
104
105 if (ev.prop[0])
106 gedev_event(&gh->dev, &ev);
107
108 if (time > gh->last_scroll + 100) {
109 flag.time = time + 1;
110 flag.state = GS_END;
111 gedev_flag(&gh->dev, &flag);
112 gh->last_scroll = time;
113 }
114 } else {
115 flag.type = GE_VSCROLL;
116 flag.time = time;
117 flag.state = GS_CANCEL;
118 gedev_flag(&gh->dev, &flag);
119 }
120 gedev_sync(&gh->dev);
121 gh->frame = *frame;
122} 48}
123 49
124static void gh_destroy(struct gesture_handler *gh) 50static void tp_gesture(struct grail *ge, const struct grail_event *ev)
125{ 51{
126 gedev_detach_client(&gh->dev, &gh->client); 52 fprintf(stderr, "gesture %d %d %d %d: %d %d\n",
127 client_destroy(&gh->client); 53 ev->type, ev->id,
128 gedev_destroy(&gh->dev); 54 ev->client_id.client, ev->client_id.event,
55 ev->prop[0], ev->prop[1]);
129} 56}
130 57
131static void tp_event(struct touch_engine *engine, 58static void loop_device(struct grail *ge, int fd)
132 const struct input_event *ev)
133{ 59{
134} 60 while (!grail_idle(ge, fd, 5000))
135 61 grail_pull(ge, fd);
136static void tp_sync(struct touch_engine *engine,
137 const struct input_event *syn)
138{
139 struct gesture_handler *gh = engine->priv;
140 struct touch_frame *frame = &engine->frame;
141 gh_handle(gh, frame, frame->time);
142}
143
144static void loop_device(struct touch_dev *dev, int fd)
145{
146 struct gesture_handler gh;
147 struct touch_engine engine;
148 gh_init(&gh);
149 touch_engine_init(&engine, tp_event, tp_sync, &gh);
150 touch_engine_attach(&engine, dev);
151 while (!touch_dev_idle(dev, fd, 5000))
152 touch_dev_pull(dev, fd);
153 touch_engine_detach(&engine, dev);
154 gh_destroy(&gh);
155} 62}
156 63
157int main(int argc, char *argv[]) 64int main(int argc, char *argv[])
158{ 65{
159 struct touch_dev dev; 66 struct grail ge;
160 int fd; 67 int fd;
68
161 if (argc < 2) { 69 if (argc < 2) {
162 fprintf(stderr, "Usage: %s <device>\n", argv[0]); 70 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
163 return -1; 71 return -1;
164 } 72 }
73
74 memset(&ge, 0, sizeof(ge));
75 ge.get_clients = tp_get_clients;
76 ge.event = tp_event;
77 ge.gesture = tp_gesture;
78
165 fd = open(argv[1], O_RDONLY | O_NONBLOCK); 79 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
166 if (fd < 0) { 80 if (fd < 0) {
167 fprintf(stderr, "error: could not open device\n"); 81 fprintf(stderr, "error: could not open device\n");
@@ -171,12 +85,14 @@ int main(int argc, char *argv[])
171 fprintf(stderr, "error: could not grab the device\n"); 85 fprintf(stderr, "error: could not grab the device\n");
172 return -1; 86 return -1;
173 } 87 }
174 if (touch_dev_open(&dev, fd)) { 88
89 if (grail_open(&ge, fd)) {
175 fprintf(stderr, "error: could not open touch device\n"); 90 fprintf(stderr, "error: could not open touch device\n");
176 return -1; 91 return -1;
177 } 92 }
178 loop_device(&dev, fd); 93 loop_device(&ge, fd);
179 touch_dev_close(&dev, fd); 94 grail_close(&ge, fd);
95
180 ioctl(fd, EVIOCGRAB, 0); 96 ioctl(fd, EVIOCGRAB, 0);
181 close(fd); 97 close(fd);
182 return 0; 98 return 0;