summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grail-api.c165
-rw-r--r--src/grail-impl.h7
2 files changed, 15 insertions, 157 deletions
diff --git a/src/grail-api.c b/src/grail-api.c
index a584e23..22724ee 100644
--- a/src/grail-api.c
+++ b/src/grail-api.c
@@ -40,22 +40,6 @@ void grail_filter_abs_events(struct grail *ge, int usage)
40 x->filter_abs = usage; 40 x->filter_abs = usage;
41} 41}
42 42
43static void init_impl(struct grail_impl *x)
44{
45 if (evemu_has_event(x->evemu, EV_ABS, ABS_X)) {
46 x->emin_x = evemu_get_abs_minimum(x->evemu, ABS_X);
47 x->emin_y = evemu_get_abs_minimum(x->evemu, ABS_Y);
48 x->emax_x = evemu_get_abs_maximum(x->evemu, ABS_X);
49 x->emax_y = evemu_get_abs_maximum(x->evemu, ABS_Y);
50 } else {
51 struct utouch_surface *s = utouch_frame_get_surface(x->fh);
52 x->emin_x = s->min_x;
53 x->emin_y = s->min_y;
54 x->emax_x = s->max_x;
55 x->emax_y = s->max_y;
56 }
57}
58
59int grail_open(struct grail *ge, int fd) 43int grail_open(struct grail *ge, int fd)
60{ 44{
61 struct grail_impl *x; 45 struct grail_impl *x;
@@ -91,7 +75,6 @@ int grail_open(struct grail *ge, int fd)
91 if (ret) 75 if (ret)
92 goto freeframe; 76 goto freeframe;
93 77
94 init_impl(x);
95 ge->impl = x; 78 ge->impl = x;
96 79
97 ret = gin_init(ge); 80 ret = gin_init(ge);
@@ -144,117 +127,12 @@ void grail_get_units(const struct grail *ge,
144 max->y = s->max_y; 127 max->y = s->max_y;
145} 128}
146 129
147// legacy glue below
148
149static void evput(struct grail_impl *x, struct timeval time,
150 unsigned type, unsigned code, int value)
151{
152 struct input_event ev = { time, type, code, value };
153 evbuf_put(&x->evbuf, &ev);
154}
155
156static void report_down(struct grail_impl *impl)
157{
158 if (impl->report_status)
159 return;
160 evput(impl, impl->report_time, EV_KEY, BTN_TOUCH, 1);
161 evput(impl, impl->report_time, EV_ABS, ABS_X, impl->report_x);
162 evput(impl, impl->report_time, EV_ABS, ABS_Y, impl->report_y);
163 impl->report_status = 1;
164}
165
166static void report_up(struct grail_impl *impl, const struct input_event *syn)
167{
168 if (!impl->report_status)
169 return;
170 evput(impl, syn->time, EV_KEY, BTN_TOUCH, 0);
171 impl->report_status = 0;
172}
173
174static void set_pointer(struct grail_impl *impl)
175{
176 struct utouch_surface *s = utouch_frame_get_surface(impl->fh);
177 const struct utouch_frame *frame = impl->frame;
178 int best_x, best_y, best_d = -1;
179 int i;
180
181 for (i = 0; i < frame->num_active; i++) {
182 const struct utouch_contact *t = frame->active[i];
183 float u = (t->x - s->min_x) / (s->max_x - s->min_x);
184 float v = (t->y - s->min_y) / (s->max_y - s->min_y);
185 int x = impl->emin_x + u * (impl->emax_x - impl->emin_x);
186 int y = impl->emin_y + v * (impl->emax_y - impl->emin_y);
187 int d = abs(x - impl->pointer_x) + abs(y - impl->pointer_y);
188 if (best_d < 0 || d < best_d) {
189 best_x = x;
190 best_y = y;
191 best_d = d;
192 }
193 }
194 if (best_d >= 0) {
195 impl->pointer_x = best_x;
196 impl->pointer_y = best_y;
197 }
198}
199
200static void handle_abs_events(struct grail *ge, const struct input_event *syn)
201{
202 static const int fm_mask = 0x03;
203 struct grail_impl *impl = ge->impl;
204 struct gesture_inserter *gin = ge->gin;
205 struct gesture_recognizer *gru = ge->gru;
206 struct move_model *move = &gru->move;
207 struct tapping_model *tap = &gru->tapping;
208 int used_move = grail_mask_count(gin->types, sizeof(gin->types));
209 int used_tap = grail_mask_get(gin->types, GRAIL_TYPE_TAP1);
210 int pointer = move->ntouch == 1;
211 int ismove = pointer && (move->active & fm_mask) && !used_move;
212 int ishold = pointer && tap->active && !used_move;
213 int istap = gru->tapping.tap == 1 && !used_tap;
214
215 set_pointer(impl);
216 if (!impl->pointer_status && pointer) {
217 impl->report_x = impl->pointer_x;
218 impl->report_y = impl->pointer_y;
219 impl->report_time = syn->time;
220 impl->pointer_status = 1;
221 if (!used_move)
222 report_down(impl);
223 return;
224 }
225
226 if (ishold)
227 return;
228
229 if (istap) {
230 report_down(impl);
231 evput(impl, impl->report_time, EV_KEY, BTN_LEFT, 1);
232 evput(impl, impl->report_time, EV_SYN, SYN_REPORT, 0);
233 evput(impl, syn->time, EV_KEY, BTN_LEFT, 0);
234 } else if (ismove) {
235 report_down(impl);
236 if (impl->report_x != impl->pointer_x) {
237 evput(impl, syn->time, EV_ABS, ABS_X, impl->pointer_x);
238 impl->report_x = impl->pointer_x;
239 }
240 if (impl->report_y != impl->pointer_y) {
241 evput(impl, syn->time, EV_ABS, ABS_Y, impl->pointer_y);
242 impl->report_y = impl->pointer_y;
243 }
244 }
245 if (impl->pointer_status && !pointer) {
246 impl->pointer_status = 0;
247 report_up(impl, syn);
248 }
249}
250
251static void report_frame(struct grail *ge, 130static void report_frame(struct grail *ge,
252 const struct utouch_frame *frame, 131 const struct utouch_frame *frame,
253 const struct input_event *syn) 132 const struct input_event *syn)
254{ 133{
255 134
256 struct grail_impl *impl = ge->impl; 135 struct grail_impl *impl = ge->impl;
257 int head = impl->evbuf.head;
258 struct input_event iev; 136 struct input_event iev;
259 struct grail_event gev; 137 struct grail_event gev;
260 138
@@ -264,20 +142,19 @@ static void report_frame(struct grail *ge,
264 gru_recognize(ge, frame); 142 gru_recognize(ge, frame);
265 gin_frame_end(ge, frame); 143 gin_frame_end(ge, frame);
266 144
267 if (!impl->filter_abs) 145 if (grailbuf_empty(&impl->gbuf)) {
268 handle_abs_events(ge, syn); 146 while (!evbuf_empty(&impl->evbuf)) {
269 if (impl->evbuf.head != head) 147 evbuf_get(&impl->evbuf, &iev);
270 evbuf_put(&impl->evbuf, syn); 148 if (ge->event)
271 149 ge->event(ge, &iev);
272 while (!grailbuf_empty(&impl->gbuf)) { 150 }
273 grailbuf_get(&impl->gbuf, &gev); 151 } else {
274 if (ge->gesture) 152 while (!grailbuf_empty(&impl->gbuf)) {
275 ge->gesture(ge, &gev); 153 grailbuf_get(&impl->gbuf, &gev);
276 } 154 if (ge->gesture)
277 while (!evbuf_empty(&impl->evbuf)) { 155 ge->gesture(ge, &gev);
278 evbuf_get(&impl->evbuf, &iev); 156 }
279 if (ge->event) 157 evbuf_clear(&impl->evbuf);
280 ge->event(ge, &iev);
281 } 158 }
282} 159}
283 160
@@ -286,24 +163,12 @@ static void grail_pump_mtdev(struct grail *ge, const struct input_event *ev)
286 struct grail_impl *impl = ge->impl; 163 struct grail_impl *impl = ge->impl;
287 const struct utouch_frame *frame; 164 const struct utouch_frame *frame;
288 165
166 evbuf_put(&impl->evbuf, ev);
167
289 if (ev->type == EV_SYN || ev->type == EV_ABS) { 168 if (ev->type == EV_SYN || ev->type == EV_ABS) {
290 frame = utouch_frame_pump_mtdev(impl->fh, ev); 169 frame = utouch_frame_pump_mtdev(impl->fh, ev);
291 if (frame) 170 if (frame)
292 report_frame(ge, frame, ev); 171 report_frame(ge, frame, ev);
293 } else if (ev->type == EV_KEY) {
294 switch (ev->code) {
295 case BTN_TOUCH:
296 case BTN_TOOL_FINGER:
297 case BTN_TOOL_DOUBLETAP:
298 case BTN_TOOL_TRIPLETAP:
299 case BTN_TOOL_QUADTAP:
300 break;
301 default:
302 evbuf_put(&impl->evbuf, ev);
303 break;
304 }
305 } else {
306 evbuf_put(&impl->evbuf, ev);
307 } 172 }
308} 173}
309 174
diff --git a/src/grail-impl.h b/src/grail-impl.h
index dcbaedd..595f0fb 100644
--- a/src/grail-impl.h
+++ b/src/grail-impl.h
@@ -41,14 +41,7 @@ struct grail_impl {
41 const struct utouch_frame *frame; 41 const struct utouch_frame *frame;
42 struct evbuf evbuf; 42 struct evbuf evbuf;
43 struct grailbuf gbuf; 43 struct grailbuf gbuf;
44 float emin_x, emin_y;
45 float emax_x, emax_y;
46 int filter_abs; 44 int filter_abs;
47 int pointer_status;
48 int pointer_x, pointer_y;
49 int report_status;
50 int report_x, report_y;
51 struct timeval report_time;
52}; 45};
53 46
54#endif 47#endif