From: Peter Hutterer Date: Fri, 14 Feb 2014 04:18:27 +0000 (+1000) Subject: touchpad: support single-touch touchpads X-Git-Tag: 0.2.0~50^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=efc8d9517116acf4f5883dfe9698ca0bd7286ad0;p=platform%2Fupstream%2Flibinput.git touchpad: support single-touch touchpads Touchpads without ABS_MT_SLOT create 5 slots by default (for up to QUINTTAP) and ABS_X/Y is mapped to the 0-slot touchpoint. This commit adds handling for a single finger, no BTN_TOOL_DOUBLETAP or similar is being processed yet. Signed-off-by: Peter Hutterer --- diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index c4c4c41..07de481 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -226,6 +226,28 @@ tp_process_absolute(struct tp_dispatch *tp, } static void +tp_process_absolute_st(struct tp_dispatch *tp, + const struct input_event *e, + uint32_t time) +{ + struct tp_touch *t = tp_current_touch(tp); + + switch(e->code) { + case ABS_X: + t->x = e->value; + t->millis = time; + t->dirty = true; + break; + case ABS_Y: + t->y = e->value; + t->millis = time; + t->dirty = true; + tp->queued |= TOUCHPAD_EVENT_MOTION; + break; + } +} + +static void tp_process_key(struct tp_dispatch *tp, const struct input_event *e, uint32_t time) @@ -245,6 +267,18 @@ tp_process_key(struct tp_dispatch *tp, tp->queued |= TOUCHPAD_EVENT_BUTTON_RELEASE; } break; + case BTN_TOUCH: + if (!tp->has_mt) { + struct tp_touch *t = tp_current_touch(tp); + if (e->value) { + tp_begin_touch(tp, t); + t->fake = true; + } else { + tp_end_touch(tp, t); + } + t->millis = time; + } + break; } } @@ -271,9 +305,10 @@ tp_post_process_state(struct tp_dispatch *tp, uint32_t time) if (!t->dirty) continue; - if (t->state == TOUCH_END) + if (t->state == TOUCH_END) { t->state = TOUCH_NONE; - else if (t->state == TOUCH_BEGIN) + t->fake = false; + } else if (t->state == TOUCH_BEGIN) t->state = TOUCH_UPDATE; t->dirty = false; @@ -443,7 +478,10 @@ tp_process(struct evdev_dispatch *dispatch, switch (e->type) { case EV_ABS: - tp_process_absolute(tp, e, time); + if (tp->has_mt) + tp_process_absolute(tp, e, time); + else + tp_process_absolute_st(tp, e, time); break; case EV_KEY: tp_process_key(tp, e, time); @@ -477,14 +515,20 @@ static int tp_init_slots(struct tp_dispatch *tp, struct evdev_device *device) { - struct input_absinfo absinfo = {0}; - - ioctl(device->fd, EVIOCGABS(ABS_MT_SLOT), &absinfo); + const struct input_absinfo *absinfo; - tp->ntouches = absinfo.maximum + 1; + absinfo = libevdev_get_abs_info(device->evdev, ABS_MT_SLOT); + if (absinfo) { + tp->ntouches = absinfo->maximum + 1; + tp->slot = absinfo->value; + tp->has_mt = true; + } else { + tp->ntouches = 5; /* FIXME: based on DOUBLETAP, etc. */ + tp->slot = 0; + tp->has_mt = false; + } tp->touches = calloc(tp->ntouches, sizeof(struct tp_touch)); - tp->slot = absinfo.value; return 0; } diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 17e9055..1e09497 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -75,6 +75,7 @@ struct tp_motion { struct tp_touch { enum touch_state state; bool dirty; + bool fake; /* a fake touch */ int32_t x; int32_t y; uint32_t millis; @@ -96,6 +97,7 @@ struct tp_dispatch { struct evdev_device *device; unsigned int nfingers_down; /* number of fingers down */ unsigned int slot; /* current slot */ + bool has_mt; unsigned int ntouches; /* number of slots */ struct tp_touch *touches; /* len == ntouches */