summaryrefslogtreecommitdiff
path: root/src/grail-api.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-07-29 15:54:31 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commite0eb1015bf30fd0913db571b000ba6a83ea22660 (patch)
treea3d62152066cfb8521c80806596a4fb0fe322014 /src/grail-api.c
parentb76660d71e2ea77752025089bd71deffad64e325 (diff)
Split the code into recognizer and inserter
Refactor code to make more room for gesture recognition. Also simplify public headers. Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'src/grail-api.c')
-rw-r--r--src/grail-api.c133
1 files changed, 43 insertions, 90 deletions
diff --git a/src/grail-api.c b/src/grail-api.c
index dbe4977..19b66aa 100644
--- a/src/grail-api.c
+++ b/src/grail-api.c
@@ -1,4 +1,5 @@
1#include <grail-gesture.h> 1#include "grail-inserter.h"
2#include "grail-recognizer.h"
2#include <grail.h> 3#include <grail.h>
3#include <string.h> 4#include <string.h>
4#include <stdio.h> 5#include <stdio.h>
@@ -6,93 +7,46 @@
6#include <fcntl.h> 7#include <fcntl.h>
7#include <malloc.h> 8#include <malloc.h>
8#include <errno.h> 9#include <errno.h>
10#include "evbuf.h"
9 11
10struct grail_impl { 12struct grail_impl {
11 struct touch_dev dev; 13 struct touch_dev dev;
12 struct touch_engine engine; 14 struct touch_engine engine;
13 struct touch_frame frame; 15 struct evbuf evbuf;
14 struct gesture_dev gedev;
15 struct gesture_client client;
16 touch_time_t last_scroll;
17}; 16};
18 17
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, 18static void tp_event(struct touch_engine *engine,
80 const struct input_event *ev) 19 const struct input_event *ev)
81{ 20{
82 struct grail *ge = engine->priv; 21 struct grail *ge = engine->priv;
83 if (ge->event) 22 struct grail_impl *x = ge->impl;
84 ge->event(ge, ev); 23 evbuf_put(&x->evbuf, ev);
85} 24}
86 25
87static void tp_sync(struct touch_engine *engine, 26static void tp_sync(struct touch_engine *engine,
88 const struct input_event *syn) 27 const struct input_event *syn)
89{ 28{
29 struct input_event ev;
90 struct grail *ge = engine->priv; 30 struct grail *ge = engine->priv;
91#if 0 31 struct grail_impl *x = ge->impl;
92 struct touch_frame *frame = &engine->frame; 32 struct touch_frame *frame = &engine->frame;
93 gh_handle(ge, frame, frame->time); 33 grail_mask_t filtered[DIM_EV_TYPE_BYTES];
94#endif 34 int nevent = 0;
95 if (ge->event) 35 gin_frame_begin(ge, frame->time);
36 gru_recognize(ge, frame);
37 gin_frame_end(ge, filtered);
38 if (!ge->event) {
39 evbuf_clear(&x->evbuf);
40 return;
41 }
42 while (!evbuf_empty(&x->evbuf)) {
43 evbuf_get(&x->evbuf, &ev);
44 if (grail_get_mask(filtered, ev.type))
45 continue;
46 ge->event(ge, &ev);
47 nevent++;
48 }
49 if (nevent)
96 ge->event(ge, syn); 50 ge->event(ge, syn);
97} 51}
98 52
@@ -103,49 +57,48 @@ int grail_open(struct grail *ge, int fd)
103 x = calloc(1, sizeof(*x)); 57 x = calloc(1, sizeof(*x));
104 if (!x) 58 if (!x)
105 return -ENOMEM; 59 return -ENOMEM;
60 ret = gin_init(ge);
61 if (ret)
62 goto freemem;
63 ret = gru_init(ge);
64 if (ret)
65 goto freedev;
106 ret = touch_dev_open(&x->dev, fd); 66 ret = touch_dev_open(&x->dev, fd);
107 if (ret) 67 if (ret)
108 goto error; 68 goto freegru;
109 touch_engine_init(&x->engine, tp_event, tp_sync, ge); 69 touch_engine_init(&x->engine, tp_event, tp_sync, ge);
110 touch_engine_attach(&x->engine, &x->dev); 70 touch_engine_attach(&x->engine, &x->dev);
111 ge->impl = x; 71 ge->impl = x;
112 return 0; 72 return 0;
113 error: 73 freegru:
74 gru_destroy(ge);
75 freedev:
76 gin_destroy(ge);
77 freemem:
114 free(x); 78 free(x);
115 return ret; 79 return ret;
116} 80}
117 81
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) 82void grail_close(struct grail *ge, int fd)
131{ 83{
132 struct grail_impl *x = ge->impl; 84 struct grail_impl *x = ge->impl;
133 touch_engine_detach(&x->engine, &x->dev); 85 touch_engine_detach(&x->engine, &x->dev);
134 touch_dev_close(&x->dev, fd); 86 touch_dev_close(&x->dev, fd);
87 gru_destroy(ge);
88 gin_destroy(ge);
135 free(ge->impl); 89 free(ge->impl);
136 ge->impl = 0; 90 ge->impl = 0;
137} 91}
138 92
139void grail_add_client(struct grail *ge, grail_clientid_t id, 93int grail_idle(struct grail *ge, int fd, int ms)
140 const int *types, const int *priority, int ntypes)
141{ 94{
142 struct grail_impl *x = ge->impl; 95 struct grail_impl *x = ge->impl;
143 //gedev_attach_client(&x->dev, &x->client); 96 return touch_dev_idle(&x->dev, fd, ms);
144} 97}
145 98
146void grail_remove_client(struct grail *ge, grail_clientid_t id) 99int grail_pull(struct grail *ge, int fd)
147{ 100{
148 struct grail_impl *x = ge->impl; 101 struct grail_impl *x = ge->impl;
149 //gedev_detach_client(&x->dev, &x->client); 102 return touch_dev_pull(&x->dev, fd);
150} 103}
151 104