evdev: cancel the middle button timer on device removed
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 30 Jan 2019 23:02:58 +0000 (09:02 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 31 Jan 2019 05:09:44 +0000 (15:09 +1000)
If a middle-button-emulating device is removed with one button down, the timer
never gets cancelled and triggers an assert during device removal.

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

index 687774c4613626625b7b0eb1aeebd86510e0289c..928937bcd52215d5f065ec3e6cfd79c650163655 100644 (file)
@@ -2641,6 +2641,7 @@ evdev_device_remove(struct evdev_device *device)
        evdev_log_info(device, "device removed\n");
 
        libinput_timer_cancel(&device->scroll.timer);
+       libinput_timer_cancel(&device->middlebutton.timer);
 
        list_for_each(dev, &device->base.seat->devices_list, link) {
                struct evdev_device *d = evdev_device(dev);
index 7af2261aa291961cea1cbac1eff5ef855748badb..b72cff5c1d758d9788ab64f4eb86bde3982b408a 100644 (file)
@@ -2138,6 +2138,31 @@ START_TEST(middlebutton_device_remove_while_down)
 }
 END_TEST
 
+START_TEST(middlebutton_device_remove_while_one_is_down)
+{
+       struct litest_device *dev = litest_current_device();
+       struct libinput_device *device = dev->libinput_device;
+       struct libinput *li = dev->libinput;
+       enum libinput_config_status status;
+
+       libinput_device_config_scroll_set_method(device,
+                                                LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
+       status = libinput_device_config_middle_emulation_set_enabled(
+                               device,
+                               LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);
+       if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED)
+               return;
+
+       litest_drain_events(li);
+
+       litest_event(dev, EV_KEY, BTN_RIGHT, 1);
+       litest_event(dev, EV_SYN, SYN_REPORT, 0);
+       libinput_dispatch(li);
+
+       litest_assert_empty_queue(li);
+}
+END_TEST
+
 START_TEST(pointer_time_usec)
 {
        struct litest_device *dev = litest_current_device();
@@ -2705,6 +2730,7 @@ TEST_COLLECTION(pointer)
        litest_add("pointer:middlebutton", middlebutton_button_scrolling, LITEST_RELATIVE|LITEST_BUTTON, LITEST_CLICKPAD);
        litest_add("pointer:middlebutton", middlebutton_button_scrolling_middle, LITEST_RELATIVE|LITEST_BUTTON, LITEST_CLICKPAD);
        litest_add("pointer:middlebutton", middlebutton_device_remove_while_down, LITEST_BUTTON, LITEST_CLICKPAD);
+       litest_add("pointer:middlebutton", middlebutton_device_remove_while_one_is_down, LITEST_BUTTON, LITEST_CLICKPAD);
 
        litest_add_ranged("pointer:state", pointer_absolute_initial_state, LITEST_ABSOLUTE, LITEST_ANY, &axis_range);