Merge lp:~oif-team/grail/trunk.whatversion into lp:grail

Proposed by Henrik Rydberg
Status: Superseded
Proposed branch: lp:~oif-team/grail/trunk.whatversion
Merge into: lp:grail
Diff against target: 2062 lines (+500/-952)
28 files modified
INSTALL (+2/-9)
Makefile.am (+1/-1)
configure.ac (+6/-2)
include/grail-touch.h (+0/-85)
src/Makefile.am (+5/-4)
src/gebuf.h (+2/-2)
src/gestures-drag.c (+3/-3)
src/gestures-pinch.c (+3/-3)
src/gestures-rotate.c (+3/-3)
src/gestures-tapping.c (+2/-2)
src/grail-api.c (+184/-145)
src/grail-event.c (+18/-18)
src/grail-gestures.c (+19/-19)
src/grail-gestures.h (+8/-8)
src/grail-impl.h (+16/-3)
src/grail-inserter.c (+13/-18)
src/grail-inserter.h (+7/-10)
src/grail-recognizer.c (+1/-2)
src/grail-recognizer.h (+1/-2)
src/grailbuf.h (+60/-0)
src/touch-caps.c (+0/-117)
src/touch-dev.c (+0/-264)
test/Makefile.am (+0/-9)
test/grail-gesture.c (+0/-126)
test/grail-touch.c (+0/-97)
tools/Makefile.am (+7/-0)
tools/grail-gesture.c (+126/-0)
utouch-grail.sym.in (+13/-0)
To merge this branch: bzr merge lp:~oif-team/grail/trunk.whatversion
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
Review via email: mp+44998@code.launchpad.net

This proposal has been superseded by a proposal from 2011-01-03.

Description of the change

Here is the first step in a series of transformations for grail. The major problem in this one is that the grail ABI is intact, but there are symbols in grail1 which never should have been exported: gin and gru. Also, the touch symbols were not really intended for public use. This patch series removes all gin/gru/touch symbols, and replaces the internal touch logic with utouch-frame. Removing symbols should normally warrant an ABI change. However, the grail usage in all our packages so far are intact. So what version to give this change?

To post a comment you must log in.
Revision history for this message
Stephen M. Webb (bregma) wrote :

An ABI-breaking change becomes obvious fairly quickly if it affects a developer. If someone is using the undocumented API and their stuff breaks, they can use the readelf tool to determine the symbols are missing and we can point them at the changelogs. Leaving the library version unaltered can save a lot of grief with the downstream Ubuntu people.

This merge builds OK after pulling in the latest unpackaged mtdev, evemu, and frame libraries and runs alright with geistest and the grail-gesture tool on maverick, so I'd give it a pass.

review: Approve
Revision history for this message
Chase Douglas (chasedouglas) wrote :

I don't have bandwidth to do a real code review on this :(. We're still in development phase, so if any issues come out we can fix them up.

I agree with Stephen in that the major API number should be left the same. As for the intricate details of so versioning, I think Stephen understands them better than I do, so I'll defer to him there too.

Revision history for this message
Henrik Rydberg (rydberg) wrote :

Ok great - I will repackage using 1.0.18 to start with, and 1.1 once the actual api changes are in place.

lp:~oif-team/grail/trunk.whatversion updated
107. By Henrik Rydberg

Bump to v1.0.18

