evdev: enable button scrolling by default on mice without wheels
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 28 Apr 2015 06:45:35 +0000 (16:45 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 28 Apr 2015 07:12:31 +0000 (17:12 +1000)
If we have a middle button but no wheels, enable on-button scrolling for the
middle button by default. This applies e.g. to the Logitech trackball added as
new test device here.

This makes the separate check for POINTINGSTICK obsolete but I'd rather leave
this in to be more explicit about it.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev.c
test/Makefile.am
test/litest-logitech-trackball.c [new file with mode: 0644]
test/litest.c
test/litest.h
test/pointer.c

index d65b11311e99dc1d3a99de8abcd88de8658d5367..16ac49976bfbac9bb2ece21ac11ee05957a0c4fb 100644 (file)
@@ -983,8 +983,15 @@ evdev_scroll_get_default_method(struct libinput_device *device)
 
        if (libevdev_has_property(evdev->evdev, INPUT_PROP_POINTING_STICK))
                return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
-       else
-               return LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
+
+       /* Mice without a scroll wheel but with middle button have on-button
+        * scrolling by default */
+       if (!libevdev_has_event_code(evdev->evdev, EV_REL, REL_WHEEL) &&
+           !libevdev_has_event_code(evdev->evdev, EV_REL, REL_HWHEEL) &&
+           libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_MIDDLE))
+               return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
+
+       return LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
 }
 
 static enum libinput_config_status
@@ -1016,8 +1023,15 @@ evdev_scroll_get_default_button(struct libinput_device *device)
 
        if (libevdev_has_property(evdev->evdev, INPUT_PROP_POINTING_STICK))
                return BTN_MIDDLE;
-       else
-               return 0;
+
+       /* A device that defaults to button scrolling defaults
+          to BTN_MIDDLE */
+       if (evdev_scroll_get_default_method(device) ==
+               LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN &&
+           libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_MIDDLE))
+               return BTN_MIDDLE;
+
+       return 0;
 }
 
 static int
index a616c5c4da4de48fefbcee58a12a307c6238b330..be0c5d909908ba3370e16c57e29affe01f25bcf3 100644 (file)
@@ -18,6 +18,7 @@ liblitest_la_SOURCES = \
        litest-generic-singletouch.c \
        litest-keyboard.c \
        litest-keyboard-razer-blackwidow.c \
+       litest-logitech-trackball.c \
        litest-mouse.c \
        litest-mouse-roccat.c \
        litest-ms-surface-cover.c \
diff --git a/test/litest-logitech-trackball.c b/test/litest-logitech-trackball.c
new file mode 100644 (file)
index 0000000..5e862d8
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2015 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_logitech_trackball_setup(void)
+{
+       struct litest_device *d = litest_create_device(LITEST_LOGITECH_TRACKBALL);
+       litest_set_current_device(d);
+}
+
+static struct input_id input_id = {
+       .bustype = 0x3,
+       .vendor = 0x46d,
+       .product = 0xc408,
+};
+
+static int events[] = {
+       EV_KEY, BTN_LEFT,
+       EV_KEY, BTN_RIGHT,
+       EV_KEY, BTN_MIDDLE,
+       EV_KEY, BTN_SIDE,
+       EV_KEY, BTN_EXTRA,
+       EV_REL, REL_X,
+       EV_REL, REL_Y,
+       -1 , -1,
+};
+
+struct litest_test_device litest_logitech_trackball_device = {
+       .type = LITEST_LOGITECH_TRACKBALL,
+       .features = LITEST_RELATIVE | LITEST_BUTTON,
+       .shortname = "logitech trackball",
+       .setup = litest_logitech_trackball_setup,
+       .interface = NULL,
+
+       .name = "Logitech USB Trackball",
+       .id = &input_id,
+       .absinfo = NULL,
+       .events = events,
+};
index 6d17a3759ea083c86e0334033c0aceee130e3572..15fc87eaeddc876e01b34d682d72c45c30c11010 100644 (file)
@@ -102,6 +102,7 @@ extern struct litest_test_device litest_keyboard_blackwidow_device;
 extern struct litest_test_device litest_wheel_only_device;
 extern struct litest_test_device litest_mouse_roccat_device;
 extern struct litest_test_device litest_ms_surface_cover_device;
+extern struct litest_test_device litest_logitech_trackball_device;
 
 struct litest_test_device* devices[] = {
        &litest_synaptics_clickpad_device,
@@ -125,6 +126,7 @@ struct litest_test_device* devices[] = {
        &litest_wheel_only_device,
        &litest_mouse_roccat_device,
        &litest_ms_surface_cover_device,
+       &litest_logitech_trackball_device,
        NULL,
 };
 
index e5a80305cbe6087a4ec2ad8fa7c1e7fc6d19cc41..611cdf78441941f0341de93eea2b1b185a8bbca8 100644 (file)
@@ -56,6 +56,7 @@ enum litest_device_type {
        LITEST_KEYBOARD_BLACKWIDOW = -20,
        LITEST_WHEEL_ONLY = -21,
        LITEST_MOUSE_ROCCAT = -22,
+       LITEST_LOGITECH_TRACKBALL = -23,
 };
 
 enum litest_device_feature {
index 26d9930c0387627c846055de21583d23d10ce5c9..1dde354d95d8923eee8db26e7767bf71b05bbb27 100644 (file)
@@ -758,6 +758,26 @@ START_TEST(pointer_scroll_button)
 }
 END_TEST
 
+START_TEST(pointer_scroll_nowheel_defaults)
+{
+       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_ON_BUTTON_DOWN);
+
+       method = libinput_device_config_scroll_get_default_method(device);
+       ck_assert_int_eq(method, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
+
+       button = libinput_device_config_scroll_get_button(device);
+       ck_assert_int_eq(button, BTN_MIDDLE);
+       button = libinput_device_config_scroll_get_default_button(device);
+       ck_assert_int_eq(button, BTN_MIDDLE);
+}
+END_TEST
+
 START_TEST(pointer_accel_defaults)
 {
        struct litest_device *dev = litest_current_device();
@@ -1243,6 +1263,7 @@ int main (int argc, char **argv) {
        litest_add_no_device("pointer:button", pointer_seat_button_count);
        litest_add("pointer:scroll", pointer_scroll_wheel, LITEST_WHEEL, LITEST_ANY);
        litest_add("pointer:scroll", pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
+       litest_add("pointer:scroll", pointer_scroll_nowheel_defaults, LITEST_RELATIVE|LITEST_BUTTON, LITEST_WHEEL);
        litest_add("pointer:scroll", pointer_scroll_natural_defaults, LITEST_WHEEL, LITEST_ANY);
        litest_add("pointer:scroll", pointer_scroll_natural_enable_config, LITEST_WHEEL, LITEST_ANY);
        litest_add("pointer:scroll", pointer_scroll_natural_wheel, LITEST_WHEEL, LITEST_ANY);