summaryrefslogtreecommitdiff
path: root/src/touch-engine.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-08-19 20:03:15 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-19 20:03:15 +0200
commita704984e03d28b4be40e12c43be1b163bc9e09e2 (patch)
treec4720a59aa77918ffef742d7ec7ef2a7e2eda16e /src/touch-engine.c
parentcb2cad3b8c506a08a6bdad548a10ff47f85ef38b (diff)
Simplify touch machinery
To be able to model touch information uniformly across all supported devices, the semantics of the touch attributes has to be treated explicitly. Drop the generic touch property array and replace it by an actual structure. In addition, the touch-engine abstraction turned out to not be needed, so drop it as well. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/touch-engine.c')
-rw-r--r--src/touch-engine.c135
1 files changed, 0 insertions, 135 deletions
diff --git a/src/touch-engine.c b/src/touch-engine.c
deleted file mode 100644
index d13785d..0000000
--- a/src/touch-engine.c
+++ /dev/null
@@ -1,135 +0,0 @@
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#include <grail-touch.h>
24#include <string.h>
25
26static void tp_event(struct touch_dev *dev, const struct input_event *ev)
27{
28 struct touch_engine *engine = dev->priv;
29 if (engine && engine->event)
30 engine->event(engine, ev);
31}
32
33static void update_frame(struct touch_frame *frame,
34 int slot, int active,
35 const grail_mask_t *mask,
36 const touch_prop_t *prop)
37{
38 struct touch *t = &frame->touch[slot];
39 int i;
40 t->active = active;
41 grail_mask_modify(frame->touches, slot, active);
42 if (mask && prop)
43 grail_mask_foreach(i, mask, DIM_TOUCH_PROP_BYTES)
44 t->prop[i] = prop[i];
45}
46
47static void finalize_frame(struct touch_frame *frame, touch_time_t time)
48{
49 int i, nslot = 0;
50 grail_mask_foreach(i, frame->touches, DIM_TOUCH_BYTES)
51 frame->active[nslot++] = &frame->touch[i];
52 frame->nactive = nslot;
53 frame->time = time;
54}
55
56static void tp_create(struct touch_dev *dev, int slot,
57 const grail_mask_t *mask, const touch_prop_t *prop)
58{
59 struct touch_engine *engine = dev->priv;
60 if (engine) {
61 engine->frame.ncreate++;
62 update_frame(&engine->frame, slot, 1, mask, prop);
63 }
64}
65
66static void tp_modify(struct touch_dev *dev, int slot,
67 const grail_mask_t *mask, const touch_prop_t *prop)
68{
69 struct touch_engine *engine = dev->priv;
70 if (engine) {
71 engine->frame.nmodify++;
72 update_frame(&engine->frame, slot, 1, mask, prop);
73 }
74}
75
76static void tp_destroy(struct touch_dev *dev, int slot)
77{
78 struct touch_engine *engine = dev->priv;
79 if (engine) {
80 engine->frame.ndestroy++;
81 update_frame(&engine->frame, slot, 0, 0, 0);
82 }
83}
84
85static void tp_sync(struct touch_dev *dev, const struct input_event *syn)
86{
87 static const touch_time_t ms = 1000;
88 struct touch_engine *engine = dev->priv;
89 touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
90 if (engine) {
91 finalize_frame(&engine->frame, time);
92 if (engine->sync)
93 engine->sync(engine, syn);
94 engine->frame.ncreate = 0;
95 engine->frame.nmodify = 0;
96 engine->frame.ndestroy = 0;
97 }
98}
99
100void touch_engine_init(struct touch_engine *engine,
101 void (*event)(struct touch_engine *engine,
102 const struct input_event *ev),
103 void (*sync)(struct touch_engine *engine,
104 const struct input_event *ev),
105 void *priv)
106{
107 int i;
108 memset(engine, 0, sizeof(*engine));
109 for (i = 0; i < DIM_TOUCH; i++)
110 engine->frame.touch[i].slot = i;
111 engine->event = event;
112 engine->sync = sync;
113 engine->priv = priv;
114}
115
116void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev)
117{
118 dev->priv = engine;
119 dev->event = tp_event;
120 dev->create = tp_create;
121 dev->modify = tp_modify;
122 dev->destroy = tp_destroy;
123 dev->sync = tp_sync;
124}
125
126void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev)
127{
128 dev->sync = 0;
129 dev->destroy = 0;
130 dev->modify = 0;
131 dev->create = 0;
132 dev->event = 0;
133 dev->priv = 0;
134}
135