summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-07-20 15:39:08 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commiteb896e11aacab5f53e3915a8d19ffffd92ce8e10 (patch)
treea2b12258c1697e61854704a0eff14070bc9fa963
parent3b9c20f869a2f55bd9953665c9e7fd713db4ff43 (diff)
Touch API changes
Add touch time to the touch frame (Thanks Rafi) Add touch change counters to the touch frame Add event bypass callback Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
-rw-r--r--include/grail-touch.h24
-rw-r--r--src/touch-engine.c31
-rw-r--r--test/grail.c11
-rw-r--r--test/touch.c12
4 files changed, 55 insertions, 23 deletions
diff --git a/include/grail-touch.h b/include/grail-touch.h
index d6c9bf5..9e8572b 100644
--- a/include/grail-touch.h
+++ b/include/grail-touch.h
@@ -52,6 +52,14 @@ struct touch {
52 touch_prop_t prop[DIM_TOUCH_PROP]; 52 touch_prop_t prop[DIM_TOUCH_PROP];
53}; 53};
54 54
55struct touch_frame {
56 int ntouch;
57 int slot;
58 int ncreate, nmodify, ndestroy;
59 touch_time_t time;
60 struct touch touch[DIM_TOUCHES];
61};
62
55struct touch_dev { 63struct touch_dev {
56 void (*event)(struct touch_dev *dev, const struct input_event *ev); 64 void (*event)(struct touch_dev *dev, const struct input_event *ev);
57 void (*create)(struct touch_dev *dev, int slot, 65 void (*create)(struct touch_dev *dev, int slot,
@@ -64,14 +72,10 @@ struct touch_dev {
64 void *priv; 72 void *priv;
65}; 73};
66 74
67struct touch_frame {
68 int ntouch;
69 int slot;
70 struct touch touch[DIM_TOUCHES];
71};
72
73struct touch_engine { 75struct touch_engine {
74 void (*sync)(struct touch_engine *engine, touch_time_t time); 76 void (*event)(struct touch_engine *engine,
77 const struct input_event *ev);
78 void (*sync)(struct touch_engine *engine);
75 struct touch_frame frame; 79 struct touch_frame frame;
76 void *priv; 80 void *priv;
77}; 81};
@@ -92,9 +96,11 @@ int touch_dev_pull(struct touch_dev *dev, int fd);
92void touch_dev_close(struct touch_dev *dev, int fd); 96void touch_dev_close(struct touch_dev *dev, int fd);
93 97
94void touch_engine_init(struct touch_engine *engine, 98void touch_engine_init(struct touch_engine *engine,
95 void (*sync)(struct touch_engine *engine, 99 void (*event)(struct touch_engine *engine,
96 touch_time_t time), 100 const struct input_event *ev),
101 void (*sync)(struct touch_engine *engine),
97 void *priv); 102 void *priv);
98void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev); 103void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev);
104void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev);
99 105
100#endif 106#endif
diff --git a/src/touch-engine.c b/src/touch-engine.c
index a3830a9..6174e0d 100644
--- a/src/touch-engine.c
+++ b/src/touch-engine.c
@@ -27,6 +27,9 @@
27 27
28static void tp_event(struct touch_dev *dev, const struct input_event *ev) 28static void tp_event(struct touch_dev *dev, const struct input_event *ev)
29{ 29{
30 struct touch_engine *engine = dev->priv;
31 if (engine && engine->event)
32 engine->event(engine, ev);
30} 33}
31 34
32static void update_frame(struct touch_frame *frame, 35static void update_frame(struct touch_frame *frame,
@@ -43,7 +46,7 @@ static void update_frame(struct touch_frame *frame,
43 } 46 }
44} 47}
45 48
46static void finalize_frame(struct touch_frame *frame) 49static void finalize_frame(struct touch_frame *frame, touch_time_t time)
47{ 50{
48 int last = -1; 51 int last = -1;
49 frame->ntouch = 0; 52 frame->ntouch = 0;
@@ -59,47 +62,59 @@ static void finalize_frame(struct touch_frame *frame)
59 frame->ntouch++; 62 frame->ntouch++;
60 } 63 }
61 } 64 }
65 frame->time = time;
62} 66}
63 67
64static void tp_create(struct touch_dev *dev, int slot, 68static void tp_create(struct touch_dev *dev, int slot,
65 const touch_prop_mask_t *mask, const touch_prop_t *prop) 69 const touch_prop_mask_t *mask, const touch_prop_t *prop)
66{ 70{
67 struct touch_engine *engine = dev->priv; 71 struct touch_engine *engine = dev->priv;
68 if (engine) 72 if (engine) {
73 engine->frame.ncreate++;
69 update_frame(&engine->frame, slot, 1, mask, prop); 74 update_frame(&engine->frame, slot, 1, mask, prop);
75 }
70} 76}
71 77
72static void tp_modify(struct touch_dev *dev, int slot, 78static void tp_modify(struct touch_dev *dev, int slot,
73 const touch_prop_mask_t *mask, const touch_prop_t *prop) 79 const touch_prop_mask_t *mask, const touch_prop_t *prop)
74{ 80{
75 struct touch_engine *engine = dev->priv; 81 struct touch_engine *engine = dev->priv;
76 if (engine) 82 if (engine) {
83 engine->frame.nmodify++;
77 update_frame(&engine->frame, slot, 1, mask, prop); 84 update_frame(&engine->frame, slot, 1, mask, prop);
85 }
78} 86}
79 87
80static void tp_destroy(struct touch_dev *dev, int slot) 88static void tp_destroy(struct touch_dev *dev, int slot)
81{ 89{
82 struct touch_engine *engine = dev->priv; 90 struct touch_engine *engine = dev->priv;
83 if (engine) 91 if (engine) {
92 engine->frame.ndestroy++;
84 update_frame(&engine->frame, slot, 0, 0, 0); 93 update_frame(&engine->frame, slot, 0, 0, 0);
94 }
85} 95}
86 96
87static void tp_sync(struct touch_dev *dev, touch_time_t time) 97static void tp_sync(struct touch_dev *dev, touch_time_t time)
88{ 98{
89 struct touch_engine *engine = dev->priv; 99 struct touch_engine *engine = dev->priv;
90 if (engine) { 100 if (engine) {
91 finalize_frame(&engine->frame); 101 finalize_frame(&engine->frame, time);
92 if (engine->sync) 102 if (engine->sync)
93 engine->sync(engine, time); 103 engine->sync(engine);
104 engine->frame.ncreate = 0;
105 engine->frame.nmodify = 0;
106 engine->frame.ndestroy = 0;
94 } 107 }
95} 108}
96 109
97void touch_engine_init(struct touch_engine *engine, 110void touch_engine_init(struct touch_engine *engine,
98 void (*sync)(struct touch_engine *engine, 111 void (*event)(struct touch_engine *engine,
99 touch_time_t time), 112 const struct input_event *ev),
113 void (*sync)(struct touch_engine *engine),
100 void *priv) 114 void *priv)
101{ 115{
102 memset(engine, 0, sizeof(*engine)); 116 memset(engine, 0, sizeof(*engine));
117 engine->event = event;
103 engine->sync = sync; 118 engine->sync = sync;
104 engine->priv = priv; 119 engine->priv = priv;
105} 120}
diff --git a/test/grail.c b/test/grail.c
index 3fe20ee..82de65f 100644
--- a/test/grail.c
+++ b/test/grail.c
@@ -128,11 +128,16 @@ static void gh_destroy(struct gesture_handler *gh)
128 gedev_destroy(&gh->dev); 128 gedev_destroy(&gh->dev);
129} 129}
130 130
131static void tp_sync(struct touch_engine *engine, touch_time_t time) 131static void tp_event(struct touch_engine *engine,
132 const struct input_event *ev)
133{
134}
135
136static void tp_sync(struct touch_engine *engine)
132{ 137{
133 struct gesture_handler *gh = engine->priv; 138 struct gesture_handler *gh = engine->priv;
134 struct touch_frame *frame = &engine->frame; 139 struct touch_frame *frame = &engine->frame;
135 gh_handle(gh, frame, time); 140 gh_handle(gh, frame, frame->time);
136} 141}
137 142
138static void loop_device(struct touch_dev *dev, int fd) 143static void loop_device(struct touch_dev *dev, int fd)
@@ -140,7 +145,7 @@ static void loop_device(struct touch_dev *dev, int fd)
140 struct gesture_handler gh; 145 struct gesture_handler gh;
141 struct touch_engine engine; 146 struct touch_engine engine;
142 gh_init(&gh); 147 gh_init(&gh);
143 touch_engine_init(&engine, tp_sync, &gh); 148 touch_engine_init(&engine, tp_event, tp_sync, &gh);
144 touch_engine_attach(&engine, dev); 149 touch_engine_attach(&engine, dev);
145 while (!touch_dev_idle(dev, fd, 5000)) 150 while (!touch_dev_idle(dev, fd, 5000))
146 touch_dev_pull(dev, fd); 151 touch_dev_pull(dev, fd);
diff --git a/test/touch.c b/test/touch.c
index 48b2f12..1f9213d 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -28,11 +28,17 @@
28#include <unistd.h> 28#include <unistd.h>
29#include <fcntl.h> 29#include <fcntl.h>
30 30
31static void tp_sync(struct touch_engine *engine, touch_time_t time) 31static void tp_event(struct touch_engine *engine,
32 const struct input_event *ev)
33{
34 fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value);
35}
36
37static void tp_sync(struct touch_engine *engine)
32{ 38{
33 struct touch_frame *frame = &engine->frame; 39 struct touch_frame *frame = &engine->frame;
34 int slot, i; 40 int slot, i;
35 fprintf(stderr, "sync %d %lld\n", frame->ntouch, time); 41 fprintf(stderr, "sync %d %lld\n", frame->ntouch, frame->time);
36 for (slot = frame->slot; slot >= 0; slot = next_slot(frame, slot)) { 42 for (slot = frame->slot; slot >= 0; slot = next_slot(frame, slot)) {
37 struct touch *touch = &frame->touch[slot]; 43 struct touch *touch = &frame->touch[slot];
38 fprintf(stderr, "touch %d\n", slot); 44 fprintf(stderr, "touch %d\n", slot);
@@ -44,7 +50,7 @@ static void tp_sync(struct touch_engine *engine, touch_time_t time)
44static void loop_device(struct touch_dev *dev, int fd) 50static void loop_device(struct touch_dev *dev, int fd)
45{ 51{
46 struct touch_engine engine; 52 struct touch_engine engine;
47 touch_engine_init(&engine, tp_sync, 0); 53 touch_engine_init(&engine, tp_event, tp_sync, 0);
48 touch_engine_attach(&engine, dev); 54 touch_engine_attach(&engine, dev);
49 while (!touch_dev_idle(dev, fd, 5000)) 55 while (!touch_dev_idle(dev, fd, 5000))
50 touch_dev_pull(dev, fd); 56 touch_dev_pull(dev, fd);