summaryrefslogtreecommitdiff
path: root/src/grailbuf.h
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 /src/grailbuf.h
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>
Diffstat (limited to 'src/grailbuf.h')
-rw-r--r--src/grailbuf.h60
1 files changed, 60 insertions, 0 deletions
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