From 4c0b8ba4c2b3eab439921429ec8334d486c30735 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 28 Apr 2017 13:52:07 +1000 Subject: touchpad: send multitap button events with the correct timestamps For multitap, we're one tap behind with the button clicks, i.e. we send the first full click button on the second tap, etc. Remember the timestamps of the touches so we can send the events with the right timestamps. This makes tapping more accurate because the time between taps and various timeouts matter less for double-click detection. Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad-tap.c | 58 +++++++++++++++++++++++++++++++++++---------- src/evdev-mt-touchpad.h | 3 ++- 2 files changed, 47 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c index 6c989d9..882b4cf 100644 --- a/src/evdev-mt-touchpad-tap.c +++ b/src/evdev-mt-touchpad-tap.c @@ -152,7 +152,7 @@ tp_tap_idle_handle_event(struct tp_dispatch *tp, switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_TOUCH; - tp->tap.first_press_time = time; + tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: @@ -186,11 +186,12 @@ tp_tap_touch_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_RELEASE: tp_tap_notify(tp, - tp->tap.first_press_time, + tp->tap.saved_press_time, 1, LIBINPUT_BUTTON_STATE_PRESSED); if (tp->tap.drag_enabled) { tp->tap.state = TAP_STATE_TAPPED; + tp->tap.saved_release_time = time; tp_tap_set_timer(tp, time); } else { tp_tap_notify(tp, @@ -258,15 +259,22 @@ tp_tap_tapped_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_DRAGGING_OR_DOUBLETAP; + tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_IDLE; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: break; @@ -342,7 +350,7 @@ tp_tap_touch2_release_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_RELEASE: tp_tap_notify(tp, - tp->tap.first_press_time, + tp->tap.saved_press_time, 2, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, time, 2, LIBINPUT_BUTTON_STATE_RELEASED); @@ -380,7 +388,7 @@ tp_tap_touch3_handle_event(struct tp_dispatch *tp, tp->tap.state = TAP_STATE_TOUCH_2_HOLD; if (t->tap.state == TAP_TOUCH_STATE_TOUCH) { tp_tap_notify(tp, - tp->tap.first_press_time, + tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, time, 3, LIBINPUT_BUTTON_STATE_RELEASED); @@ -430,7 +438,11 @@ tp_tap_dragging_or_doubletap_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_MULTITAP; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + tp->tap.saved_release_time = time; break; case TAP_EVENT_MOTION: case TAP_EVENT_TIMEOUT: @@ -438,7 +450,10 @@ tp_tap_dragging_or_doubletap_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: break; @@ -574,7 +589,11 @@ tp_tap_multitap_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_MULTITAP_DOWN; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_PRESSED); + tp_tap_notify(tp, + tp->tap.saved_press_time, + 1, + LIBINPUT_BUTTON_STATE_PRESSED); + tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_MOTION: @@ -583,8 +602,14 @@ tp_tap_multitap_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_IDLE; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_PRESSED); - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_notify(tp, + tp->tap.saved_press_time, + 1, + LIBINPUT_BUTTON_STATE_PRESSED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_IDLE; @@ -604,7 +629,11 @@ tp_tap_multitap_down_handle_event(struct tp_dispatch *tp, switch (event) { case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_MULTITAP; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + tp->tap.saved_release_time = time; break; case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_DRAGGING_2; @@ -617,7 +646,10 @@ tp_tap_multitap_down_handle_event(struct tp_dispatch *tp, break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; - tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); tp_tap_clear_timer(tp); break; case TAP_EVENT_THUMB: diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 8d5bbc4..304e92f 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -321,7 +321,8 @@ struct tp_dispatch { struct libinput_timer timer; enum tp_tap_state state; uint32_t buttons_pressed; - uint64_t first_press_time; + uint64_t saved_press_time, + saved_release_time; enum libinput_config_tap_button_map map; enum libinput_config_tap_button_map want_map; -- cgit v1.2.3