[PATCH libinput 11/12] evdev: add "READY" state to button scrolling

Peter Hutterer peter.hutterer at who-t.net
Mon Feb 20 20:53:38 UTC 2017


Before, our states were idle, button down and scrolling. This adds a state
where the button is down and the timeout has expired (i.e. we're ready to send
scroll events) but we haven't actually sent any events anymore.

If the button is released in this state, we generate a normal click event.

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

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev.c            | 10 ++++++++--
 src/evdev.h            |  3 ++-
 test/test-pointer.c    | 16 +++++++++++++---
 test/test-trackpoint.c |  9 +++++++--
 4 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index a50d7fa..d50f9bb 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -221,7 +221,7 @@ evdev_button_scroll_timeout(uint64_t time, void *data)
 {
 	struct evdev_device *device = data;
 
-	device->scroll.button_scroll_state = BUTTONSCROLL_SCROLLING;
+	device->scroll.button_scroll_state = BUTTONSCROLL_READY;
 }
 
 static void
@@ -260,9 +260,12 @@ evdev_button_scroll_button(struct evdev_device *device,
 					 "invalid state IDLE for button up\n");
 			break;
 		case BUTTONSCROLL_BUTTON_DOWN:
+		case BUTTONSCROLL_READY:
 			log_debug(evdev_libinput_context(device),
 				  "btnscroll: cancel\n");
-			/* If the button is released quickly enough emit the
+
+			/* If the button is released quickly enough or
+			 * without scroll events, emit the
 			 * button press/release events. */
 			evdev_pointer_post_button(device,
 					device->scroll.button_down_time,
@@ -401,6 +404,9 @@ evdev_post_trackpoint_scroll(struct evdev_device *device,
 		log_debug(evdev_libinput_context(device),
 			  "btnscroll: discarding\n");
 		return true;
+	case BUTTONSCROLL_READY:
+		device->scroll.button_scroll_state = BUTTONSCROLL_SCROLLING;
+		/* fallthrough */
 	case BUTTONSCROLL_SCROLLING:
 		evdev_post_scroll(device, time,
 				  LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS,
diff --git a/src/evdev.h b/src/evdev.h
index d481d5c..392d71c 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -132,7 +132,8 @@ enum evdev_device_model {
 enum evdev_button_scroll_state {
 	BUTTONSCROLL_IDLE,
 	BUTTONSCROLL_BUTTON_DOWN,	/* button is down */
-	BUTTONSCROLL_SCROLLING,		/* scrolling */
+	BUTTONSCROLL_READY,		/* ready for scroll events */
+	BUTTONSCROLL_SCROLLING,		/* have sent scroll events */
 };
 
 struct mt_slot {
diff --git a/test/test-pointer.c b/test/test-pointer.c
index f6dae75..8498da9 100644
--- a/test/test-pointer.c
+++ b/test/test-pointer.c
@@ -1006,11 +1006,15 @@ START_TEST(pointer_scroll_button)
 	litest_button_scroll(dev, BTN_LEFT, -9, 1);
 	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9);
 
-	/* scroll smaller than the threshold should not generate events */
+	/* scroll smaller than the threshold should not generate axis events */
 	litest_button_scroll(dev, BTN_LEFT, 1, 1);
-	/* left press without movement should not generate events */
+
 	litest_button_scroll(dev, BTN_LEFT, 0, 0);
-
+	litest_assert_button_event(li, BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_PRESSED);
+	litest_assert_button_event(li,
+				   BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_RELEASED);
 	litest_assert_empty_queue(li);
 
 	/* Restore default scroll behavior */
@@ -1076,6 +1080,12 @@ START_TEST(pointer_scroll_button_no_event_before_timeout)
 	litest_timeout_buttonscroll();
 	libinput_dispatch(li);
 	litest_button_click(device, BTN_LEFT, false);
+
+	litest_assert_button_event(li, BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_PRESSED);
+	litest_assert_button_event(li,
+				   BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_RELEASED);
 	litest_assert_empty_queue(li);
 }
 END_TEST
diff --git a/test/test-trackpoint.c b/test/test-trackpoint.c
index e9ba027..adbd46e 100644
--- a/test/test-trackpoint.c
+++ b/test/test-trackpoint.c
@@ -85,10 +85,15 @@ START_TEST(trackpoint_scroll)
 	litest_button_scroll(dev, BTN_MIDDLE, -9, 1);
 	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9);
 
-	/* scroll smaller than the threshold should not generate events */
+	/* scroll smaller than the threshold should not generate axis events */
 	litest_button_scroll(dev, BTN_MIDDLE, 1, 1);
-	/* long middle press without movement should not generate events */
+
 	litest_button_scroll(dev, BTN_MIDDLE, 0, 0);
+	litest_assert_button_event(li, BTN_MIDDLE,
+				   LIBINPUT_BUTTON_STATE_PRESSED);
+	litest_assert_button_event(li,
+				   BTN_MIDDLE,
+				   LIBINPUT_BUTTON_STATE_RELEASED);
 
 	litest_assert_empty_queue(li);
 }
-- 
2.9.3



More information about the wayland-devel mailing list