Swap the return values for unsupported scroll button configs
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 6 Feb 2017 01:23:18 +0000 (11:23 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 6 Feb 2017 01:23:18 +0000 (11:23 +1000)
Usually we reply INVALID before we reply UNSUPPORTED but that's only for those
values where the value is a programming error. But in this case it's a bit
more complicated. INVALID is only for the cases where the button doesn't exist
on the device, if we don't have button scrolling at all then we have
UNSUPPORTED for all.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/libinput.c
test/test-pointer.c

index 84e329de12f56fa20128b5770723ec46a03ea315..514a611984efa764bf6aa0f9fc06017c0eda4322 100644 (file)
@@ -3954,13 +3954,13 @@ LIBINPUT_EXPORT enum libinput_config_status
 libinput_device_config_scroll_set_button(struct libinput_device *device,
                                         uint32_t button)
 {
-       if (button && !libinput_device_pointer_has_button(device, button))
-               return LIBINPUT_CONFIG_STATUS_INVALID;
-
        if ((libinput_device_config_scroll_get_methods(device) &
             LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0)
                return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
 
+       if (button && !libinput_device_pointer_has_button(device, button))
+               return LIBINPUT_CONFIG_STATUS_INVALID;
+
        return device->config.scroll_method->set_button(device, button);
 }
 
index f28b5076edccac29357da2629e620e066051e347..57e7fd1464a6538f633c4c9087dc22e4bbba0da4 100644 (file)
@@ -1014,6 +1014,28 @@ START_TEST(pointer_scroll_button)
 }
 END_TEST
 
+START_TEST(pointer_scroll_button_noscroll)
+{
+       struct litest_device *dev = litest_current_device();
+       struct libinput_device *device = dev->libinput_device;
+       uint32_t methods, button;
+       enum libinput_config_status status;
+
+       methods = libinput_device_config_scroll_get_method(device);
+       ck_assert_int_eq((methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN), 0);
+       button = libinput_device_config_scroll_get_button(device);
+       ck_assert_int_eq(button, 0);
+       button = libinput_device_config_scroll_get_default_button(device);
+       ck_assert_int_eq(button, 0);
+
+       status = libinput_device_config_scroll_set_method(device,
+                                       LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
+       ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
+       status = libinput_device_config_scroll_set_button(device, BTN_LEFT);
+       ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
+}
+END_TEST
+
 START_TEST(pointer_scroll_button_no_event_before_timeout)
 {
        struct litest_device *device = litest_current_device();
@@ -1889,6 +1911,7 @@ litest_setup_tests_pointer(void)
        litest_add_for_device("pointer:button", pointer_button_has_no_button, LITEST_KEYBOARD);
        litest_add("pointer:scroll", pointer_scroll_wheel, LITEST_WHEEL, LITEST_TABLET);
        litest_add("pointer:scroll", pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
+       litest_add("pointer:scroll", pointer_scroll_button_noscroll, LITEST_ANY, LITEST_RELATIVE|LITEST_BUTTON);
        litest_add("pointer:scroll", pointer_scroll_button_no_event_before_timeout, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
        litest_add("pointer:scroll", pointer_scroll_button_middle_emulation, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
        litest_add("pointer:scroll", pointer_scroll_nowheel_defaults, LITEST_RELATIVE|LITEST_BUTTON, LITEST_WHEEL);