summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-01-02 12:38:26 +0100
committerHenrik Rydberg <rydberg@euromail.se>2011-01-02 12:38:26 +0100
commit1e07054fbeab6e90f104c279d3246097dd838a17 (patch)
treed5369728c02ee5d826b7e104f0b2297832276f94
parentab67ba5e161c4d65128fc5eada6845a543464759 (diff)
Prepare for queued event handling
The current grail operates via callbacks. In order to make grail work as a pipe, where input and output can be controlled externally, add the missing event queue for gestures, and align the code to simplify a switch. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--src/Makefile.am1
-rw-r--r--src/grail-api.c25
-rw-r--r--src/grail-event.c3
-rw-r--r--src/grail-impl.h2
-rw-r--r--src/grailbuf.h60
5 files changed, 79 insertions, 12 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a6ca322..dd2af2b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,7 @@ libutouch_grail_la_LDFLAGS = \
8libutouch_grail_la_SOURCES = \ 8libutouch_grail_la_SOURCES = \
9 evbuf.h \ 9 evbuf.h \
10 gebuf.h \ 10 gebuf.h \
11 grailbuf.h \
11 touch-dev.c \ 12 touch-dev.c \
12 touch-caps.c \ 13 touch-caps.c \
13 grail-bits.c \ 14 grail-bits.c \
diff --git a/src/grail-api.c b/src/grail-api.c
index f013aa3..f38ca18 100644
--- a/src/grail-api.c
+++ b/src/grail-api.c
@@ -184,28 +184,31 @@ static void handle_abs_events(struct grail *ge, const struct input_event *syn)
184static void tp_sync(struct touch_dev *dev, 184static void tp_sync(struct touch_dev *dev,
185 const struct input_event *syn) 185 const struct input_event *syn)
186{ 186{
187 struct input_event ev;
188 struct grail *ge = dev->priv; 187 struct grail *ge = dev->priv;
189 struct grail_impl *impl = ge->impl; 188 struct grail_impl *impl = ge->impl;
189 int head = impl->evbuf.head;
190 struct input_event iev;
191 struct grail_event gev;
190 struct touch_frame *frame = &dev->frame; 192 struct touch_frame *frame = &dev->frame;
191 int nevent = 0;
192 gin_frame_begin(ge, frame); 193 gin_frame_begin(ge, frame);
193 gru_recognize(ge, frame); 194 gru_recognize(ge, frame);
194 gin_frame_end(ge, frame); 195 gin_frame_end(ge, frame);
195 196
196 if (!ge->event) {
197 evbuf_clear(&impl->evbuf);
198 return;
199 }
200 if (!impl->filter_abs) 197 if (!impl->filter_abs)
201 handle_abs_events(ge, syn); 198 handle_abs_events(ge, syn);
199 if (impl->evbuf.head != head)
200 evbuf_put(&impl->evbuf, syn);
201
202 while (!grailbuf_empty(&impl->gbuf)) {
203 grailbuf_get(&impl->gbuf, &gev);
204 if (ge->gesture)
205 ge->gesture(ge, &gev);
206 }
202 while (!evbuf_empty(&impl->evbuf)) { 207 while (!evbuf_empty(&impl->evbuf)) {
203 evbuf_get(&impl->evbuf, &ev); 208 evbuf_get(&impl->evbuf, &iev);
204 ge->event(ge, &ev); 209 if (ge->event)
205 nevent++; 210 ge->event(ge, &iev);
206 } 211 }
207 if (nevent)
208 ge->event(ge, syn);
209} 212}
210 213
211void grail_filter_abs_events(struct grail *ge, int usage) 214void grail_filter_abs_events(struct grail *ge, int usage)
diff --git a/src/grail-event.c b/src/grail-event.c
index 2cf8209..23fdbb3 100644
--- a/src/grail-event.c
+++ b/src/grail-event.c
@@ -97,6 +97,7 @@ void gin_send_event(struct grail *ge, struct slot_state *s,
97 const struct gesture_event *ev, 97 const struct gesture_event *ev,
98 const struct touch_frame *frame) 98 const struct touch_frame *frame)
99{ 99{
100 struct grail_impl *impl = ge->impl;
100 const struct gesture_inserter *gin = ge->gin; 101 const struct gesture_inserter *gin = ge->gin;
101 struct grail_event gev; 102 struct grail_event gev;
102 int i; 103 int i;
@@ -113,7 +114,7 @@ void gin_send_event(struct grail *ge, struct slot_state *s,
113 memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t)); 114 memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t));
114 for (i = 0; i < s->nclient; i++) { 115 for (i = 0; i < s->nclient; i++) {
115 gev.client_id = s->client_id[i]; 116 gev.client_id = s->client_id[i];
116 ge->gesture(ge, &gev); 117 grailbuf_put(&impl->gbuf, &gev);
117 } 118 }
118} 119}
119 120
diff --git a/src/grail-impl.h b/src/grail-impl.h
index dc3b425..2859186 100644
--- a/src/grail-impl.h
+++ b/src/grail-impl.h
@@ -25,11 +25,13 @@
25 25
26#include <grail-touch.h> 26#include <grail-touch.h>
27#include "evbuf.h" 27#include "evbuf.h"
28#include "grailbuf.h"
28 29
29struct grail_impl { 30struct grail_impl {
30 struct touch_dev dev; 31 struct touch_dev dev;
31 struct touch_caps emu; 32 struct touch_caps emu;
32 struct evbuf evbuf; 33 struct evbuf evbuf;
34 struct grailbuf gbuf;
33 int filter_abs; 35 int filter_abs;
34 int pointer_status; 36 int pointer_status;
35 int pointer_x, pointer_y; 37 int pointer_x, pointer_y;
diff --git a/src/grailbuf.h b/src/grailbuf.h
new file mode 100644
index 0000000..b319d24
--- /dev/null
+++ b/src/grailbuf.h
@@ -0,0 +1,60 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ****************************************************************************/
22
23#ifndef _GRAIL_BUFFER_H
24#define _GRAIL_BUFFER_H
25
26#include <grail.h>
27
28#define DIM_GRAIL_EVENTS 512
29
30struct grailbuf {
31 int head;
32 int tail;
33 struct grail_event buffer[DIM_GRAIL_EVENTS];
34};
35
36static inline void grailbuf_clear(struct grailbuf *buf)
37{
38 buf->head = buf->tail = 0;
39}
40
41static inline int grailbuf_empty(const struct grailbuf *buf)
42{
43 return buf->head == buf->tail;
44}
45
46static inline void grailbuf_put(struct grailbuf *buf,
47 const struct grail_event *ev)
48{
49 buf->buffer[buf->head++] = *ev;
50 buf->head &= DIM_GRAIL_EVENTS - 1;
51}
52
53static inline void grailbuf_get(struct grailbuf *buf,
54 struct grail_event *ev)
55{
56 *ev = buf->buffer[buf->tail++];
57 buf->tail &= DIM_GRAIL_EVENTS - 1;
58}
59
60#endif