evdev: improve default scroll button detection

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@who-t.net>
This commit is contained in:
Peter Hutterer 2017-02-27 11:20:14 +10:00
parent 927ad51fad
commit 555ee1a989
2 changed files with 13 additions and 0 deletions

View file

@ -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;
}

View file

@ -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