The grail symbols are intact and abi compatible, whereas the remaining
symbols, which should not really be present, have all been
removed. Since the remaining symbols represent the actual official
API, this is not considered an ABI breakage.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'INSTALL'
2--- INSTALL 2010-08-05 20:48:38 +0000
3+++ INSTALL 2011-01-02 12:29:53 +0000
4@@ -1,19 +1,12 @@
5 grail - Gesture Recognition And Instantiation Library
6
7-To build, you need to have the autoconf, libtool and mtdev-dev packages
8-installed. Then, do
9+To build, you need to have the autoconf, libtool, mtdev-dev,
10+libutouch-evemu-dev and libutouch-frame packages installed. Then, do
11
12 ./autogen.sh
13 ./configure
14 make
15
16-To test the touch properties of an MT device at /dev/input/eventX, do
17-
18- sudo ./test/grail-touch /dev/input/eventX
19-
20-You should be able to see touch events in the terminal. After five
21-seconds of inactivity, the program exits.
22-
23 To test gestures, do
24
25 sudo ./test/grail-gesture 0xffffffff /dev/input/eventX
26
27=== modified file 'Makefile.am'
28--- Makefile.am 2010-08-12 15:55:30 +0000
29+++ Makefile.am 2011-01-02 12:29:53 +0000
30@@ -1,4 +1,4 @@
31-SUBDIRS = src test
32+SUBDIRS = src test tools
33
34 pkgconfigdir = $(libdir)/pkgconfig
35 pkgconfig_DATA = utouch-grail.pc
36
37=== modified file 'configure.ac'
38--- configure.ac 2010-11-17 16:29:52 +0000
39+++ configure.ac 2011-01-02 12:29:53 +0000
40@@ -1,7 +1,7 @@
41 # Initialize Autoconf
42 AC_PREREQ([2.60])
43 AC_INIT([Gesture Recognition And Instantiation Library],
44- [1.0.17],
45+ [1.0.18],
46 [],
47 [utouch-grail])
48 AC_CONFIG_SRCDIR([Makefile.am])
49@@ -22,10 +22,14 @@
50 AC_PROG_CC
51 AC_PROG_INSTALL
52
53-PKG_CHECK_MODULES([MTDEV], [mtdev >= 1.0])
54+PKG_CHECK_MODULES([MTDEV], [mtdev >= 1.1])
55+PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0])
56+PKG_CHECK_MODULES([FRAME], [utouch-frame >= 1.0])
57
58 AC_CONFIG_FILES([Makefile
59 src/Makefile
60+ tools/Makefile
61 test/Makefile
62+ utouch-grail.sym
63 utouch-grail.pc])
64 AC_OUTPUT
65
66=== removed file 'include/grail-touch.h'
67--- include/grail-touch.h 2010-09-10 12:00:27 +0000
68+++ include/grail-touch.h 1970-01-01 00:00:00 +0000
69@@ -1,85 +0,0 @@
70-/*****************************************************************************
71- *
72- * grail - Gesture Recognition And Instantiation Library
73- *
74- * Copyright (C) 2010 Canonical Ltd.
75- * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
76- *
77- * This program is free software: you can redistribute it and/or modify it
78- * under the terms of the GNU General Public License as published by the
79- * Free Software Foundation, either version 3 of the License, or (at your
80- * option) any later version.
81- *
82- * This program is distributed in the hope that it will be useful, but
83- * WITHOUT ANY WARRANTY; without even the implied warranty of
84- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
85- * General Public License for more details.
86- *
87- * You should have received a copy of the GNU General Public License along
88- * with this program. If not, see <http://www.gnu.org/licenses/>.
89- *
90- ****************************************************************************/
91-
92-#ifndef _GRAIL_TOUCH_H
93-#define _GRAIL_TOUCH_H
94-
95-#include <grail-bits.h>
96-#include <mtdev.h>
97-
98-#define DIM_TOUCH 32
99-#define DIM_TOUCH_BYTES ((DIM_TOUCH + 7) >> 3)
100-
101-typedef __u64 touch_time_t;
102-
103-struct touch {
104- int active;
105- int slot;
106- int id;
107- int tool_type;
108- int x, y;
109- int touch_major;
110- int touch_minor;
111- int width_major;
112- int width_minor;
113- int orientation;
114- int pressure;
115-};
116-
117-struct touch_frame {
118- int nactive;
119- int ncreate, nmodify, ndestroy;
120- touch_time_t time;
121- grail_mask_t touches[DIM_TOUCH_BYTES];
122- struct touch *active[DIM_TOUCH];
123- struct touch touch[DIM_TOUCH];
124-};
125-
126-struct touch_caps {
127- float min_x, max_x;
128- float min_y, max_y;
129- float min_orient, max_orient;
130- float min_press, max_press;
131-};
132-
133-struct touch_dev {
134- void (*event)(struct touch_dev *dev, const struct input_event *ev);
135- void (*sync)(struct touch_dev *dev, const struct input_event *syn);
136- void *priv;
137- struct mtdev mtdev;
138- struct touch_frame frame;
139- struct touch_caps caps;
140- int slot;
141- int state;
142-};
143-
144-int touch_caps_is_supported(struct touch_dev *dev, int fd);
145-void touch_caps_init(struct touch_dev *dev);
146-float touch_angle(const struct touch_dev *dev, int orientation);
147-float touch_pressure(const struct touch_dev *dev, int pressure);
148-
149-int touch_dev_open(struct touch_dev *dev, int fd);
150-int touch_dev_idle(struct touch_dev *dev, int fd, int ms);
151-int touch_dev_pull(struct touch_dev *dev, int fd);
152-void touch_dev_close(struct touch_dev *dev, int fd);
153-
154-#endif
155
156=== modified file 'src/Makefile.am'
157--- src/Makefile.am 2010-08-20 06:45:26 +0000
158+++ src/Makefile.am 2011-01-02 12:29:53 +0000
159@@ -2,14 +2,16 @@
160
161 libutouch_grail_la_LDFLAGS = \
162 -version-info @LIB_VERSION@ \
163+ -export-symbols ../utouch-grail.sym \
164 -lm \
165- $(MTDEV_LIBS)
166+ $(MTDEV_LIBS) \
167+ $(EVEMU_LIBS) \
168+ $(FRAME_LIBS)
169
170 libutouch_grail_la_SOURCES = \
171 evbuf.h \
172 gebuf.h \
173- touch-dev.c \
174- touch-caps.c \
175+ grailbuf.h \
176 grail-bits.c \
177 grail-inserter.c \
178 grail-inserter.h \
179@@ -33,5 +35,4 @@
180 libutouch_grailinclude_HEADERS = \
181 $(top_srcdir)/include/grail-bits.h \
182 $(top_srcdir)/include/grail-types.h \
183- $(top_srcdir)/include/grail-touch.h \
184 $(top_srcdir)/include/grail.h
185
186=== modified file 'src/gebuf.h'
187--- src/gebuf.h 2010-08-07 20:21:27 +0000
188+++ src/gebuf.h 2011-01-02 12:29:53 +0000
189@@ -23,7 +23,7 @@
190 #ifndef _GRAIL_GESTURE_BUFFER_H
191 #define _GRAIL_GESTURE_BUFFER_H
192
193-#include <grail.h>
194+#include "grail-impl.h"
195
196 #define DIM_GESTURE_EVENTS 512
197
198@@ -31,7 +31,7 @@
199 int status;
200 int ntouch;
201 int nprop;
202- touch_time_t time;
203+ utouch_frame_time_t time;
204 struct grail_coord pos;
205 grail_prop_t prop[DIM_GRAIL_PROP];
206 };
207
208=== modified file 'src/gestures-drag.c'
209--- src/gestures-drag.c 2010-08-26 14:39:58 +0000
210+++ src/gestures-drag.c 2011-01-02 12:29:53 +0000
211@@ -35,7 +35,7 @@
212
213 static void set_props(const struct gesture_inserter *gin,
214 struct combo_model *s, const struct move_model *m,
215- const struct touch_frame *frame)
216+ const struct utouch_frame *frame)
217 {
218 if (m->single) {
219 s->prop[GRAIL_PROP_DRAG_DX] =
220@@ -59,7 +59,7 @@
221 static const int fm_mask = 0x03;
222
223 int gru_drag(struct grail *ge,
224- const struct touch_frame *frame)
225+ const struct utouch_frame *frame)
226 {
227 struct gesture_recognizer *gru = ge->gru;
228 struct combo_model *state = &gru->drag;
229@@ -89,7 +89,7 @@
230 }
231
232 int gru_windrag(struct grail *ge,
233- const struct touch_frame *frame)
234+ const struct utouch_frame *frame)
235 {
236 struct gesture_recognizer *gru = ge->gru;
237 struct combo_model *state = &gru->windrag;
238
239=== modified file 'src/gestures-pinch.c'
240--- src/gestures-pinch.c 2010-08-19 20:36:11 +0000
241+++ src/gestures-pinch.c 2011-01-02 12:29:53 +0000
242@@ -38,7 +38,7 @@
243 static void set_props(const struct gesture_inserter *gin,
244 struct combo_model *s,
245 const struct move_model *m,
246- const struct touch_frame *frame)
247+ const struct utouch_frame *frame)
248 {
249 s->prop[GRAIL_PROP_PINCH_DR] = gin->scale_r * m->fm[FM_R].action_delta;
250 s->prop[GRAIL_PROP_PINCH_VR] = gin->scale_r * m->fm[FM_R].velocity;
251@@ -48,7 +48,7 @@
252 }
253
254 int gru_pinch(struct grail *ge,
255- const struct touch_frame *frame)
256+ const struct utouch_frame *frame)
257 {
258 struct gesture_recognizer *gru = ge->gru;
259 struct combo_model *state = &gru->pinch;
260@@ -79,7 +79,7 @@
261 }
262
263 int gru_winpinch(struct grail *ge,
264- const struct touch_frame *frame)
265+ const struct utouch_frame *frame)
266 {
267 struct gesture_recognizer *gru = ge->gru;
268 struct combo_model *state = &gru->winpinch;
269
270=== modified file 'src/gestures-rotate.c'
271--- src/gestures-rotate.c 2010-08-19 20:36:11 +0000
272+++ src/gestures-rotate.c 2011-01-02 12:29:53 +0000
273@@ -37,7 +37,7 @@
274
275 static void set_props(const struct gesture_inserter *gin,
276 struct combo_model *s, const struct move_model *m,
277- const struct touch_frame *frame)
278+ const struct utouch_frame *frame)
279 {
280 s->prop[GRAIL_PROP_ROTATE_DA] = m->fm[FM_A].action_delta;
281 s->prop[GRAIL_PROP_ROTATE_VA] = m->fm[FM_A].velocity;
282@@ -47,7 +47,7 @@
283 }
284
285 int gru_rotate(struct grail *ge,
286- const struct touch_frame *frame)
287+ const struct utouch_frame *frame)
288 {
289 struct gesture_recognizer *gru = ge->gru;
290 struct combo_model *state = &gru->rotate;
291@@ -78,7 +78,7 @@
292 }
293
294 int gru_winrotate(struct grail *ge,
295- const struct touch_frame *frame)
296+ const struct utouch_frame *frame)
297 {
298 struct gesture_recognizer *gru = ge->gru;
299 struct combo_model *state = &gru->winrotate;
300
301=== modified file 'src/gestures-tapping.c'
302--- src/gestures-tapping.c 2010-09-21 11:26:43 +0000
303+++ src/gestures-tapping.c 2011-01-02 12:29:53 +0000
304@@ -30,7 +30,7 @@
305
306 static void set_props(const struct gesture_inserter *gin,
307 struct tapping_model *s, const struct move_model *m,
308- const struct touch_frame *frame)
309+ const struct utouch_frame *frame)
310 {
311 s->prop[GRAIL_PROP_TAP_DT] = m->time - s->start;
312 s->prop[GRAIL_PROP_TAP_X] = gin_prop_x(gin, m->fm[FM_X].value);
313@@ -40,7 +40,7 @@
314 }
315
316 int gru_tapping(struct grail *ge,
317- const struct touch_frame *frame)
318+ const struct utouch_frame *frame)
319 {
320 struct gesture_recognizer *gru = ge->gru;
321 struct tapping_model *state = &gru->tapping;
322
323=== modified file 'src/grail-api.c'
324--- src/grail-api.c 2010-11-17 16:29:28 +0000
325+++ src/grail-api.c 2011-01-02 12:29:53 +0000
326@@ -30,26 +30,123 @@
327 #include <malloc.h>
328 #include <errno.h>
329
330-static void tp_event(struct touch_dev *dev,
331- const struct input_event *ev)
332-{
333- struct grail *ge = dev->priv;
334- struct grail_impl *x = ge->impl;
335- if (ev->type == EV_ABS) {
336- return;
337- }
338- if (ev->type == EV_KEY) {
339- switch (ev->code) {
340- case BTN_TOUCH:
341- case BTN_TOOL_FINGER:
342- case BTN_TOOL_DOUBLETAP:
343- case BTN_TOOL_TRIPLETAP:
344- case BTN_TOOL_QUADTAP:
345- return;
346- }
347- }
348- evbuf_put(&x->evbuf, ev);
349-}
350+#define DIM_FRAMES 100
351+#define FRAME_RATE 100
352+
353+void grail_filter_abs_events(struct grail *ge, int usage)
354+{
355+ struct grail_impl *x = ge->impl;
356+ x->filter_abs = usage;
357+}
358+
359+static void init_impl(struct grail_impl *x)
360+{
361+ int i;
362+
363+ if (evemu_has_event(x->evemu, EV_ABS, ABS_X)) {
364+ x->emin_x = evemu_get_abs_minimum(x->evemu, ABS_X);
365+ x->emin_y = evemu_get_abs_minimum(x->evemu, ABS_Y);
366+ x->emax_x = evemu_get_abs_maximum(x->evemu, ABS_X);
367+ x->emax_y = evemu_get_abs_maximum(x->evemu, ABS_Y);
368+ } else {
369+ struct utouch_surface *s = utouch_frame_get_surface(x->fh);
370+ x->emin_x = s->min_x;
371+ x->emin_y = s->min_y;
372+ x->emax_x = s->max_x;
373+ x->emax_y = s->max_y;
374+ }
375+}
376+
377+int grail_open(struct grail *ge, int fd)
378+{
379+ struct grail_impl *x;
380+ int ret;
381+ x = calloc(1, sizeof(*x));
382+ if (!x)
383+ return -ENOMEM;
384+
385+ x->evemu = evemu_new(0);
386+ if (!x->evemu) {
387+ ret = -ENOMEM;
388+ goto freemem;
389+ }
390+ ret = evemu_extract(x->evemu, fd);
391+ if (ret)
392+ goto freemem;
393+ if (!utouch_frame_is_supported_mtdev(x->evemu)) {
394+ ret = -ENODEV;
395+ goto freemem;
396+ }
397+ x->mtdev = mtdev_new_open(fd);
398+ if (!x->mtdev) {
399+ ret = -ENOMEM;
400+ goto freemem;
401+ }
402+
403+ x->fh = utouch_frame_new_engine(DIM_FRAMES, DIM_TOUCH, FRAME_RATE);
404+ if (!x->fh) {
405+ ret = -ENOMEM;
406+ goto freedev;
407+ }
408+ ret = utouch_frame_init_mtdev(x->fh, x->evemu);
409+ if (ret)
410+ goto freeframe;
411+
412+ init_impl(x);
413+ ge->impl = x;
414+
415+ ret = gin_init(ge);
416+ if (ret)
417+ goto freeframe;
418+
419+ ret = gru_init(ge);
420+ if (ret)
421+ goto freegin;
422+
423+ return 0;
424+ freegin:
425+ gin_destroy(ge);
426+ freeframe:
427+ utouch_frame_delete_engine(x->fh);
428+ freedev:
429+ mtdev_close_delete(x->mtdev);
430+ freemem:
431+ evemu_delete(x->evemu);
432+ free(x);
433+ ge->impl = 0;
434+ return ret;
435+}
436+
437+void grail_close(struct grail *ge, int fd)
438+{
439+ struct grail_impl *x = ge->impl;
440+ void *status;
441+ gru_destroy(ge);
442+ gin_destroy(ge);
443+ utouch_frame_delete_engine(x->fh);
444+ mtdev_close_delete(x->mtdev);
445+ evemu_delete(x->evemu);
446+ free(x);
447+ ge->impl = 0;
448+}
449+
450+int grail_idle(struct grail *ge, int fd, int ms)
451+{
452+ struct grail_impl *x = ge->impl;
453+ return mtdev_idle(x->mtdev, fd, ms);
454+}
455+
456+void grail_get_units(const struct grail *ge,
457+ struct grail_coord *min, struct grail_coord *max)
458+{
459+ struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh);
460+ min->x = s->min_x;
461+ min->y = s->min_y;
462+ max->x = s->max_x;
463+ max->y = s->max_y;
464+}
465+
466+// legacy glue below
467
468 static void evput(struct grail_impl *x, struct timeval time,
469 unsigned type, unsigned code, int value)
470@@ -76,47 +173,19 @@
471 impl->report_status = 0;
472 }
473
474-#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
475-
476-static int getabs(struct input_absinfo *abs, int key, int fd)
477-{
478- int rc;
479- SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs));
480- return rc >= 0;
481-}
482-
483-static void set_emulation_caps(struct grail_impl *impl, int fd)
484-{
485- struct touch_caps *emu = &impl->emu;
486- struct input_absinfo info;
487-
488- memset(emu, 0, sizeof(*emu));
489-
490- if (getabs(&info, ABS_X, fd)) {
491- emu->min_x = info.minimum;
492- emu->max_x = info.maximum;
493- }
494- if (getabs(&info, ABS_Y, fd)) {
495- emu->min_y = info.minimum;
496- emu->max_y = info.maximum;
497- }
498-}
499-
500 static void set_pointer(struct grail_impl *impl)
501 {
502- struct touch_dev *dev = &impl->dev;
503- struct touch_caps *caps = &dev->caps;
504- struct touch_caps *emu = &impl->emu;
505- struct touch_frame *frame = &dev->frame;
506+ struct utouch_surface *s = utouch_frame_get_surface(impl->fh);
507+ const struct utouch_frame *frame = impl->frame;
508 int best_x, best_y, best_d = -1;
509 int i;
510
511- for (i = 0; i < frame->nactive; i++) {
512- struct touch *t = frame->active[i];
513- float u = (t->x - caps->min_x) / (caps->max_x - caps->min_x);
514- float v = (t->y - caps->min_y) / (caps->max_y - caps->min_y);
515- int x = emu->min_x + u * (emu->max_x - emu->min_x);
516- int y = emu->min_y + v * (emu->max_y - emu->min_y);
517+ for (i = 0; i < frame->num_active; i++) {
518+ const struct utouch_contact *t = frame->active[i];
519+ float u = (t->x - s->min_x) / (s->max_x - s->min_x);
520+ float v = (t->y - s->min_y) / (s->max_y - s->min_y);
521+ int x = impl->emin_x + u * (impl->emax_x - impl->emin_x);
522+ int y = impl->emin_y + v * (impl->emax_y - impl->emin_y);
523 int d = abs(x - impl->pointer_x) + abs(y - impl->pointer_y);
524 if (best_d < 0 || d < best_d) {
525 best_x = x;
526@@ -181,105 +250,75 @@
527 }
528 }
529
530-static void tp_sync(struct touch_dev *dev,
531- const struct input_event *syn)
532+static void report_frame(struct grail *ge,
533+ const struct utouch_frame *frame,
534+ const struct input_event *syn)
535 {
536- struct input_event ev;
537- struct grail *ge = dev->priv;
538+
539 struct grail_impl *impl = ge->impl;
540- struct touch_frame *frame = &dev->frame;
541- int nevent = 0;
542+ int head = impl->evbuf.head;
543+ struct input_event iev;
544+ struct grail_event gev;
545+
546+ ge->impl->frame = frame;
547+
548 gin_frame_begin(ge, frame);
549 gru_recognize(ge, frame);
550 gin_frame_end(ge, frame);
551
552- if (!ge->event) {
553- evbuf_clear(&impl->evbuf);
554- return;
555- }
556 if (!impl->filter_abs)
557 handle_abs_events(ge, syn);
558+ if (impl->evbuf.head != head)
559+ evbuf_put(&impl->evbuf, syn);
560+
561+ while (!grailbuf_empty(&impl->gbuf)) {
562+ grailbuf_get(&impl->gbuf, &gev);
563+ if (ge->gesture)
564+ ge->gesture(ge, &gev);
565+ }
566 while (!evbuf_empty(&impl->evbuf)) {
567- evbuf_get(&impl->evbuf, &ev);
568- ge->event(ge, &ev);
569- nevent++;
570- }
571- if (nevent)
572- ge->event(ge, syn);
573-}
574-
575-void grail_filter_abs_events(struct grail *ge, int usage)
576-{
577- struct grail_impl *x = ge->impl;
578- x->filter_abs = usage;
579-}
580-
581-int grail_open(struct grail *ge, int fd)
582-{
583- struct grail_impl *x;
584- int ret;
585- x = calloc(1, sizeof(*x));
586- if (!x)
587- return -ENOMEM;
588- ge->impl = x;
589-
590- ret = touch_dev_open(&x->dev, fd);
591- if (ret)
592- goto freemem;
593- set_emulation_caps(x, fd);
594- x->dev.event = tp_event;
595- x->dev.sync = tp_sync;
596- x->dev.priv = ge;
597-
598- ret = gin_init(ge);
599- if (ret)
600- goto freedev;
601-
602- ret = gru_init(ge);
603- if (ret)
604- goto freegin;
605-
606- return 0;
607- freegin:
608- gin_destroy(ge);
609- freedev:
610- touch_dev_close(&x->dev, fd);
611- freemem:
612- free(x);
613- ge->impl = 0;
614- return ret;
615-}
616-
617-void grail_close(struct grail *ge, int fd)
618-{
619- struct grail_impl *x = ge->impl;
620- void *status;
621- gru_destroy(ge);
622- gin_destroy(ge);
623- touch_dev_close(&x->dev, fd);
624- free(ge->impl);
625- ge->impl = 0;
626-}
627-
628-int grail_idle(struct grail *ge, int fd, int ms)
629-{
630- struct grail_impl *x = ge->impl;
631- return touch_dev_idle(&x->dev, fd, ms);
632+ evbuf_get(&impl->evbuf, &iev);
633+ if (ge->event)
634+ ge->event(ge, &iev);
635+ }
636+}
637+
638+static void grail_pump_mtdev(struct grail *ge, const struct input_event *ev)
639+{
640+ struct grail_impl *impl = ge->impl;
641+ const struct utouch_frame *frame;
642+
643+ if (ev->type == EV_SYN || ev->type == EV_ABS) {
644+ frame = utouch_frame_pump_mtdev(impl->fh, ev);
645+ if (frame)
646+ report_frame(ge, frame, ev);
647+ } else if (ev->type == EV_KEY) {
648+ switch (ev->code) {
649+ case BTN_TOUCH:
650+ case BTN_TOOL_FINGER:
651+ case BTN_TOOL_DOUBLETAP:
652+ case BTN_TOOL_TRIPLETAP:
653+ case BTN_TOOL_QUADTAP:
654+ break;
655+ default:
656+ evbuf_put(&impl->evbuf, ev);
657+ break;
658+ }
659+ } else {
660+ evbuf_put(&impl->evbuf, ev);
661+ }
662 }
663
664 int grail_pull(struct grail *ge, int fd)
665 {
666- struct grail_impl *x = ge->impl;
667- return touch_dev_pull(&x->dev, fd);
668-}
669-
670-void grail_get_units(const struct grail *ge,
671- struct grail_coord *min, struct grail_coord *max)
672-{
673- const struct touch_caps *caps = &ge->impl->dev.caps;
674- min->x = caps->min_x;
675- min->y = caps->min_y;
676- max->x = caps->max_x;
677- max->y = caps->max_y;
678-}
679-
680+ struct grail_impl *impl = ge->impl;
681+ struct input_event ev;
682+ int ret, count = 0;
683+
684+ while ((ret = mtdev_get(impl->mtdev, fd, &ev, 1)) > 0) {
685+ grail_pump_mtdev(ge, &ev);
686+ count++;
687+ }
688+
689+ return count > 0 ? count : ret;
690+}
691
692=== modified file 'src/grail-event.c'
693--- src/grail-event.c 2010-08-19 20:36:11 +0000
694+++ src/grail-event.c 2011-01-02 12:29:53 +0000
695@@ -28,17 +28,17 @@
696 #include <math.h>
697
698 static void compute_bbox(struct grail_coord *min, struct grail_coord *max,
699- const struct touch_frame *frame)
700+ const struct utouch_frame *frame)
701 {
702 float x, y;
703 int i;
704- if (frame->nactive < 1)
705+ if (frame->num_active < 1)
706 return;
707 x = frame->active[0]->x;
708 y = frame->active[0]->y;
709 min->x = max->x = x;
710 min->y = max->y = y;
711- for (i = 1; i < frame->nactive; i++) {
712+ for (i = 1; i < frame->num_active; i++) {
713 x = frame->active[i]->x;
714 y = frame->active[i]->y;
715 if (x < min->x)
716@@ -53,10 +53,10 @@
717 }
718
719 int gin_add_contact_props(const struct gesture_inserter *gin,
720- grail_prop_t *prop, const struct touch_frame *frame)
721+ grail_prop_t *prop, const struct utouch_frame *frame)
722 {
723 struct grail_coord min, max;
724- int i, n = 0, ntouch = frame->nactive;
725+ int i, n = 0, ntouch = frame->num_active;
726 if (!ntouch)
727 return n;
728 if (ntouch > 5)
729@@ -67,7 +67,7 @@
730 prop[n++] = gin_prop_x(gin, max.x);
731 prop[n++] = gin_prop_y(gin, max.y);
732 for (i = 0; i < ntouch; i++) {
733- const struct touch *ct = frame->active[i];
734+ const struct utouch_contact *ct = frame->active[i];
735 prop[n++] = ct->id;
736 prop[n++] = gin_prop_x(gin, ct->x);
737 prop[n++] = gin_prop_y(gin, ct->y);
738@@ -79,15 +79,15 @@
739 struct grail_client_info *info, int maxinfo,
740 const grail_mask_t* types, int btypes,
741 const grail_mask_t* span, int bspan,
742- const struct touch_frame *frame)
743+ const struct utouch_frame *frame)
744 {
745 struct grail_coord pos[DIM_TOUCH];
746 int i, npos = 0;
747 if (!ge->get_clients)
748 return 0;
749 grail_mask_foreach(i, span, bspan) {
750- pos[npos].x = gin_prop_x(ge->gin, frame->touch[i].x);
751- pos[npos].y = gin_prop_y(ge->gin, frame->touch[i].y);
752+ pos[npos].x = gin_prop_x(ge->gin, frame->slots[i]->x);
753+ pos[npos].y = gin_prop_y(ge->gin, frame->slots[i]->y);
754 npos++;
755 }
756 return ge->get_clients(ge, info, maxinfo, pos, npos, types, btypes);
757@@ -95,8 +95,9 @@
758
759 void gin_send_event(struct grail *ge, struct slot_state *s,
760 const struct gesture_event *ev,
761- const struct touch_frame *frame)
762+ const struct utouch_frame *frame)
763 {
764+ struct grail_impl *impl = ge->impl;
765 const struct gesture_inserter *gin = ge->gin;
766 struct grail_event gev;
767 int i;
768@@ -113,22 +114,21 @@
769 memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t));
770 for (i = 0; i < s->nclient; i++) {
771 gev.client_id = s->client_id[i];
772- ge->gesture(ge, &gev);
773+ grailbuf_put(&impl->gbuf, &gev);
774 }
775 }
776
777 int grail_get_contacts(const struct grail *ge,
778 struct grail_contact *touch, int max_touch)
779 {
780- const struct touch_dev *dev = &ge->impl->dev;
781 const struct gesture_inserter *gin = ge->gin;
782- const struct touch_frame *frame = &dev->frame;
783+ const struct utouch_frame *frame = ge->impl->frame;
784 int i;
785- if (frame->nactive < max_touch)
786- max_touch = frame->nactive;
787+ if (frame->num_active < max_touch)
788+ max_touch = frame->num_active;
789 for (i = 0; i < max_touch; i++) {
790 struct grail_contact *t = &touch[i];
791- const struct touch *ct = frame->active[i];
792+ const struct utouch_contact *ct = frame->active[i];
793 t->id = ct->id;
794 t->tool_type = ct->tool_type;
795 t->pos.x = gin_prop_x(gin, ct->x);
796@@ -137,8 +137,8 @@
797 t->touch_minor = gin->scale_r * ct->touch_minor;
798 t->width_major = gin->scale_r * ct->width_major;
799 t->width_minor = gin->scale_r * ct->width_minor;
800- t->angle = touch_angle(dev, ct->orientation);
801- t->pressure = touch_pressure(dev, ct->pressure);
802+ t->angle = ct->orientation;
803+ t->pressure = ct->pressure;
804 }
805 return max_touch;
806 }
807
808=== modified file 'src/grail-gestures.c'
809--- src/grail-gestures.c 2010-09-10 12:09:48 +0000
810+++ src/grail-gestures.c 2011-01-02 12:29:53 +0000
811@@ -31,15 +31,15 @@
812 static const float EPS = 1e-3;
813
814 static void compute_position(float *x, float *y,
815- const struct touch_frame *frame)
816+ const struct utouch_frame *frame)
817 {
818- int i, n = frame->nactive;
819+ int i, n = frame->num_active;
820 *x = 0;
821 *y = 0;
822 if (n < 1)
823 return;
824 for (i = 0; i < n; i++) {
825- const struct touch *t = frame->active[i];
826+ const struct utouch_contact *t = frame->active[i];
827 *x += t->x;
828 *y += t->y;
829 }
830@@ -48,14 +48,14 @@
831 }
832
833 static float compute_radius(float x, float y,
834- const struct touch_frame *frame)
835+ const struct utouch_frame *frame)
836 {
837- int i, n = frame->nactive;
838+ int i, n = frame->num_active;
839 float r = 0, r2 = 0;
840 if (n < 2)
841 return r;
842 for (i = 0; i < n; i++) {
843- const struct touch *t = frame->active[i];
844+ const struct utouch_contact *t = frame->active[i];
845 float dx = t->x - x;
846 float dy = t->y - y;
847 r2 += dx * dx + dy * dy;
848@@ -66,16 +66,15 @@
849 }
850
851 static float compute_rotation(float x, float y, float r,
852- const struct touch_frame *prev,
853- const struct touch_frame *frame)
854+ const struct utouch_frame *frame)
855 {
856- int i, n = frame->nactive;
857+ int i, n = frame->num_active;
858 float da = 0, darc2 = 0;
859 if (n < 2)
860 return da;
861 for (i = 0; i < n; i++) {
862- const struct touch *t = frame->active[i];
863- const struct touch *ot = &prev->touch[t->slot];
864+ const struct utouch_contact *t = frame->active[i];
865+ const struct utouch_contact *ot = t->prev;
866 float dx = t->x - x;
867 float dy = t->y - y;
868 float mx = t->x - ot->x;
869@@ -142,13 +141,13 @@
870
871 void gru_init_motion(struct grail *ge)
872 {
873- struct touch_caps *caps = &ge->impl->dev.caps;
874+ struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh);
875 struct gesture_recognizer *gru = ge->gru;
876 struct move_model *m = &gru->move;
877 float D[DIM_FM];
878 int i;
879- D[FM_X] = caps->max_x - caps->min_x;
880- D[FM_Y] = caps->max_y - caps->min_y;
881+ D[FM_X] = s->max_x - s->min_x;
882+ D[FM_Y] = s->max_y - s->min_y;
883 D[FM_R] = sqrt(D[FM_X] * D[FM_X] + D[FM_Y] * D[FM_Y]);
884 D[FM_A] = 2 * M_PI;
885 for (i = 0; i < DIM_FM; i++) {
886@@ -159,14 +158,15 @@
887 }
888
889 void gru_motion(struct grail *ge,
890- const struct touch_frame *frame)
891+ const struct utouch_frame *frame)
892 {
893 struct gesture_recognizer *gru = ge->gru;
894 struct move_model *m = &gru->move;
895 grail_time_t t = frame->time;
896 float x, y, r, a;
897+
898 compute_position(&x, &y, frame);
899- if (frame->ncreate || frame->ndestroy) {
900+ if (frame->prev->revision != frame->revision) {
901 r = compute_radius(x, y, frame);
902 a = 0;
903 move_reset(m, FM_X, x, t);
904@@ -175,7 +175,7 @@
905 move_reset(m, FM_A, a, t);
906 m->single = 0;
907 m->multi = 0;
908- } else if (frame->nactive < 2) {
909+ } else if (frame->num_active < 2) {
910 r = 0;
911 a = 0;
912 move_update(m, FM_X, x, t);
913@@ -190,7 +190,7 @@
914 r = compute_radius(x, y, frame);
915 r = move_filter(&m->fm[FM_R], r);
916 a = m->fm[FM_A].value;
917- a += compute_rotation(x, y, r, &gru->frame, frame);
918+ a += compute_rotation(x, y, r, frame);
919 a = move_filter(&m->fm[FM_A], a);
920 move_update(m, FM_X, x, t);
921 move_update(m, FM_Y, y, t);
922@@ -199,7 +199,7 @@
923 m->single = 0;
924 m->multi = 1;
925 }
926- m->ntouch = frame->nactive;
927+ m->ntouch = frame->num_active;
928 m->time = t;
929 }
930
931
932=== modified file 'src/grail-gestures.h'
933--- src/grail-gestures.h 2010-09-21 11:26:43 +0000
934+++ src/grail-gestures.h 2011-01-02 12:29:53 +0000
935@@ -61,7 +61,7 @@
936
937 void gru_init_motion(struct grail *ge);
938 void gru_motion(struct grail *ge,
939- const struct touch_frame *frame);
940+ const struct utouch_frame *frame);
941 void gru_event(struct grail *ge, int gid,
942 const struct move_model *move,
943 const grail_prop_t *prop, int nprop);
944@@ -77,11 +77,11 @@
945 };
946
947 int gru_drag(struct grail *ge,
948- const struct touch_frame *frame);
949+ const struct utouch_frame *frame);
950 int gru_pinch(struct grail *ge,
951- const struct touch_frame *frame);
952+ const struct utouch_frame *frame);
953 int gru_rotate(struct grail *ge,
954- const struct touch_frame *frame);
955+ const struct utouch_frame *frame);
956
957 static inline int out_of_bounds(const struct combo_model *s,
958 const struct move_model *m)
959@@ -90,11 +90,11 @@
960 }
961
962 int gru_windrag(struct grail *ge,
963- const struct touch_frame *frame);
964+ const struct utouch_frame *frame);
965 int gru_winpinch(struct grail *ge,
966- const struct touch_frame *frame);
967+ const struct utouch_frame *frame);
968 int gru_winrotate(struct grail *ge,
969- const struct touch_frame *frame);
970+ const struct utouch_frame *frame);
971
972 struct tapping_model {
973 grail_time_t start, end;
974@@ -105,7 +105,7 @@
975 };
976
977 int gru_tapping(struct grail *ge,
978- const struct touch_frame *frame);
979+ const struct utouch_frame *frame);
980
981 #endif
982
983
984=== modified file 'src/grail-impl.h'
985--- src/grail-impl.h 2010-11-17 16:29:28 +0000
986+++ src/grail-impl.h 2011-01-02 12:29:53 +0000
987@@ -23,13 +23,26 @@
988 #ifndef _GRAIL_IMPL_H
989 #define _GRAIL_IMPL_H
990
991-#include <grail-touch.h>
992+#define MTDEV_NO_LEGACY_API
993+#define GRAIL_NO_LEGACY_API
994+
995+#include <grail.h>
996+#include <utouch/frame-mtdev.h>
997 #include "evbuf.h"
998+#include "grailbuf.h"
999+
1000+#define DIM_TOUCH 32
1001+#define DIM_TOUCH_BYTES ((DIM_TOUCH + 7) >> 3)
1002
1003 struct grail_impl {
1004- struct touch_dev dev;
1005- struct touch_caps emu;
1006+ struct evemu_device *evemu;
1007+ struct mtdev *mtdev;
1008+ utouch_frame_handle fh;
1009+ const struct utouch_frame *frame;
1010 struct evbuf evbuf;
1011+ struct grailbuf gbuf;
1012+ float emin_x, emin_y;
1013+ float emax_x, emax_y;
1014 int filter_abs;
1015 int pointer_status;
1016 int pointer_x, pointer_y;
1017
1018=== modified file 'src/grail-inserter.c'
1019--- src/grail-inserter.c 2010-09-21 11:23:35 +0000
1020+++ src/grail-inserter.c 2011-01-02 12:29:53 +0000
1021@@ -40,7 +40,7 @@
1022
1023 // todo: spanning tree for multi-user case
1024 static void setup_new_gestures(struct grail *ge,
1025- const struct touch_frame *frame)
1026+ const struct utouch_frame *frame)
1027 {
1028 struct gesture_inserter *gin = ge->gin;
1029 grail_mask_t types[DIM_GRAIL_TYPE_BYTES];
1030@@ -100,14 +100,14 @@
1031 ge->gin = NULL;
1032 }
1033
1034-void gin_frame_begin(struct grail *ge, const struct touch_frame *frame)
1035+void gin_frame_begin(struct grail *ge, const struct utouch_frame *frame)
1036 {
1037 struct gesture_inserter *gin = ge->gin;
1038 memset(gin->types, 0, sizeof(gin->types));
1039 gin->time = frame->time;
1040 }
1041
1042-void gin_frame_end(struct grail *ge, const struct touch_frame *frame)
1043+void gin_frame_end(struct grail *ge, const struct utouch_frame *frame)
1044 {
1045 struct gesture_inserter *gin = ge->gin;
1046 int i, hold = 0, discard = 0;
1047@@ -151,11 +151,12 @@
1048 }
1049 }
1050
1051-int gin_gid_begin_select(struct grail *ge, int type, int priority,
1052- const grail_mask_t *span, int nspan)
1053+int gin_gid_begin(struct grail *ge, int type, int priority,
1054+ const struct utouch_frame *frame)
1055 {
1056 struct gesture_inserter *gin = ge->gin;
1057 struct slot_state *s;
1058+ int slot;
1059 int i = grail_mask_get_first(gin->unused, sizeof(gin->unused));
1060 if (i < 0)
1061 return -1;
1062@@ -165,7 +166,8 @@
1063 s->id = gin->gestureid++ & MAX_GESTURE_ID;
1064 s->status = GRAIL_STATUS_BEGIN;
1065 s->nclient = 0;
1066- memcpy(s->span, span, nspan);
1067+ for (slot = 0; slot < DIM_TOUCH; slot++)
1068+ grail_mask_modify(s->span, slot, frame->slots[slot]->active);
1069 gebuf_clear(&s->buf);
1070 grail_mask_clear(gin->unused, i);
1071 grail_mask_set(gin->fresh, i);
1072@@ -173,13 +175,6 @@
1073 return s->id;
1074 }
1075
1076-int gin_gid_begin(struct grail *ge, int type, int priority,
1077- const struct touch_frame *frame)
1078-{
1079- return gin_gid_begin_select(ge, type, priority,
1080- frame->touches, sizeof(frame->touches));
1081-}
1082-
1083 void gin_gid_discard(struct grail *ge, int gid)
1084 {
1085 struct gesture_inserter *gin = ge->gin;
1086@@ -248,18 +243,18 @@
1087 const struct grail_coord *tmin,
1088 const struct grail_coord *tmax)
1089 {
1090- struct touch_caps *caps = &ge->impl->dev.caps;
1091+ struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh);
1092 struct gesture_inserter *gin = ge->gin;
1093 double tx, ty, dx, dy, sx, sy;
1094 tx = tmax->x - tmin->x;
1095 ty = tmax->y - tmin->y;
1096- dx = caps->max_x - caps->min_x;
1097- dy = caps->max_y - caps->min_y;
1098+ dx = s->max_x - s->min_x;
1099+ dy = s->max_y - s->min_y;
1100 sx = tx / dx;
1101 sy = ty / dy;
1102 gin->scale_x = sx;
1103 gin->scale_y = sy;
1104 gin->scale_r = sqrt((tx * tx + ty * ty) / (dx * dx + dy * dy));
1105- gin->trans_x = tmin->x - caps->min_x * sx;
1106- gin->trans_y = tmin->y - caps->min_y * sy;
1107+ gin->trans_x = tmin->x - s->min_x * sx;
1108+ gin->trans_y = tmin->y - s->min_y * sy;
1109 }
1110
1111=== modified file 'src/grail-inserter.h'
1112--- src/grail-inserter.h 2010-09-21 11:23:35 +0000
1113+++ src/grail-inserter.h 2011-01-02 12:29:53 +0000
1114@@ -23,8 +23,7 @@
1115 #ifndef _GRAIL_INSERTER_H
1116 #define _GRAIL_INSERTER_H
1117
1118-#include <grail-touch.h>
1119-#include <grail.h>
1120+#include "grail-impl.h"
1121 #include "gebuf.h"
1122
1123 #define DIM_EV_TYPE EV_CNT
1124@@ -69,27 +68,25 @@
1125 }
1126
1127 int gin_add_contact_props(const struct gesture_inserter *gin,
1128- grail_prop_t *prop, const struct touch_frame *frame);
1129+ grail_prop_t *prop, const struct utouch_frame *frame);
1130
1131 int gin_get_clients(struct grail *ge,
1132 struct grail_client_info *info, int maxinfo,
1133 const grail_mask_t* types, int btypes,
1134 const grail_mask_t* span, int bspan,
1135- const struct touch_frame *frame);
1136+ const struct utouch_frame *frame);
1137 void gin_send_event(struct grail *ge, struct slot_state *s,
1138 const struct gesture_event *ev,
1139- const struct touch_frame *frame);
1140+ const struct utouch_frame *frame);
1141
1142 int gin_init(struct grail *ge);
1143 void gin_destroy(struct grail *ge);
1144
1145-void gin_frame_begin(struct grail *ge, const struct touch_frame *frame);
1146-void gin_frame_end(struct grail *ge, const struct touch_frame *frame);
1147+void gin_frame_begin(struct grail *ge, const struct utouch_frame *frame);
1148+void gin_frame_end(struct grail *ge, const struct utouch_frame *frame);
1149
1150-int gin_gid_begin_select(struct grail *ge, int type, int priority,
1151- const grail_mask_t *span, int nspan);
1152 int gin_gid_begin(struct grail *ge, int type, int priority,
1153- const struct touch_frame *frame);
1154+ const struct utouch_frame *frame);
1155 void gin_gid_discard(struct grail *ge, int gid);
1156
1157 void gin_gid_event(struct grail *ge, int gid,
1158
1159=== modified file 'src/grail-recognizer.c'
1160--- src/grail-recognizer.c 2010-08-11 17:04:45 +0000
1161+++ src/grail-recognizer.c 2011-01-02 12:29:53 +0000
1162@@ -42,7 +42,7 @@
1163 ge->gru = NULL;
1164 }
1165
1166-void gru_recognize(struct grail *ge, const struct touch_frame *frame)
1167+void gru_recognize(struct grail *ge, const struct utouch_frame *frame)
1168 {
1169 if (!ge->gin || !ge->gru)
1170 return;
1171@@ -54,5 +54,4 @@
1172 gru_winpinch(ge, frame);
1173 gru_winrotate(ge, frame);
1174 gru_tapping(ge, frame);
1175- ge->gru->frame = *frame;
1176 }
1177
1178=== modified file 'src/grail-recognizer.h'
1179--- src/grail-recognizer.h 2010-08-11 17:04:45 +0000
1180+++ src/grail-recognizer.h 2011-01-02 12:29:53 +0000
1181@@ -26,7 +26,6 @@
1182 #include "grail-gestures.h"
1183
1184 struct gesture_recognizer {
1185- struct touch_frame frame;
1186 struct move_model move;
1187 struct combo_model drag;
1188 struct combo_model pinch;
1189@@ -38,7 +37,7 @@
1190 };
1191
1192 int gru_init(struct grail *ge);
1193-void gru_recognize(struct grail *ge, const struct touch_frame *frame);
1194+void gru_recognize(struct grail *ge, const struct utouch_frame *frame);
1195 void gru_destroy(struct grail *ge);
1196
1197 #endif
1198
1199=== added file 'src/grailbuf.h'
1200--- src/grailbuf.h 1970-01-01 00:00:00 +0000
1201+++ src/grailbuf.h 2011-01-02 12:29:53 +0000
1202@@ -0,0 +1,60 @@
1203+/*****************************************************************************
1204+ *
1205+ * grail - Gesture Recognition And Instantiation Library
1206+ *
1207+ * Copyright (C) 2010 Canonical Ltd.
1208+ * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
1209+ *
1210+ * This program is free software: you can redistribute it and/or modify it
1211+ * under the terms of the GNU General Public License as published by the
1212+ * Free Software Foundation, either version 3 of the License, or (at your
1213+ * option) any later version.
1214+ *
1215+ * This program is distributed in the hope that it will be useful, but
1216+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1217+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1218+ * General Public License for more details.
1219+ *
1220+ * You should have received a copy of the GNU General Public License along
1221+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1222+ *
1223+ ****************************************************************************/
1224+
1225+#ifndef _GRAIL_BUFFER_H
1226+#define _GRAIL_BUFFER_H
1227+
1228+#include <grail.h>
1229+
1230+#define DIM_GRAIL_EVENTS 512
1231+
1232+struct grailbuf {
1233+ int head;
1234+ int tail;
1235+ struct grail_event buffer[DIM_GRAIL_EVENTS];
1236+};
1237+
1238+static inline void grailbuf_clear(struct grailbuf *buf)
1239+{
1240+ buf->head = buf->tail = 0;
1241+}
1242+
1243+static inline int grailbuf_empty(const struct grailbuf *buf)
1244+{
1245+ return buf->head == buf->tail;
1246+}
1247+
1248+static inline void grailbuf_put(struct grailbuf *buf,
1249+ const struct grail_event *ev)
1250+{
1251+ buf->buffer[buf->head++] = *ev;
1252+ buf->head &= DIM_GRAIL_EVENTS - 1;
1253+}
1254+
1255+static inline void grailbuf_get(struct grailbuf *buf,
1256+ struct grail_event *ev)
1257+{
1258+ *ev = buf->buffer[buf->tail++];
1259+ buf->tail &= DIM_GRAIL_EVENTS - 1;
1260+}
1261+
1262+#endif
1263
1264=== removed file 'src/touch-caps.c'
1265--- src/touch-caps.c 2010-09-28 09:33:20 +0000
1266+++ src/touch-caps.c 1970-01-01 00:00:00 +0000
1267@@ -1,117 +0,0 @@
1268-/*****************************************************************************
1269- *
1270- * grail - Gesture Recognition And Instantiation Library
1271- *
1272- * Copyright (C) 2010 Canonical Ltd.
1273- * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
1274- *
1275- * This program is free software: you can redistribute it and/or modify it
1276- * under the terms of the GNU General Public License as published by the
1277- * Free Software Foundation, either version 3 of the License, or (at your
1278- * option) any later version.
1279- *
1280- * This program is distributed in the hope that it will be useful, but
1281- * WITHOUT ANY WARRANTY; without even the implied warranty of
1282- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1283- * General Public License for more details.
1284- *
1285- * You should have received a copy of the GNU General Public License along
1286- * with this program. If not, see <http://www.gnu.org/licenses/>.
1287- *
1288- ****************************************************************************/
1289-
1290-#include <grail-touch.h>
1291-#include <errno.h>
1292-#include <math.h>
1293-
1294-/* see mtdev-mapping.h */
1295-#define MTDEV_POSITION_X 5
1296-#define MTDEV_POSITION_Y 6
1297-#define MTDEV_ORIENTATION 4
1298-#define MTDEV_PRESSURE 10
1299-
1300-#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
1301-
1302-static const int bits_per_long = 8 * sizeof(long);
1303-
1304-static inline int nlongs(int nbit)
1305-{
1306- return (nbit + bits_per_long - 1) / bits_per_long;
1307-}
1308-
1309-static inline int getbit(const unsigned long *map, int key)
1310-{
1311- return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01;
1312-}
1313-
1314-int touch_caps_is_supported(struct touch_dev *dev, int fd)
1315-{
1316- unsigned long keybits[nlongs(KEY_MAX)];
1317- unsigned long absbits[nlongs(ABS_MAX)];
1318- unsigned long relbits[nlongs(REL_CNT)];
1319- int rc;
1320-
1321- SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits));
1322- if (rc < 0)
1323- return 0;
1324- SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits));
1325- if (rc < 0)
1326- return 0;
1327- SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbits)), relbits));
1328- if (rc < 0)
1329- return 0;
1330-
1331- /* only support pure absolute devices at this time */
1332- if (getbit(relbits, REL_X) || getbit(relbits, REL_Y))
1333- return 0;
1334-
1335- if (dev->mtdev.caps.has_mtdata)
1336- return 1;
1337-
1338- return getbit(absbits, ABS_X) &&
1339- getbit(absbits, ABS_Y) &&
1340- getbit(keybits, BTN_TOUCH) &&
1341- getbit(keybits, BTN_TOOL_DOUBLETAP);
1342-}
1343-
1344-void touch_caps_init(struct touch_dev *dev)
1345-{
1346- const struct mtdev_caps *mt = &dev->mtdev.caps;
1347- struct touch_caps *caps = &dev->caps;
1348- caps->min_x = mt->abs[MTDEV_POSITION_X].minimum;
1349- caps->max_x = mt->abs[MTDEV_POSITION_X].maximum;
1350- caps->min_y = mt->abs[MTDEV_POSITION_Y].minimum;
1351- caps->max_y = mt->abs[MTDEV_POSITION_Y].maximum;
1352- caps->min_orient = mt->abs[MTDEV_ORIENTATION].minimum;
1353- caps->max_orient = mt->abs[MTDEV_ORIENTATION].maximum;
1354- caps->min_press = mt->abs[MTDEV_PRESSURE].minimum;
1355- caps->max_press = mt->abs[MTDEV_PRESSURE].maximum;
1356- if (caps->min_x == caps->max_x) {
1357- caps->min_x = 0;
1358- caps->max_x = 1024;
1359- }
1360- if (caps->min_y == caps->max_y) {
1361- caps->min_y = 0;
1362- caps->max_y = 768;
1363- }
1364- if (caps->min_orient == caps->max_orient)
1365- caps->max_orient = 1;
1366- if (caps->min_orient + caps->max_orient != 0)
1367- caps->min_orient = -caps->max_orient;
1368- if (caps->min_press == caps->max_press) {
1369- caps->min_press = 0;
1370- caps->max_press = 256;
1371- }
1372-}
1373-
1374-float touch_angle(const struct touch_dev *dev, int orient)
1375-{
1376- const struct touch_caps *caps = &dev->caps;
1377- return orient / caps->max_orient * M_PI_2;
1378-}
1379-
1380-float touch_pressure(const struct touch_dev *dev, int press)
1381-{
1382- const struct touch_caps *caps = &dev->caps;
1383- return (press - caps->min_press) / (caps->max_press - caps->min_press);
1384-}
1385
1386=== removed file 'src/touch-dev.c'
1387--- src/touch-dev.c 2010-09-10 12:00:27 +0000
1388+++ src/touch-dev.c 1970-01-01 00:00:00 +0000
1389@@ -1,264 +0,0 @@
1390-/*****************************************************************************
1391- *
1392- * grail - Gesture Recognition And Instantiation Library
1393- *
1394- * Copyright (C) 2010 Canonical Ltd.
1395- * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
1396- *
1397- * This program is free software: you can redistribute it and/or modify it
1398- * under the terms of the GNU General Public License as published by the
1399- * Free Software Foundation, either version 3 of the License, or (at your
1400- * option) any later version.
1401- *
1402- * This program is distributed in the hope that it will be useful, but
1403- * WITHOUT ANY WARRANTY; without even the implied warranty of
1404- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1405- * General Public License for more details.
1406- *
1407- * You should have received a copy of the GNU General Public License along
1408- * with this program. If not, see <http://www.gnu.org/licenses/>.
1409- *
1410- ****************************************************************************/
1411-
1412-#include <grail-touch.h>
1413-#include <malloc.h>
1414-#include <string.h>
1415-#include <errno.h>
1416-
1417-/* see mtdev-mapping.h */
1418-#define MTDEV_TOUCH_MINOR 1
1419-
1420-#define SET_PROP(name, value) \
1421- if (t->name != value) { \
1422- t->name = value; \
1423- frame->nmodify++; \
1424- }
1425-
1426-static void finish_touch(struct touch_dev *dev, struct touch_frame *frame)
1427-{
1428- struct touch *t = &frame->touch[dev->slot];
1429- if (t->touch_major && !t->touch_minor ||
1430- !dev->mtdev.caps.has_abs[MTDEV_TOUCH_MINOR])
1431- SET_PROP(touch_minor, t->touch_major);
1432- if (dev->state > 0) {
1433- t->active = 1;
1434- grail_mask_set(frame->touches, dev->slot);
1435- frame->ncreate++;
1436- }
1437- if (dev->state < 0) {
1438- t->active = 0;
1439- grail_mask_clear(frame->touches, dev->slot);
1440- frame->ndestroy++;
1441- }
1442- dev->state = 0;
1443-}
1444-
1445-static void finish_legacy(struct touch_dev *dev, struct touch_frame *frame)
1446-{
1447- static int trkid;
1448- int i;
1449- for (i = 0; i < frame->nactive; i++) {
1450- struct touch *t = &frame->touch[i];
1451- t->active = 1;
1452- if (t->id < 0) {
1453- t->id = trkid++ & 0xffff;
1454- frame->ncreate++;
1455- }
1456- if (i > 0) {
1457- SET_PROP(x, frame->touch[0].x);
1458- SET_PROP(y, frame->touch[0].y);
1459- SET_PROP(pressure, frame->touch[0].pressure);
1460- }
1461- grail_mask_set(frame->touches, i);
1462- }
1463- for (i = frame->nactive; i < DIM_TOUCH; i++) {
1464- struct touch *t = &frame->touch[i];
1465- t->active = 0;
1466- if (t->id >= 0) {
1467- t->id = -1;
1468- frame->ndestroy++;
1469- }
1470- grail_mask_clear(frame->touches, i);
1471- }
1472-}
1473-
1474-static void finish_packet(struct touch_dev *dev,
1475- const struct input_event *syn)
1476-{
1477- static const touch_time_t ms = 1000;
1478- struct touch_frame *frame = &dev->frame;
1479- int i, nslot = 0;
1480- if (dev->mtdev.caps.has_mtdata)
1481- finish_touch(dev, frame);
1482- else
1483- finish_legacy(dev, frame);
1484- grail_mask_foreach(i, frame->touches, DIM_TOUCH_BYTES)
1485- frame->active[nslot++] = &frame->touch[i];
1486- frame->nactive = nslot;
1487- frame->time = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
1488- if (dev->sync)
1489- dev->sync(dev, syn);
1490- frame->ncreate = 0;
1491- frame->nmodify = 0;
1492- frame->ndestroy = 0;
1493-}
1494-
1495-static int handle_abs_event(struct touch_dev *dev,
1496- const struct input_event *ev)
1497-{
1498- struct touch_frame *frame = &dev->frame;
1499- struct touch *t = &frame->touch[dev->slot];
1500- switch (ev->code) {
1501- case ABS_X:
1502- if (dev->mtdev.caps.has_mtdata)
1503- return 0;
1504- SET_PROP(x, ev->value);
1505- return 0;
1506- case ABS_Y:
1507- if (dev->mtdev.caps.has_mtdata)
1508- return 0;
1509- SET_PROP(y, ev->value);
1510- return 0;
1511- case ABS_PRESSURE:
1512- if (dev->mtdev.caps.has_mtdata)
1513- return 0;
1514- SET_PROP(pressure, ev->value);
1515- return 0;
1516- case ABS_MT_SLOT:
1517- if (ev->value >= 0 && ev->value < DIM_TOUCH) {
1518- if (dev->slot != ev->value)
1519- finish_touch(dev, frame);
1520- dev->slot = ev->value;
1521- t = &frame->touch[dev->slot];
1522- }
1523- return 1;
1524- case ABS_MT_POSITION_X:
1525- SET_PROP(x, ev->value);
1526- return 1;
1527- case ABS_MT_POSITION_Y:
1528- SET_PROP(y, ev->value);
1529- return 1;
1530- case ABS_MT_TOUCH_MAJOR:
1531- SET_PROP(touch_major, ev->value);
1532- return 1;
1533- case ABS_MT_TOUCH_MINOR:
1534- SET_PROP(touch_minor, ev->value);
1535- return 1;
1536- case ABS_MT_WIDTH_MAJOR:
1537- SET_PROP(width_major, ev->value);
1538- return 1;
1539- case ABS_MT_WIDTH_MINOR:
1540- SET_PROP(width_minor, ev->value);
1541- return 1;
1542- case ABS_MT_ORIENTATION:
1543- SET_PROP(orientation, ev->value);
1544- return 1;
1545- case ABS_MT_PRESSURE:
1546- SET_PROP(pressure, ev->value);
1547- return 1;
1548- case ABS_MT_TOOL_TYPE:
1549- SET_PROP(tool_type, ev->value);
1550- return 1;
1551- case ABS_MT_TRACKING_ID:
1552- if (t->id != ev->value) {
1553- if (t->id != MT_ID_NULL) {
1554- dev->state = -1;
1555- finish_touch(dev, frame);
1556- }
1557- if (ev->value != MT_ID_NULL)
1558- dev->state = 1;
1559- t->id = ev->value;
1560- }
1561- return 1;
1562- default:
1563- return 0;
1564- }
1565-}
1566-
1567-static int handle_key_event(struct touch_dev *dev,
1568- const struct input_event *ev)
1569-{
1570- struct touch_frame *frame = &dev->frame;
1571- if (dev->mtdev.caps.has_mtdata)
1572- return 0;
1573- switch (ev->code) {
1574- case BTN_TOUCH:
1575- if (ev->value && !frame->nactive)
1576- frame->nactive = 1;
1577- else if (!ev->value && frame->nactive)
1578- frame->nactive = 0;
1579- return 0;
1580- case BTN_TOOL_FINGER:
1581- if (ev->value)
1582- frame->nactive = 1;
1583- return 0;
1584- case BTN_TOOL_DOUBLETAP:
1585- if (ev->value)
1586- frame->nactive = 2;
1587- return 0;
1588- case BTN_TOOL_TRIPLETAP:
1589- if (ev->value)
1590- frame->nactive = 3;
1591- return 0;
1592- case BTN_TOOL_QUADTAP:
1593- if (ev->value)
1594- frame->nactive = 4;
1595- return 0;
1596- default:
1597- return 0;
1598- }
1599-}
1600-
1601-int touch_dev_open(struct touch_dev *dev, int fd)
1602-{
1603- struct touch_frame *frame = &dev->frame;
1604- int ret, i;
1605- memset(dev, 0, sizeof(*dev));
1606- for (i = 0; i < DIM_TOUCH; i++) {
1607- struct touch *t = &frame->touch[i];
1608- t->slot = i;
1609- t->id = MT_ID_NULL;
1610- }
1611- ret = mtdev_open(&dev->mtdev, fd);
1612- if (!ret && !touch_caps_is_supported(dev, fd))
1613- ret = -ENODEV;
1614- if (ret)
1615- goto error;
1616- touch_caps_init(dev);
1617- return 0;
1618- error:
1619- return ret;
1620-}
1621-
1622-int touch_dev_idle(struct touch_dev *dev, int fd, int ms)
1623-{
1624- return mtdev_idle(&dev->mtdev, fd, ms);
1625-}
1626-
1627-int touch_dev_pull(struct touch_dev *dev, int fd)
1628-{
1629- struct input_event ev;
1630- int ret, count = 0, consumed;
1631- while ((ret = mtdev_get(&dev->mtdev, fd, &ev, 1)) > 0) {
1632- consumed = 0;
1633- if (ev.type == EV_SYN) {
1634- if (ev.code == SYN_REPORT)
1635- finish_packet(dev, &ev);
1636- consumed++;
1637- } else if (ev.type == EV_ABS) {
1638- consumed += handle_abs_event(dev, &ev);
1639- } else if (ev.type == EV_KEY) {
1640- consumed += handle_key_event(dev, &ev);
1641- }
1642- if (!consumed && dev->event)
1643- dev->event(dev, &ev);
1644- count++;
1645- }
1646- return count > 0 ? count : ret;
1647-}
1648-
1649-void touch_dev_close(struct touch_dev *dev, int fd)
1650-{
1651- mtdev_close(&dev->mtdev);
1652- memset(dev, 0, sizeof(*dev));
1653-}
1654
1655=== modified file 'test/Makefile.am'
1656--- test/Makefile.am 2010-08-12 15:55:30 +0000
1657+++ test/Makefile.am 2011-01-02 12:29:53 +0000
1658@@ -1,9 +0,0 @@
1659-bin_PROGRAMS = grail-touch grail-gesture
1660-
1661-INCLUDES=-I$(top_srcdir)/include/
1662-
1663-grail_touch_SOURCES = grail-touch.c
1664-grail_touch_LDFLAGS = -L$(top_builddir)/src/.libs/ -lutouch-grail -lmtdev -lm
1665-
1666-grail_gesture_SOURCES = grail-gesture.c
1667-grail_gesture_LDFLAGS = -L$(top_builddir)/src/.libs/ -lutouch-grail -lmtdev -lm
1668
1669=== removed file 'test/grail-gesture.c'
1670--- test/grail-gesture.c 2010-09-21 11:27:02 +0000
1671+++ test/grail-gesture.c 1970-01-01 00:00:00 +0000
1672@@ -1,126 +0,0 @@
1673-/*****************************************************************************
1674- *
1675- * grail - Gesture Recognition And Instantiation Library
1676- *
1677- * Copyright (C) 2010 Canonical Ltd.
1678- *
1679- * This program is free software: you can redistribute it and/or modify it
1680- * under the terms of the GNU General Public License as published by the
1681- * Free Software Foundation, either version 3 of the License, or (at your
1682- * option) any later version.
1683- *
1684- * This program is distributed in the hope that it will be useful, but
1685- * WITHOUT ANY WARRANTY; without even the implied warranty of
1686- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1687- * General Public License for more details.
1688- *
1689- * You should have received a copy of the GNU General Public License along
1690- * with this program. If not, see <http://www.gnu.org/licenses/>.
1691- *
1692- * Authors:
1693- * Henrik Rydberg <rydberg@bitmath.org>
1694- *
1695- ****************************************************************************/
1696-
1697-#include <grail.h>
1698-#include <string.h>
1699-#include <stdio.h>
1700-#include <unistd.h>
1701-#include <fcntl.h>
1702-
1703-static grail_mask_t flag_mask[DIM_GRAIL_TYPE_BYTES];
1704-
1705-static int tp_get_clients(struct grail *ge,
1706- struct grail_client_info *clients, int max_clients,
1707- const struct grail_coord *coords, int num_coords,
1708- const grail_mask_t *types, int type_bytes)
1709-{
1710- memset(&clients[0], 0, sizeof(clients[0]));
1711- clients[0].id.client = 345;
1712- clients[0].id.root = 1;
1713- clients[0].id.event = 2;
1714- clients[0].id.child = 3;
1715- memcpy(clients[0].mask, flag_mask, sizeof(flag_mask));
1716- return 1;
1717-}
1718-
1719-static void tp_event(struct grail *ge, const struct input_event *ev)
1720-{
1721- fprintf(stderr, "%lu.%06u %04x %04x %d\n",
1722- ev->time.tv_sec, (unsigned)ev->time.tv_usec,
1723- ev->type, ev->code, ev->value);
1724-}
1725-
1726-static void tp_gesture(struct grail *ge, const struct grail_event *ev)
1727-{
1728- struct grail_contact touch[32];
1729- int i, ntouch;
1730- fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n",
1731- ev->type, ev->id, ev->client_id.client, ev->client_id.event,
1732- ev->pos.x, ev->pos.y, ev->ntouch,
1733- ev->status);
1734- ntouch = grail_get_contacts(ge, touch, 32);
1735- for (i = 0; i < ntouch; i++) {
1736- const struct grail_contact *t = &touch[i];
1737- fprintf(stderr, "\t%d: %d %d\n", i, t->id, t->tool_type);
1738- fprintf(stderr, "\t %f %f\n", t->pos.x, t->pos.y);
1739- fprintf(stderr, "\t %f %f %f %f\n", t->touch_major,
1740- t->touch_minor, t->width_major, t->width_minor);
1741- fprintf(stderr, "\t %f %f\n", t->angle, t->pressure);
1742- }
1743- for (i = 0; i < ev->nprop; i++)
1744- fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]);
1745-}
1746-
1747-static void loop_device(struct grail *ge, int fd)
1748-{
1749- while (!grail_idle(ge, fd, 5000))
1750- grail_pull(ge, fd);
1751-}
1752-
1753-int main(int argc, char *argv[])
1754-{
1755- struct grail ge;
1756- int i, fd;
1757-
1758- if (argc < 3) {
1759- fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]);
1760- return -1;
1761- }
1762-
1763- memset(&ge, 0, sizeof(ge));
1764- ge.get_clients = tp_get_clients;
1765- ge.event = tp_event;
1766- ge.gesture = tp_gesture;
1767-
1768- unsigned long mask = strtoull(argv[1], 0, 0);
1769- for (i = 0; i < DIM_GRAIL_TYPE; i++)
1770- if ((mask >> i) & 1)
1771- grail_mask_set(flag_mask, i);
1772-
1773- fd = open(argv[2], O_RDONLY | O_NONBLOCK);
1774- if (fd < 0) {
1775- fprintf(stderr, "error: could not open device\n");
1776- return -1;
1777- }
1778- if (ioctl(fd, EVIOCGRAB, 1)) {
1779- fprintf(stderr, "error: could not grab the device\n");
1780- return -1;
1781- }
1782-
1783- if (grail_open(&ge, fd)) {
1784- fprintf(stderr, "error: could not open touch device\n");
1785- return -1;
1786- }
1787- //grail_filter_abs_events(&ge, 1);
1788-
1789- struct grail_coord min = { -2, -1 }, max = { 2, 1 };
1790- grail_set_bbox(&ge, &min, &max);
1791-
1792- loop_device(&ge, fd);
1793- grail_close(&ge, fd);
1794-
1795- ioctl(fd, EVIOCGRAB, 0);
1796- close(fd);
1797- return 0;
1798-}
1799
1800=== removed file 'test/grail-touch.c'
1801--- test/grail-touch.c 2010-08-19 20:26:11 +0000
1802+++ test/grail-touch.c 1970-01-01 00:00:00 +0000
1803@@ -1,97 +0,0 @@
1804-/*****************************************************************************
1805- *
1806- * grail - Gesture Recognition And Instantiation Library
1807- *
1808- * Copyright (C) 2010 Canonical Ltd.
1809- *
1810- * This program is free software: you can redistribute it and/or modify it
1811- * under the terms of the GNU General Public License as published by the
1812- * Free Software Foundation, either version 3 of the License, or (at your
1813- * option) any later version.
1814- *
1815- * This program is distributed in the hope that it will be useful, but
1816- * WITHOUT ANY WARRANTY; without even the implied warranty of
1817- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1818- * General Public License for more details.
1819- *
1820- * You should have received a copy of the GNU General Public License along
1821- * with this program. If not, see <http://www.gnu.org/licenses/>.
1822- *
1823- * Authors:
1824- * Henrik Rydberg <rydberg@bitmath.org>
1825- *
1826- ****************************************************************************/
1827-
1828-#include <grail-touch.h>
1829-#include <string.h>
1830-#include <stdio.h>
1831-#include <unistd.h>
1832-#include <fcntl.h>
1833-
1834-static void tp_event(struct touch_dev *dev,
1835- const struct input_event *ev)
1836-{
1837- fprintf(stderr, "event %d 0x%x %d\n", ev->type, ev->code, ev->value);
1838-}
1839-
1840-static void tp_sync(struct touch_dev *dev,
1841- const struct input_event *syn)
1842-{
1843- struct touch_frame *frame = &dev->frame;
1844- int i, j;
1845- for (i = 0; i < frame->nactive; i++) {
1846- struct touch *t = frame->active[i];
1847- fprintf(stderr, "touch %d\n", i);
1848- fprintf(stderr, " slot: %d\n", t->slot);
1849- fprintf(stderr, " id: %d\n", t->id);
1850- fprintf(stderr, " tool_type: %d\n", t->tool_type);
1851- fprintf(stderr, " x: %d\n", t->x);
1852- fprintf(stderr, " y: %d\n", t->y);
1853- fprintf(stderr, " touch_major: %d\n", t->touch_major);
1854- fprintf(stderr, " touch_minor: %d\n", t->touch_minor);
1855- fprintf(stderr, " width_major: %d\n", t->width_major);
1856- fprintf(stderr, " width_minor: %d\n", t->width_minor);
1857- fprintf(stderr, " angle: %f\n",
1858- touch_angle(dev, t->orientation));
1859- fprintf(stderr, " pressure: %f\n",
1860- touch_pressure(dev, t->pressure));
1861- }
1862- fprintf(stderr, "sync %d %lld %d %d\n",
1863- frame->nactive, frame->time, frame->ncreate, frame->ndestroy);
1864-}
1865-
1866-static void loop_device(struct touch_dev *dev, int fd)
1867-{
1868- dev->event = tp_event;
1869- dev->sync = tp_sync;
1870- while (!touch_dev_idle(dev, fd, 5000))
1871- touch_dev_pull(dev, fd);
1872-}
1873-
1874-int main(int argc, char *argv[])
1875-{
1876- struct touch_dev dev;
1877- int fd;
1878- if (argc < 2) {
1879- fprintf(stderr, "Usage: %s <device>\n", argv[0]);
1880- return -1;
1881- }
1882- fd = open(argv[1], O_RDONLY | O_NONBLOCK);
1883- if (fd < 0) {
1884- fprintf(stderr, "error: could not open device\n");
1885- return -1;
1886- }
1887- if (ioctl(fd, EVIOCGRAB, 1)) {
1888- fprintf(stderr, "error: could not grab the device\n");
1889- return -1;
1890- }
1891- if (touch_dev_open(&dev, fd)) {
1892- fprintf(stderr, "error: could not open touch device\n");
1893- return -1;
1894- }
1895- loop_device(&dev, fd);
1896- touch_dev_close(&dev, fd);
1897- ioctl(fd, EVIOCGRAB, 0);
1898- close(fd);
1899- return 0;
1900-}
1901
1902=== added directory 'tools'
1903=== added file 'tools/Makefile.am'
1904--- tools/Makefile.am 1970-01-01 00:00:00 +0000
1905+++ tools/Makefile.am 2011-01-02 12:29:53 +0000
1906@@ -0,0 +1,7 @@
1907+bin_PROGRAMS = grail-gesture
1908+
1909+INCLUDES=-I$(top_srcdir)/include/
1910+
1911+grail_gesture_SOURCES = grail-gesture.c
1912+grail_gesture_LDFLAGS = -L$(top_builddir)/src/.libs/ \
1913+ -lutouch-grail -lutouch-frame -lutouch-evemu -lmtdev -lm
1914
1915=== added file 'tools/grail-gesture.c'
1916--- tools/grail-gesture.c 1970-01-01 00:00:00 +0000
1917+++ tools/grail-gesture.c 2011-01-02 12:29:53 +0000
1918@@ -0,0 +1,126 @@
1919+/*****************************************************************************
1920+ *
1921+ * grail - Gesture Recognition And Instantiation Library
1922+ *
1923+ * Copyright (C) 2010 Canonical Ltd.
1924+ *
1925+ * This program is free software: you can redistribute it and/or modify it
1926+ * under the terms of the GNU General Public License as published by the
1927+ * Free Software Foundation, either version 3 of the License, or (at your
1928+ * option) any later version.
1929+ *
1930+ * This program is distributed in the hope that it will be useful, but
1931+ * WITHOUT ANY WARRANTY; without even the implied warranty of
1932+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1933+ * General Public License for more details.
1934+ *
1935+ * You should have received a copy of the GNU General Public License along
1936+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1937+ *
1938+ * Authors:
1939+ * Henrik Rydberg <rydberg@bitmath.org>
1940+ *
1941+ ****************************************************************************/
1942+
1943+#include <grail.h>
1944+#include <string.h>
1945+#include <stdio.h>
1946+#include <unistd.h>
1947+#include <fcntl.h>
1948+
1949+static grail_mask_t flag_mask[DIM_GRAIL_TYPE_BYTES];
1950+
1951+static int tp_get_clients(struct grail *ge,
1952+ struct grail_client_info *clients, int max_clients,
1953+ const struct grail_coord *coords, int num_coords,
1954+ const grail_mask_t *types, int type_bytes)
1955+{
1956+ memset(&clients[0], 0, sizeof(clients[0]));
1957+ clients[0].id.client = 345;
1958+ clients[0].id.root = 1;
1959+ clients[0].id.event = 2;
1960+ clients[0].id.child = 3;
1961+ memcpy(clients[0].mask, flag_mask, sizeof(flag_mask));
1962+ return 1;
1963+}
1964+
1965+static void tp_event(struct grail *ge, const struct input_event *ev)
1966+{
1967+ fprintf(stderr, "%lu.%06u %04x %04x %d\n",
1968+ ev->time.tv_sec, (unsigned)ev->time.tv_usec,
1969+ ev->type, ev->code, ev->value);
1970+}
1971+
1972+static void tp_gesture(struct grail *ge, const struct grail_event *ev)
1973+{
1974+ struct grail_contact touch[32];
1975+ int i, ntouch;
1976+ fprintf(stderr, "gesture %d %d %d %d - %f %f %d - %d\n",
1977+ ev->type, ev->id, ev->client_id.client, ev->client_id.event,
1978+ ev->pos.x, ev->pos.y, ev->ntouch,
1979+ ev->status);
1980+ ntouch = grail_get_contacts(ge, touch, 32);
1981+ for (i = 0; i < ntouch; i++) {
1982+ const struct grail_contact *t = &touch[i];
1983+ fprintf(stderr, "\t%d: %d %d\n", i, t->id, t->tool_type);
1984+ fprintf(stderr, "\t %f %f\n", t->pos.x, t->pos.y);
1985+ fprintf(stderr, "\t %f %f %f %f\n", t->touch_major,
1986+ t->touch_minor, t->width_major, t->width_minor);
1987+ fprintf(stderr, "\t %f %f\n", t->angle, t->pressure);
1988+ }
1989+ for (i = 0; i < ev->nprop; i++)
1990+ fprintf(stderr, "\t%d: %f\n", i, ev->prop[i]);
1991+}
1992+
1993+static void loop_device(struct grail *ge, int fd)
1994+{
1995+ while (!grail_idle(ge, fd, 5000))
1996+ grail_pull(ge, fd);
1997+}
1998+
1999+int main(int argc, char *argv[])
2000+{
2001+ struct grail ge;
2002+ int i, fd;
2003+
2004+ if (argc < 3) {
2005+ fprintf(stderr, "Usage: %s <mask> <device>\n", argv[0]);
2006+ return -1;
2007+ }
2008+
2009+ memset(&ge, 0, sizeof(ge));
2010+ ge.get_clients = tp_get_clients;
2011+ ge.event = tp_event;
2012+ ge.gesture = tp_gesture;
2013+
2014+ unsigned long mask = strtoull(argv[1], 0, 0);
2015+ for (i = 0; i < DIM_GRAIL_TYPE; i++)
2016+ if ((mask >> i) & 1)
2017+ grail_mask_set(flag_mask, i);
2018+
2019+ fd = open(argv[2], O_RDONLY | O_NONBLOCK);
2020+ if (fd < 0) {
2021+ fprintf(stderr, "error: could not open device\n");
2022+ return -1;
2023+ }
2024+ if (ioctl(fd, EVIOCGRAB, 1)) {
2025+ fprintf(stderr, "error: could not grab the device\n");
2026+ return -1;
2027+ }
2028+
2029+ if (grail_open(&ge, fd)) {
2030+ fprintf(stderr, "error: could not open touch device\n");
2031+ return -1;
2032+ }
2033+ //grail_filter_abs_events(&ge, 1);
2034+
2035+ struct grail_coord min = { -2, -1 }, max = { 2, 1 };
2036+ grail_set_bbox(&ge, &min, &max);
2037+
2038+ loop_device(&ge, fd);
2039+ grail_close(&ge, fd);
2040+
2041+ ioctl(fd, EVIOCGRAB, 0);
2042+ close(fd);
2043+ return 0;
2044+}
2045
2046=== added file 'utouch-grail.sym.in'
2047--- utouch-grail.sym.in 1970-01-01 00:00:00 +0000
2048+++ utouch-grail.sym.in 2011-01-02 12:29:53 +0000
2049@@ -0,0 +1,13 @@
2050+grail_close
2051+grail_filter_abs_events
2052+grail_get_contacts
2053+grail_get_units
2054+grail_idle
2055+grail_mask_clear_mask
2056+grail_mask_count
2057+grail_mask_get_first
2058+grail_mask_get_next
2059+grail_mask_set_mask
2060+grail_open
2061+grail_pull
2062+grail_set_bbox

Subscribers

People subscribed via source and target branches

to all changes: