From a704984e03d28b4be40e12c43be1b163bc9e09e2 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Thu, 19 Aug 2010 20:03:15 +0200 Subject: 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 --- src/touch-dev.c | 164 ++++++++++++++++++++++---------------------------------- 1 file changed, 64 insertions(+), 100 deletions(-) (limited to 'src/touch-dev.c') diff --git a/src/touch-dev.c b/src/touch-dev.c index b88cb8d..287076a 100644 --- a/src/touch-dev.c +++ b/src/touch-dev.c @@ -25,128 +25,97 @@ #include #include -/* from mtdev-mapping.h */ -#define MT_TOUCH_MAJOR 0 -#define MT_TOUCH_MINOR 1 -#define MT_WIDTH_MAJOR 2 -#define MT_WIDTH_MINOR 3 -#define MT_ORIENTATION 4 -#define MT_POSITION_X 5 -#define MT_POSITION_Y 6 -#define MT_TRACKING_ID 9 -#define MT_PRESSURE 10 - -struct touch_dev_impl { - int id[DIM_TOUCH]; - int slot; - int status; - grail_mask_t mask[DIM_TOUCH_BYTES]; - touch_prop_t prop[DIM_TOUCH_PROP]; - struct mtdev mtdev; -}; - -static inline void set_info(struct touch_dev_caps *caps, int code, - const struct input_absinfo *info) -{ - grail_mask_set(caps->mask, code); - caps->info[code] = *info; -} - -static void set_caps(struct touch_dev_caps *caps, - const struct mtdev_caps *mtcaps) -{ - if (mtcaps->has_abs[MT_POSITION_X]) - set_info(caps, TP_POS_X, &mtcaps->abs[MT_POSITION_X]); - if (mtcaps->has_abs[MT_POSITION_Y]) - set_info(caps, TP_POS_Y, &mtcaps->abs[MT_POSITION_Y]); - if (mtcaps->has_abs[MT_TOUCH_MAJOR]) - set_info(caps, TP_TOUCH_MAJOR, &mtcaps->abs[MT_TOUCH_MAJOR]); - if (mtcaps->has_abs[MT_TOUCH_MINOR]) - set_info(caps, TP_TOUCH_MINOR, &mtcaps->abs[MT_TOUCH_MINOR]); - if (mtcaps->has_abs[MT_WIDTH_MAJOR]) - set_info(caps, TP_WIDTH_MAJOR, &mtcaps->abs[MT_WIDTH_MAJOR]); - if (mtcaps->has_abs[MT_WIDTH_MINOR]) - set_info(caps, TP_WIDTH_MINOR, &mtcaps->abs[MT_WIDTH_MINOR]); - if (mtcaps->has_abs[MT_ORIENTATION]) - set_info(caps, TP_ORIENTATION, &mtcaps->abs[MT_ORIENTATION]); - if (mtcaps->has_abs[MT_PRESSURE]) - set_info(caps, TP_PRESSURE, &mtcaps->abs[MT_PRESSURE]); -} - -static inline void set_prop(struct touch_dev_impl *x, int code, int value) -{ - grail_mask_set(x->mask, code); - x->prop[code] = value; -} +#define SET_PROP(name, value) \ + if (t->name != value) { \ + t->name = value; \ + frame->nmodify++; \ + } -static void finish_touch(struct touch_dev *dev, - struct touch_dev_impl *x) +static void finish_touch(struct touch_dev *dev, struct touch_frame *frame) { - if (x->status < 0 && dev->destroy) - dev->destroy(dev, x->slot); - if (x->status > 0 && dev->create) - dev->create(dev, x->slot, x->mask, x->prop); - if (x->status == 0 && dev->modify && - grail_mask_count(x->mask, sizeof(x->mask))) - dev->modify(dev, x->slot, x->mask, x->prop); - x->status = 0; - memset(x->mask, 0, sizeof(x->mask)); + struct touch *t = &frame->touch[dev->slot]; + if (dev->state > 0) { + t->active = 1; + grail_mask_set(frame->touches, dev->slot); + frame->ncreate++; + } + if (dev->state < 0) { + t->active = 0; + grail_mask_clear(frame->touches, dev->slot); + frame->ndestroy++; + } + dev->state = 0; } static void finish_packet(struct touch_dev *dev, const struct input_event *syn) { - finish_touch(dev, dev->impl); + static const touch_time_t ms = 1000; + struct touch_frame *frame = &dev->frame; + int i, nslot = 0; + finish_touch(dev, frame); + grail_mask_foreach(i, frame->touches, DIM_TOUCH_BYTES) + frame->active[nslot++] = &frame->touch[i]; + frame->nactive = nslot; + frame->time = syn->time.tv_usec / ms + syn->time.tv_sec * ms; if (dev->sync) dev->sync(dev, syn); + frame->ncreate = 0; + frame->nmodify = 0; + frame->ndestroy = 0; } static int handle_abs_event(struct touch_dev *dev, const struct input_event *ev) { - struct touch_dev_impl *x = dev->impl; + struct touch_frame *frame = &dev->frame; + struct touch *t = &frame->touch[dev->slot]; switch (ev->code) { case ABS_MT_SLOT: if (ev->value >= 0 && ev->value < DIM_TOUCH) { - if (x->slot != ev->value) - finish_touch(dev, x); - x->slot = ev->value; + if (dev->slot != ev->value) + finish_touch(dev, frame); + dev->slot = ev->value; + t = &frame->touch[dev->slot]; } return 1; case ABS_MT_POSITION_X: - set_prop(x, TP_POS_X, ev->value); + SET_PROP(x, ev->value); return 1; case ABS_MT_POSITION_Y: - set_prop(x, TP_POS_Y, ev->value); + SET_PROP(y, ev->value); return 1; case ABS_MT_TOUCH_MAJOR: - set_prop(x, TP_TOUCH_MAJOR, ev->value); + SET_PROP(touch_major, ev->value); return 1; case ABS_MT_TOUCH_MINOR: - set_prop(x, TP_TOUCH_MINOR, ev->value); + SET_PROP(touch_minor, ev->value); return 1; case ABS_MT_WIDTH_MAJOR: - set_prop(x, TP_WIDTH_MAJOR, ev->value); + SET_PROP(width_major, ev->value); return 1; case ABS_MT_WIDTH_MINOR: - set_prop(x, TP_WIDTH_MINOR, ev->value); + SET_PROP(width_minor, ev->value); return 1; case ABS_MT_ORIENTATION: - set_prop(x, TP_ORIENTATION, ev->value); + SET_PROP(orientation, ev->value); return 1; case ABS_MT_PRESSURE: - set_prop(x, TP_PRESSURE, ev->value); + SET_PROP(pressure, ev->value); + return 1; + case ABS_MT_TOOL_TYPE: + SET_PROP(tool_type, ev->value); return 1; case ABS_MT_TRACKING_ID: - if (x->id[x->slot] != ev->value) { - if (x->id[x->slot] != MT_ID_NULL) { - x->status = -1; - finish_touch(dev, x); + if (t->id != ev->value) { + if (t->id != MT_ID_NULL) { + dev->state = -1; + finish_touch(dev, frame); } if (ev->value != MT_ID_NULL) - x->status = 1; + dev->state = 1; + t->id = ev->value; } - x->id[x->slot] = ev->value; return 1; default: return 0; @@ -155,38 +124,35 @@ static int handle_abs_event(struct touch_dev *dev, int touch_dev_open(struct touch_dev *dev, int fd) { - struct touch_dev_impl *x; + struct touch_frame *frame = &dev->frame; int ret, i; memset(dev, 0, sizeof(*dev)); - x = calloc(1, sizeof(*x)); - if (!x) - return -ENOMEM; - ret = mtdev_open(&x->mtdev, fd); - if (!ret && !x->mtdev.caps.has_mtdata) + for (i = 0; i < DIM_TOUCH; i++) { + struct touch *t = &frame->touch[i]; + t->slot = i; + t->id = MT_ID_NULL; + } + ret = mtdev_open(&dev->mtdev, fd); + if (!ret && !dev->mtdev.caps.has_mtdata) ret = -ENODEV; if (ret) goto error; - for (i = 0; i < DIM_TOUCH; i++) - x->id[i] = MT_ID_NULL; - set_caps(&dev->caps, &x->mtdev.caps); - dev->impl = x; + touch_caps_init(dev); return 0; error: - free(x); return ret; } int touch_dev_idle(struct touch_dev *dev, int fd, int ms) { - return mtdev_idle(&dev->impl->mtdev, fd, ms); + return mtdev_idle(&dev->mtdev, fd, ms); } int touch_dev_pull(struct touch_dev *dev, int fd) { - struct touch_dev_impl *x = dev->impl; struct input_event ev; int ret, count = 0, consumed; - while ((ret = mtdev_get(&x->mtdev, fd, &ev, 1)) > 0) { + while ((ret = mtdev_get(&dev->mtdev, fd, &ev, 1)) > 0) { consumed = 0; if (ev.type == EV_SYN) { if (ev.code == SYN_REPORT) @@ -204,8 +170,6 @@ int touch_dev_pull(struct touch_dev *dev, int fd) void touch_dev_close(struct touch_dev *dev, int fd) { - struct touch_dev_impl *x = dev->impl; - mtdev_close(&x->mtdev); - free(x); + mtdev_close(&dev->mtdev); memset(dev, 0, sizeof(*dev)); } -- cgit v1.2.3