[PATCH libinput] evdev: improve default scroll button detection

Peter Hutterer peter.hutterer at who-t.net
Tue Feb 28 02:38:37 UTC 2017


Try to guess the default scroll buttons a bit better. Right now we default to
scroll button 0 (disabled) whenever a device doesn't have a middle button but
we might as well cast a wider net here as setting a scroll button only has a
direct effect when button scrolling is enabled.

Use the first extra button we find or fall back onto the right button if we
don't have any extra buttons.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev.c         | 9 +++++++++
 test/test-pointer.c | 4 ++++
 2 files changed, 13 insertions(+)

diff --git a/src/evdev.c b/src/evdev.c
index 2a57b25..e6ae1a3 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1536,10 +1536,19 @@ static uint32_t
 evdev_scroll_get_default_button(struct libinput_device *device)
 {
 	struct evdev_device *evdev = evdev_device(device);
+	unsigned int code;
 
 	if (libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_MIDDLE))
 		return BTN_MIDDLE;
 
+	for (code = BTN_SIDE; code <= BTN_TASK; code++) {
+		if (libevdev_has_event_code(evdev->evdev, EV_KEY, code))
+			return code;
+	}
+
+	if (libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_RIGHT))
+		return BTN_RIGHT;
+
 	return 0;
 }
 
diff --git a/test/test-pointer.c b/test/test-pointer.c
index 06c45b2..e09f8f8 100644
--- a/test/test-pointer.c
+++ b/test/test-pointer.c
@@ -1176,11 +1176,15 @@ START_TEST(pointer_scroll_defaults_logitech_marble)
 	struct litest_device *dev = litest_current_device();
 	struct libinput_device *device = dev->libinput_device;
 	enum libinput_config_scroll_method method;
+	uint32_t button;
 
 	method = libinput_device_config_scroll_get_method(device);
 	ck_assert_int_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
 	method = libinput_device_config_scroll_get_default_method(device);
 	ck_assert_int_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
+
+	button = libinput_device_config_scroll_get_button(device);
+	ck_assert_int_eq(button, BTN_SIDE);
 }
 END_TEST
 
-- 
2.9.3



More information about the wayland-devel mailing list