From 1e07054fbeab6e90f104c279d3246097dd838a17 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sun, 2 Jan 2011 12:38:26 +0100 Subject: 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 --- src/Makefile.am | 1 + src/grail-api.c | 25 +++++++++++++---------- src/grail-event.c | 3 ++- src/grail-impl.h | 2 ++ src/grailbuf.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 src/grailbuf.h (limited to 'src') 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 = \ libutouch_grail_la_SOURCES = \ evbuf.h \ gebuf.h \ + grailbuf.h \ touch-dev.c \ touch-caps.c \ 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) static void tp_sync(struct touch_dev *dev, const struct input_event *syn) { - struct input_event ev; struct grail *ge = dev->priv; struct grail_impl *impl = ge->impl; + int head = impl->evbuf.head; + struct input_event iev; + struct grail_event gev; struct touch_frame *frame = &dev->frame; - int nevent = 0; gin_frame_begin(ge, frame); gru_recognize(ge, frame); gin_frame_end(ge, frame); - if (!ge->event) { - evbuf_clear(&impl->evbuf); - return; - } if (!impl->filter_abs) handle_abs_events(ge, syn); + if (impl->evbuf.head != head) + evbuf_put(&impl->evbuf, syn); + + while (!grailbuf_empty(&impl->gbuf)) { + grailbuf_get(&impl->gbuf, &gev); + if (ge->gesture) + ge->gesture(ge, &gev); + } while (!evbuf_empty(&impl->evbuf)) { - evbuf_get(&impl->evbuf, &ev); - ge->event(ge, &ev); - nevent++; + evbuf_get(&impl->evbuf, &iev); + if (ge->event) + ge->event(ge, &iev); } - if (nevent) - ge->event(ge, syn); } void 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, const struct gesture_event *ev, const struct touch_frame *frame) { + struct grail_impl *impl = ge->impl; const struct gesture_inserter *gin = ge->gin; struct grail_event gev; int i; @@ -113,7 +114,7 @@ void gin_send_event(struct grail *ge, struct slot_state *s, memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t)); for (i = 0; i < s->nclient; i++) { gev.client_id = s->client_id[i]; - ge->gesture(ge, &gev); + grailbuf_put(&impl->gbuf, &gev); } } 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 @@ #include #include "evbuf.h" +#include "grailbuf.h" struct grail_impl { struct touch_dev dev; struct touch_caps emu; struct evbuf evbuf; + struct grailbuf gbuf; int filter_abs; int pointer_status; 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 @@ +/***************************************************************************** + * + * grail - Gesture Recognition And Instantiation Library + * + * Copyright (C) 2010 Canonical Ltd. + * Copyright (C) 2010 Henrik Rydberg + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + ****************************************************************************/ + +#ifndef _GRAIL_BUFFER_H +#define _GRAIL_BUFFER_H + +#include + +#define DIM_GRAIL_EVENTS 512 + +struct grailbuf { + int head; + int tail; + struct grail_event buffer[DIM_GRAIL_EVENTS]; +}; + +static inline void grailbuf_clear(struct grailbuf *buf) +{ + buf->head = buf->tail = 0; +} + +static inline int grailbuf_empty(const struct grailbuf *buf) +{ + return buf->head == buf->tail; +} + +static inline void grailbuf_put(struct grailbuf *buf, + const struct grail_event *ev) +{ + buf->buffer[buf->head++] = *ev; + buf->head &= DIM_GRAIL_EVENTS - 1; +} + +static inline void grailbuf_get(struct grailbuf *buf, + struct grail_event *ev) +{ + *ev = buf->buffer[buf->tail++]; + buf->tail &= DIM_GRAIL_EVENTS - 1; +} + +#endif -- cgit v1.2.3