From eb896e11aacab5f53e3915a8d19ffffd92ce8e10 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Tue, 20 Jul 2010 15:39:08 +0200 Subject: 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 --- include/grail-touch.h | 24 +++++++++++++++--------- src/touch-engine.c | 31 +++++++++++++++++++++++-------- test/grail.c | 11 ++++++++--- test/touch.c | 12 +++++++++--- 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 { touch_prop_t prop[DIM_TOUCH_PROP]; }; +struct touch_frame { + int ntouch; + int slot; + int ncreate, nmodify, ndestroy; + touch_time_t time; + struct touch touch[DIM_TOUCHES]; +}; + struct touch_dev { void (*event)(struct touch_dev *dev, const struct input_event *ev); void (*create)(struct touch_dev *dev, int slot, @@ -64,14 +72,10 @@ struct touch_dev { void *priv; }; -struct touch_frame { - int ntouch; - int slot; - struct touch touch[DIM_TOUCHES]; -}; - struct touch_engine { - void (*sync)(struct touch_engine *engine, touch_time_t time); + void (*event)(struct touch_engine *engine, + const struct input_event *ev); + void (*sync)(struct touch_engine *engine); struct touch_frame frame; void *priv; }; @@ -92,9 +96,11 @@ int touch_dev_pull(struct touch_dev *dev, int fd); void touch_dev_close(struct touch_dev *dev, int fd); void touch_engine_init(struct touch_engine *engine, - void (*sync)(struct touch_engine *engine, - touch_time_t time), + void (*event)(struct touch_engine *engine, + const struct input_event *ev), + void (*sync)(struct touch_engine *engine), void *priv); void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev); +void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev); #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 @@ static void tp_event(struct touch_dev *dev, const struct input_event *ev) { + struct touch_engine *engine = dev->priv; + if (engine && engine->event) + engine->event(engine, ev); } static void update_frame(struct touch_frame *frame, @@ -43,7 +46,7 @@ static void update_frame(struct touch_frame *frame, } } -static void finalize_frame(struct touch_frame *frame) +static void finalize_frame(struct touch_frame *frame, touch_time_t time) { int last = -1; frame->ntouch = 0; @@ -59,47 +62,59 @@ static void finalize_frame(struct touch_frame *frame) frame->ntouch++; } } + frame->time = time; } static void tp_create(struct touch_dev *dev, int slot, const touch_prop_mask_t *mask, const touch_prop_t *prop) { struct touch_engine *engine = dev->priv; - if (engine) + if (engine) { + engine->frame.ncreate++; update_frame(&engine->frame, slot, 1, mask, prop); + } } static void tp_modify(struct touch_dev *dev, int slot, const touch_prop_mask_t *mask, const touch_prop_t *prop) { struct touch_engine *engine = dev->priv; - if (engine) + if (engine) { + engine->frame.nmodify++; update_frame(&engine->frame, slot, 1, mask, prop); + } } static void tp_destroy(struct touch_dev *dev, int slot) { struct touch_engine *engine = dev->priv; - if (engine) + if (engine) { + engine->frame.ndestroy++; update_frame(&engine->frame, slot, 0, 0, 0); + } } static void tp_sync(struct touch_dev *dev, touch_time_t time) { struct touch_engine *engine = dev->priv; if (engine) { - finalize_frame(&engine->frame); + finalize_frame(&engine->frame, time); if (engine->sync) - engine->sync(engine, time); + engine->sync(engine); + engine->frame.ncreate = 0; + engine->frame.nmodify = 0; + engine->frame.ndestroy = 0; } } void touch_engine_init(struct touch_engine *engine, - void (*sync)(struct touch_engine *engine, - touch_time_t time), + void (*event)(struct touch_engine *engine, + const struct input_event *ev), + void (*sync)(struct touch_engine *engine), void *priv) { memset(engine, 0, sizeof(*engine)); + engine->event = event; engine->sync = sync; engine->priv = priv; } 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) gedev_destroy(&gh->dev); } -static void tp_sync(struct touch_engine *engine, touch_time_t time) +static void tp_event(struct touch_engine *engine, + const struct input_event *ev) +{ +} + +static void tp_sync(struct touch_engine *engine) { struct gesture_handler *gh = engine->priv; struct touch_frame *frame = &engine->frame; - gh_handle(gh, frame, time); + gh_handle(gh, frame, frame->time); } static void loop_device(struct touch_dev *dev, int fd) @@ -140,7 +145,7 @@ static void loop_device(struct touch_dev *dev, int fd) struct gesture_handler gh; struct touch_engine engine; gh_init(&gh); - touch_engine_init(&engine, tp_sync, &gh); + touch_engine_init(&engine, tp_event, tp_sync, &gh); touch_engine_attach(&engine, dev); while (!touch_dev_idle(dev, fd, 5000)) 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 @@ #include #include -static void tp_sync(struct touch_engine *engine, touch_time_t time) +static void tp_event(struct touch_engine *engine, + const struct input_event *ev) +{ + fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value); +} + +static void tp_sync(struct touch_engine *engine) { struct touch_frame *frame = &engine->frame; int slot, i; - fprintf(stderr, "sync %d %lld\n", frame->ntouch, time); + fprintf(stderr, "sync %d %lld\n", frame->ntouch, frame->time); for (slot = frame->slot; slot >= 0; slot = next_slot(frame, slot)) { struct touch *touch = &frame->touch[slot]; fprintf(stderr, "touch %d\n", slot); @@ -44,7 +50,7 @@ static void tp_sync(struct touch_engine *engine, touch_time_t time) static void loop_device(struct touch_dev *dev, int fd) { struct touch_engine engine; - touch_engine_init(&engine, tp_sync, 0); + touch_engine_init(&engine, tp_event, tp_sync, 0); touch_engine_attach(&engine, dev); while (!touch_dev_idle(dev, fd, 5000)) touch_dev_pull(dev, fd); -- cgit v1.2.3