From 1f656f12cf1c208b035f676474c5a3c0a712331a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 7 Feb 2014 13:59:38 +1000 Subject: [PATCH] touchpad: add a struct for handling physical button event state changes On ClickPads (touchpads without phys. middle/right buttons) it is important to know whether a physical click is queued up. The finger position or number of fingers decide which button event to send. This isn't currently used, we still just send the button number at the moment. Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 54 ++++++++++++++++++++++++++++++++++++----- src/evdev-mt-touchpad.h | 5 ++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 1d34df88..e25997df 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -230,16 +230,20 @@ tp_process_key(struct tp_dispatch *tp, const struct input_event *e, uint32_t time) { + uint32_t mask; + switch (e->code) { case BTN_LEFT: case BTN_MIDDLE: case BTN_RIGHT: - pointer_notify_button( - &tp->device->base, - time, - e->code, - e->value ? LIBINPUT_POINTER_BUTTON_STATE_PRESSED : - LIBINPUT_POINTER_BUTTON_STATE_RELEASED); + mask = 1 << (e->code - BTN_LEFT); + if (e->value) { + tp->buttons.state |= mask; + tp->queued |= TOUCHPAD_EVENT_BUTTON_PRESS; + } else { + tp->buttons.state &= ~mask; + tp->queued |= TOUCHPAD_EVENT_BUTTON_RELEASE; + } break; } } @@ -275,6 +279,8 @@ tp_post_process_state(struct tp_dispatch *tp, uint32_t time) t->dirty = false; } + tp->buttons.old_state = tp->buttons.state; + tp->queued = TOUCHPAD_EVENT_NONE; } @@ -316,6 +322,40 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint32_t time) li_fixed_from_double(dy)); } +static void +tp_post_button_events(struct tp_dispatch *tp, uint32_t time) +{ + uint32_t current, old, button; + + if ((tp->queued & + (TOUCHPAD_EVENT_BUTTON_PRESS|TOUCHPAD_EVENT_BUTTON_RELEASE)) == 0) + return; + + current = tp->buttons.state; + old = tp->buttons.old_state; + button = BTN_LEFT; + + while (current || old) { + enum libinput_pointer_button_state state; + + if ((current & 0x1) ^ (old & 0x1)) { + if (!!(current & 0x1)) + state = LIBINPUT_POINTER_BUTTON_STATE_PRESSED; + else + state = LIBINPUT_POINTER_BUTTON_STATE_RELEASED; + + pointer_notify_button(&tp->device->base, + time, + button, + state); + } + + button++; + current >>= 1; + old >>= 1; + } +} + static void tp_post_events(struct tp_dispatch *tp, uint32_t time) { @@ -342,6 +382,8 @@ tp_post_events(struct tp_dispatch *tp, uint32_t time) time, li_fixed_from_double(dx), li_fixed_from_double(dy)); + + tp_post_button_events(tp, time); } static void diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 52ad3ab0..d12647de 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -91,6 +91,11 @@ struct tp_dispatch { double max_factor; } accel; + struct { + uint32_t state; + uint32_t old_state; + } buttons; /* physical buttons */ + enum touchpad_event queued; }; -- 2.34.1