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/grailbuf.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/grailbuf.h (limited to 'src/grailbuf.h') 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