evdev: use the button down time for no-scroll middle button press event
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 1 Jun 2015 04:38:29 +0000 (14:38 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 1 Jun 2015 23:01:18 +0000 (09:01 +1000)
When we get the release event within the timeout, we send a press + release
event for the middle button. Rather than using the release event's timestamp
for both, remember and use the button press timestamp.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev.c
src/evdev.h
test/trackpoint.c

index 642f441c6fc4b7913058ca690310f140d3673d2b..ed1a9a30a510d886b2346b101704b1aa7caa01ee 100644 (file)
@@ -442,6 +442,7 @@ evdev_button_scroll_button(struct evdev_device *device,
        if (is_press) {
                libinput_timer_set(&device->scroll.timer,
                                time + DEFAULT_MIDDLE_BUTTON_SCROLL_TIMEOUT);
+               device->scroll.button_down_time = time;
        } else {
                libinput_timer_cancel(&device->scroll.timer);
                if (device->scroll.button_scroll_active) {
@@ -451,7 +452,8 @@ evdev_button_scroll_button(struct evdev_device *device,
                } else {
                        /* If the button is released quickly enough emit the
                         * button press/release events. */
-                       evdev_pointer_notify_physical_button(device, time,
+                       evdev_pointer_notify_physical_button(device,
+                                       device->scroll.button_down_time,
                                        device->scroll.button,
                                        LIBINPUT_BUTTON_STATE_PRESSED);
                        evdev_pointer_notify_physical_button(device, time,
index 692795276d6a4a818c73750753a9b29397eed60e..3f63c57a45f40011e3a423b7779e6ad095bb3675 100644 (file)
@@ -150,6 +150,8 @@ struct evdev_device {
                /* Currently enabled method, button */
                enum libinput_config_scroll_method method;
                uint32_t button;
+               uint64_t button_down_time;
+
                /* set during device init, used at runtime to delay changes
                 * until all buttons are up */
                enum libinput_config_scroll_method want_method;
index 9fcce6f7fd40c1d6b00c0d61f67b64c2fdc3fee6..0a6f6b0fd1442e41ff087368c3786ded5a3ae53c 100644 (file)
@@ -35,15 +35,34 @@ START_TEST(trackpoint_middlebutton)
 {
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
+       struct libinput_event *event;
+       struct libinput_event_pointer *ptrev;
+       uint64_t ptime, rtime;
 
        litest_drain_events(li);
 
        /* A quick middle button click should get reported normally */
        litest_button_click(dev, BTN_MIDDLE, 1);
+       msleep(2);
        litest_button_click(dev, BTN_MIDDLE, 0);
 
-       litest_assert_button_event(li, BTN_MIDDLE, 1);
-       litest_assert_button_event(li, BTN_MIDDLE, 0);
+       litest_wait_for_event(li);
+
+       event = libinput_get_event(li);
+       ptrev = litest_is_button_event(event,
+                                      BTN_MIDDLE,
+                                      LIBINPUT_BUTTON_STATE_PRESSED);
+       ptime = libinput_event_pointer_get_time(ptrev);
+       libinput_event_destroy(event);
+
+       event = libinput_get_event(li);
+       ptrev = litest_is_button_event(event,
+                                      BTN_MIDDLE,
+                                      LIBINPUT_BUTTON_STATE_RELEASED);
+       rtime = libinput_event_pointer_get_time(ptrev);
+       libinput_event_destroy(event);
+
+       ck_assert_int_lt(ptime, rtime);
 
        litest_assert_empty_queue(li);
 }