summaryrefslogtreecommitdiff
path: root/src/grail-api.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-07-26 13:51:34 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commitb76660d71e2ea77752025089bd71deffad64e325 (patch)
treec19adf132087edcdc1e721446d4975f37899239e /src/grail-api.c
parenteb896e11aacab5f53e3915a8d19ffffd92ce8e10 (diff)
Test implementation of grail api
This patch introduces the grail API, and a program to test it (evlink). Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/grail-api.c')
-rw-r--r--src/grail-api.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/grail-api.c b/src/grail-api.c
new file mode 100644
index 0000000..dbe4977
--- /dev/null
+++ b/src/grail-api.c
@@ -0,0 +1,151 @@
1#include <grail-gesture.h>
2#include <grail.h>
3#include <string.h>
4#include <stdio.h>
5#include <unistd.h>
6#include <fcntl.h>
7#include <malloc.h>
8#include <errno.h>
9
10struct grail_impl {
11 struct touch_dev dev;
12 struct touch_engine engine;
13 struct touch_frame frame;
14 struct gesture_dev gedev;
15 struct gesture_client client;
16 touch_time_t last_scroll;
17};
18
19static void gh_handle(struct grail_impl *gh,
20 const struct touch_frame *frame,
21 touch_time_t time)
22{
23#if 0
24 struct gesture_flag flag;
25 struct grail_event ev;
26 if (frame->ntouch == 1 || frame->ntouch == 2) {
27 flag.type = GE_MOVE;
28 flag.time = time;
29 flag.state = GS_BEGIN;
30 gedev_flag(&gh->dev, &flag);
31
32 ev.type = GE_MOVE;
33 ev.time = time;
34 ev.prop[0] =
35 frame->touch[0].prop[TP_POS_X] -
36 gh->frame.touch[0].prop[TP_POS_X];
37 ev.prop[1] =
38 frame->touch[0].prop[TP_POS_Y] -
39 gh->frame.touch[0].prop[TP_POS_Y];
40 if (ev.prop[0] || ev.prop[1])
41 gedev_event(&gh->dev, &ev);
42
43 flag.time = time + 1;
44 flag.state = GS_END;
45 gedev_flag(&gh->dev, &flag);
46 }
47 if (frame->ntouch == 2) {
48 flag.type = GE_VSCROLL;
49 flag.time = time;
50 flag.state = GS_BEGIN;
51 gedev_flag(&gh->dev, &flag);
52
53 ev.type = GE_VSCROLL;
54 ev.time = time;
55 ev.prop[0] =
56 frame->touch[0].prop[TP_POS_Y] -
57 gh->frame.touch[0].prop[TP_POS_Y];
58
59 if (ev.prop[0])
60 gedev_event(&gh->dev, &ev);
61
62 if (time > gh->last_scroll + 100) {
63 flag.time = time + 1;
64 flag.state = GS_END;
65 gedev_flag(&gh->dev, &flag);
66 gh->last_scroll = time;
67 }
68 } else {
69 flag.type = GE_VSCROLL;
70 flag.time = time;
71 flag.state = GS_CANCEL;
72 gedev_flag(&gh->dev, &flag);
73 }
74 gedev_sync(&gh->dev);
75 gh->frame = *frame;
76#endif
77}
78
79static void tp_event(struct touch_engine *engine,
80 const struct input_event *ev)
81{
82 struct grail *ge = engine->priv;
83 if (ge->event)
84 ge->event(ge, ev);
85}
86
87static void tp_sync(struct touch_engine *engine,
88 const struct input_event *syn)
89{
90 struct grail *ge = engine->priv;
91#if 0
92 struct touch_frame *frame = &engine->frame;
93 gh_handle(ge, frame, frame->time);
94#endif
95 if (ge->event)
96 ge->event(ge, syn);
97}
98
99int grail_open(struct grail *ge, int fd)
100{
101 struct grail_impl *x;
102 int ret;
103 x = calloc(1, sizeof(*x));
104 if (!x)
105 return -ENOMEM;
106 ret = touch_dev_open(&x->dev, fd);
107 if (ret)
108 goto error;
109 touch_engine_init(&x->engine, tp_event, tp_sync, ge);
110 touch_engine_attach(&x->engine, &x->dev);
111 ge->impl = x;
112 return 0;
113 error:
114 free(x);
115 return ret;
116}
117
118int grail_idle(struct grail *ge, int fd, int ms)
119{
120 struct grail_impl *x = ge->impl;
121 return touch_dev_idle(&x->dev, fd, ms);
122}
123
124int grail_pull(struct grail *ge, int fd)
125{
126 struct grail_impl *x = ge->impl;
127 return touch_dev_pull(&x->dev, fd);
128}
129
130void grail_close(struct grail *ge, int fd)
131{
132 struct grail_impl *x = ge->impl;
133 touch_engine_detach(&x->engine, &x->dev);
134 touch_dev_close(&x->dev, fd);
135 free(ge->impl);
136 ge->impl = 0;
137}
138
139void grail_add_client(struct grail *ge, grail_clientid_t id,
140 const int *types, const int *priority, int ntypes)
141{
142 struct grail_impl *x = ge->impl;
143 //gedev_attach_client(&x->dev, &x->client);
144}
145
146void grail_remove_client(struct grail *ge, grail_clientid_t id)
147{
148 struct grail_impl *x = ge->impl;
149 //gedev_detach_client(&x->dev, &x->client);
150}
151