summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/gesture-client.c2
-rw-r--r--src/gesture-dev.c2
-rw-r--r--src/grail-api.c151
-rw-r--r--src/touch-dev.c6
-rw-r--r--src/touch-engine.c9
6 files changed, 165 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7ccacae..50a5afd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,7 +8,8 @@ libgrail_la_SOURCES = \
8 touch-dev.c \ 8 touch-dev.c \
9 touch-engine.c \ 9 touch-engine.c \
10 gesture-client.c \ 10 gesture-client.c \
11 gesture-dev.c 11 gesture-dev.c \
12 grail-api.c
12 13
13AM_CFLAGS = $(CWARNFLAGS) -std=c99 14AM_CFLAGS = $(CWARNFLAGS) -std=c99
14 15
@@ -17,4 +18,5 @@ INCLUDES = -I$(top_srcdir)/include/
17libgrailincludedir = $(includedir) 18libgrailincludedir = $(includedir)
18libgrailinclude_HEADERS = \ 19libgrailinclude_HEADERS = \
19 $(top_srcdir)/include/grail-touch.h \ 20 $(top_srcdir)/include/grail-touch.h \
21 $(top_srcdir)/include/grail-gesture.h \
20 $(top_srcdir)/include/grail.h 22 $(top_srcdir)/include/grail.h
diff --git a/src/gesture-client.c b/src/gesture-client.c
index 78328b7..91f1530 100644
--- a/src/gesture-client.c
+++ b/src/gesture-client.c
@@ -22,7 +22,7 @@
22 * 22 *
23 ****************************************************************************/ 23 ****************************************************************************/
24 24
25#include <grail.h> 25#include <grail-gesture.h>
26#include <malloc.h> 26#include <malloc.h>
27#include <string.h> 27#include <string.h>
28#include <errno.h> 28#include <errno.h>
diff --git a/src/gesture-dev.c b/src/gesture-dev.c
index 8dd11a9..46c77d7 100644
--- a/src/gesture-dev.c
+++ b/src/gesture-dev.c
@@ -22,7 +22,7 @@
22 * 22 *
23 ****************************************************************************/ 23 ****************************************************************************/
24 24
25#include <grail.h> 25#include <grail-gesture.h>
26#include <malloc.h> 26#include <malloc.h>
27#include <string.h> 27#include <string.h>
28#include <errno.h> 28#include <errno.h>
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
diff --git a/src/touch-dev.c b/src/touch-dev.c
index 80cc82f..dc23baa 100644
--- a/src/touch-dev.c
+++ b/src/touch-dev.c
@@ -65,11 +65,9 @@ static void finish_touch(struct touch_dev *dev,
65static void finish_packet(struct touch_dev *dev, 65static void finish_packet(struct touch_dev *dev,
66 const struct input_event *syn) 66 const struct input_event *syn)
67{ 67{
68 static const touch_time_t ms = 1000;
69 touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
70 finish_touch(dev, dev->impl); 68 finish_touch(dev, dev->impl);
71 if (dev->sync) 69 if (dev->sync)
72 dev->sync(dev, time); 70 dev->sync(dev, syn);
73} 71}
74 72
75static int handle_abs_event(struct touch_dev *dev, 73static int handle_abs_event(struct touch_dev *dev,
@@ -133,6 +131,8 @@ int touch_dev_open(struct touch_dev *dev, int fd)
133 if (!x) 131 if (!x)
134 return -ENOMEM; 132 return -ENOMEM;
135 ret = mtdev_open(&x->mtdev, fd); 133 ret = mtdev_open(&x->mtdev, fd);
134 if (!ret && !x->mtdev.caps.has_mtdata)
135 ret = -ENODEV;
136 if (ret) 136 if (ret)
137 goto error; 137 goto error;
138 for (i = 0; i < DIM_TOUCH; i++) 138 for (i = 0; i < DIM_TOUCH; i++)
diff --git a/src/touch-engine.c b/src/touch-engine.c
index 6174e0d..8e43faf 100644
--- a/src/touch-engine.c
+++ b/src/touch-engine.c
@@ -94,13 +94,15 @@ static void tp_destroy(struct touch_dev *dev, int slot)
94 } 94 }
95} 95}
96 96
97static void tp_sync(struct touch_dev *dev, touch_time_t time) 97static void tp_sync(struct touch_dev *dev, const struct input_event *syn)
98{ 98{
99 static const touch_time_t ms = 1000;
99 struct touch_engine *engine = dev->priv; 100 struct touch_engine *engine = dev->priv;
101 touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
100 if (engine) { 102 if (engine) {
101 finalize_frame(&engine->frame, time); 103 finalize_frame(&engine->frame, time);
102 if (engine->sync) 104 if (engine->sync)
103 engine->sync(engine); 105 engine->sync(engine, syn);
104 engine->frame.ncreate = 0; 106 engine->frame.ncreate = 0;
105 engine->frame.nmodify = 0; 107 engine->frame.nmodify = 0;
106 engine->frame.ndestroy = 0; 108 engine->frame.ndestroy = 0;
@@ -110,7 +112,8 @@ static void tp_sync(struct touch_dev *dev, touch_time_t time)
110void touch_engine_init(struct touch_engine *engine, 112void touch_engine_init(struct touch_engine *engine,
111 void (*event)(struct touch_engine *engine, 113 void (*event)(struct touch_engine *engine,
112 const struct input_event *ev), 114 const struct input_event *ev),
113 void (*sync)(struct touch_engine *engine), 115 void (*sync)(struct touch_engine *engine,
116 const struct input_event *ev),
114 void *priv) 117 void *priv)
115{ 118{
116 memset(engine, 0, sizeof(*engine)); 119 memset(engine, 0, sizeof(*engine));