touchpad: mark ALPS touchpads for middle button emulation
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 15 Jun 2015 04:37:49 +0000 (14:37 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Sun, 21 Jun 2015 22:12:04 +0000 (08:12 +1000)
Alps devices don't know if there is a physical middle button on the touchpad,
so they always report one.
Since a large number of touchpads only have two buttons, enable middle button
emulation by default. Those that really don't want it can play with
configuration options, everyone else has it working by default.

The hwdb entry uses "*Alps ..*" as name to also trigger the "litest Alps..."
devices.

https://bugzilla.redhat.com/show_bug.cgi?id=1227992

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev-mt-touchpad-buttons.c
src/evdev.c
src/evdev.h
test/pointer.c
udev/90-libinput-model-quirks.hwdb

index d8438b846ba528d604c78693ca7703ec66f2a1eb..8d4e278e5dd49dccbb57269ca77268ede9c4056b 100644 (file)
@@ -678,6 +678,35 @@ tp_button_config_click_get_default_method(struct libinput_device *device)
        return tp_click_get_default_method(tp);
 }
 
+static inline void
+tp_init_middlebutton_emulation(struct tp_dispatch *tp,
+                              struct evdev_device *device)
+{
+       bool enable_by_default,
+            want_config_option;
+
+       if (tp->buttons.is_clickpad)
+               return;
+
+       /* init middle button emulation on non-clickpads, but only if we
+        * don't have a middle button. Exception: ALPS touchpads don't know
+        * if they have a middle button, so we always want the option there
+        * and enabled by default.
+        */
+       if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE)) {
+               enable_by_default = true;
+               want_config_option = false;
+       } else if (device->model == EVDEV_MODEL_ALPS_TOUCHPAD) {
+               enable_by_default = true;
+               want_config_option = true;
+       } else
+               return;
+
+       evdev_init_middlebutton(tp->device,
+                               enable_by_default,
+                               want_config_option);
+}
+
 int
 tp_init_buttons(struct tp_dispatch *tp,
                struct evdev_device *device)
@@ -734,9 +763,7 @@ tp_init_buttons(struct tp_dispatch *tp,
 
        tp_init_top_softbuttons(tp, device, 1.0);
 
-       if (!tp->buttons.is_clickpad &&
-           !libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE))
-               evdev_init_middlebutton(tp->device, true, false);
+       tp_init_middlebutton_emulation(tp, device);
 
        tp_for_each_touch(tp, t) {
                t->button.state = BUTTON_STATE_NONE;
index 6f457b8d57f195dd57340d139f1a3375b76df9d1..7e1e5c804d8aa9672f352c1c938cb4e5ae8205f7 100644 (file)
@@ -1516,6 +1516,7 @@ evdev_read_model(struct evdev_device *device)
                { "LIBINPUT_MODEL_CLEVO_W740SU", EVDEV_MODEL_CLEVO_W740SU },
                { "LIBINPUT_MODEL_APPLE_TOUCHPAD", EVDEV_MODEL_APPLE_TOUCHPAD },
                { "LIBINPUT_MODEL_WACOM_TOUCHPAD", EVDEV_MODEL_WACOM_TOUCHPAD },
+               { "LIBINPUT_MODEL_ALPS_TOUCHPAD", EVDEV_MODEL_ALPS_TOUCHPAD },
                { NULL, EVDEV_MODEL_DEFAULT },
        };
        const struct model_map *m = model_map;
index ff35a8d2fa1196741ff02798040d3e8c1a1af61b..566b0a4408e4bdf1a408e2724b61162de068e94b 100644 (file)
@@ -106,6 +106,7 @@ enum evdev_device_model {
        EVDEV_MODEL_CLEVO_W740SU,
        EVDEV_MODEL_APPLE_TOUCHPAD,
        EVDEV_MODEL_WACOM_TOUCHPAD,
+       EVDEV_MODEL_ALPS_TOUCHPAD,
 };
 
 struct mt_slot {
index 90977d7e802392f01c96a27c8043259261b94a67..688b6b0b7090847e3c179949976609278dc17290 100644 (file)
@@ -1279,6 +1279,11 @@ START_TEST(middlebutton_default_touchpad)
        struct libinput_device *device = dev->libinput_device;
        enum libinput_config_middle_emulation_state state;
        int available;
+       const char *name = libinput_device_get_name(dev->libinput_device);
+
+       if (streq(name, "litest AlpsPS/2 ALPS GlidePoint") ||
+           streq(name, "litest AlpsPS/2 ALPS DualPoint TouchPad"))
+           return;
 
        available = libinput_device_config_middle_emulation_is_available(device);
        ck_assert(!available);
@@ -1295,6 +1300,25 @@ START_TEST(middlebutton_default_touchpad)
 }
 END_TEST
 
+START_TEST(middlebutton_default_alps)
+{
+       struct litest_device *dev = litest_current_device();
+       struct libinput_device *device = dev->libinput_device;
+       enum libinput_config_middle_emulation_state state;
+       int available;
+
+       available = libinput_device_config_middle_emulation_is_available(device);
+       ck_assert(available);
+
+       state = libinput_device_config_middle_emulation_get_enabled(
+                                           device);
+       ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);
+       state = libinput_device_config_middle_emulation_get_default_enabled(
+                                           device);
+       ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);
+}
+END_TEST
+
 START_TEST(middlebutton_default_disabled)
 {
        struct litest_device *dev = litest_current_device();
@@ -1360,6 +1384,7 @@ litest_setup_tests(void)
        litest_add("pointer:middlebutton", middlebutton_default_clickpad, LITEST_CLICKPAD, LITEST_ANY);
        litest_add("pointer:middlebutton", middlebutton_default_touchpad, LITEST_TOUCHPAD, LITEST_CLICKPAD);
        litest_add("pointer:middlebutton", middlebutton_default_disabled, LITEST_ANY, LITEST_BUTTON);
+       litest_add_for_device("pointer:middlebutton", middlebutton_default_alps, LITEST_ALPS_SEMI_MT);
 
        litest_add_ranged("pointer:state", pointer_absolute_initial_state, LITEST_ABSOLUTE, LITEST_ANY, &axis_range);
 }
index 7442f82844ece7332b2554b5adf3f05ecb742c2c..cf57e9c9b0db396a9e1f8d40820bb2f9ee6c7caf 100644 (file)
 #
 # Sort by brand, model
 
+##########################################
+# ALPS
+##########################################
+libinput:name:*AlpsPS/2 ALPS DualPoint TouchPad:dmi:*
+libinput:name:*AlpsPS/2 ALPS GlidePoint:dmi:*
+ LIBINPUT_MODEL_ALPS_TOUCHPAD=1
+
 ##########################################
 # Apple
 ##########################################