[PATCH libinput 3/3] touchpad: for 2/3-finger tap, use the last finger down as press time

Peter Hutterer peter.hutterer at who-t.net
Fri Apr 28 06:00:27 UTC 2017


This makes the tapping times shorter and hopefully more obvious. It also fixes
a bug where repeated tripletap (by tapping with one finger while leaving the
other two down) could cause incorrect timestamps.

https://bugs.freedesktop.org/show_bug.cgi?id=100796

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad-tap.c | 10 +++++++-
 test/test-touchpad-tap.c    | 56 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c
index 882b4cf..5a237fe 100644
--- a/src/evdev-mt-touchpad-tap.c
+++ b/src/evdev-mt-touchpad-tap.c
@@ -182,6 +182,7 @@ tp_tap_touch_handle_event(struct tp_dispatch *tp,
 	switch (event) {
 	case TAP_EVENT_TOUCH:
 		tp->tap.state = TAP_STATE_TOUCH_2;
+		tp->tap.saved_press_time = time;
 		tp_tap_set_timer(tp, time);
 		break;
 	case TAP_EVENT_RELEASE:
@@ -227,6 +228,7 @@ tp_tap_hold_handle_event(struct tp_dispatch *tp,
 	switch (event) {
 	case TAP_EVENT_TOUCH:
 		tp->tap.state = TAP_STATE_TOUCH_2;
+		tp->tap.saved_press_time = time;
 		tp_tap_set_timer(tp, time);
 		break;
 	case TAP_EVENT_RELEASE:
@@ -290,10 +292,12 @@ tp_tap_touch2_handle_event(struct tp_dispatch *tp,
 	switch (event) {
 	case TAP_EVENT_TOUCH:
 		tp->tap.state = TAP_STATE_TOUCH_3;
+		tp->tap.saved_press_time = time;
 		tp_tap_set_timer(tp, time);
 		break;
 	case TAP_EVENT_RELEASE:
 		tp->tap.state = TAP_STATE_TOUCH_2_RELEASE;
+		tp->tap.saved_release_time = time;
 		tp_tap_set_timer(tp, time);
 		break;
 	case TAP_EVENT_MOTION:
@@ -319,6 +323,7 @@ tp_tap_touch2_hold_handle_event(struct tp_dispatch *tp,
 	switch (event) {
 	case TAP_EVENT_TOUCH:
 		tp->tap.state = TAP_STATE_TOUCH_3;
+		tp->tap.saved_press_time = time;
 		tp_tap_set_timer(tp, time);
 		break;
 	case TAP_EVENT_RELEASE:
@@ -353,7 +358,10 @@ tp_tap_touch2_release_handle_event(struct tp_dispatch *tp,
 			      tp->tap.saved_press_time,
 			      2,
 			      LIBINPUT_BUTTON_STATE_PRESSED);
-		tp_tap_notify(tp, time, 2, LIBINPUT_BUTTON_STATE_RELEASED);
+		tp_tap_notify(tp,
+			      tp->tap.saved_release_time,
+			      2,
+			      LIBINPUT_BUTTON_STATE_RELEASED);
 		tp->tap.state = TAP_STATE_IDLE;
 		break;
 	case TAP_EVENT_MOTION:
diff --git a/test/test-touchpad-tap.c b/test/test-touchpad-tap.c
index 021ccaa..d7b39ef 100644
--- a/test/test-touchpad-tap.c
+++ b/test/test-touchpad-tap.c
@@ -1469,8 +1469,11 @@ START_TEST(touchpad_3fg_tap)
 		litest_drain_events(li);
 
 		litest_touch_down(dev, 0, 50, 50);
+		msleep(5);
 		litest_touch_down(dev, 1, 70, 50);
+		msleep(5);
 		litest_touch_down(dev, 2, 80, 50);
+		msleep(10);
 
 		litest_touch_up(dev, (i + 2) % 3);
 		litest_touch_up(dev, (i + 1) % 3);
@@ -1497,6 +1500,58 @@ START_TEST(touchpad_3fg_tap)
 }
 END_TEST
 
+START_TEST(touchpad_3fg_tap_tap_again)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	int i;
+
+	if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) <= 2)
+		return;
+
+	litest_enable_tap(dev->libinput_device);
+
+	uint64_t ptime, rtime;
+	struct libinput_event *ev;
+	struct libinput_event_pointer *ptrev;
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 50, 50);
+	msleep(5);
+	litest_touch_down(dev, 1, 70, 50);
+	msleep(5);
+	litest_touch_down(dev, 2, 80, 50);
+	msleep(10);
+	litest_touch_up(dev, 0);
+	msleep(10);
+	litest_touch_down(dev, 0, 80, 50);
+	msleep(10);
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	litest_touch_up(dev, 2);
+
+	libinput_dispatch(li);
+
+	for (i = 0; i < 2; i++) {
+		ev = libinput_get_event(li);
+		ptrev = litest_is_button_event(ev,
+					       BTN_MIDDLE,
+					       LIBINPUT_BUTTON_STATE_PRESSED);
+		ptime = libinput_event_pointer_get_time_usec(ptrev);
+		libinput_event_destroy(ev);
+		ev = libinput_get_event(li);
+		ptrev = litest_is_button_event(ev,
+					       BTN_MIDDLE,
+					       LIBINPUT_BUTTON_STATE_RELEASED);
+		rtime = libinput_event_pointer_get_time_usec(ptrev);
+		libinput_event_destroy(ev);
+
+		ck_assert_int_lt(ptime, rtime);
+	}
+}
+END_TEST
+
 START_TEST(touchpad_3fg_tap_quickrelease)
 {
 	struct litest_device *dev = litest_current_device();
@@ -2306,6 +2361,7 @@ litest_setup_tests_touchpad_tap(void)
 	litest_add_ranged("tap-3fg:3fg", touchpad_3fg_tap_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &tap_map_range);
 	litest_add_ranged("tap-3fg:3fg", touchpad_3fg_tap_btntool_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &tap_map_range);
 	litest_add_ranged("tap-3fg:3fg", touchpad_3fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &tap_map_range);
+	litest_add("tap-3fg:3fg", touchpad_3fg_tap_tap_again, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
 	litest_add("tap-3fg:3fg", touchpad_3fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
 	litest_add("tap-4fg:4fg", touchpad_4fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
 	litest_add("tap-4fg:4fg", touchpad_4fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
-- 
2.9.3



More information about the wayland-devel mailing list