From adbd566f8387f551fcccc461f9211ab001597316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 22 Jun 2016 17:55:58 +0800 Subject: [PATCH] ClutterSeatEvdev: Keep track of button count libinput does it for us, but only for physical devices. When we add virtual devices to the same seat, we need to track button press count ourself. https://bugzilla.gnome.org/show_bug.cgi?id=765009 --- clutter/clutter/evdev/clutter-seat-evdev.c | 37 ++++++++++++++++++++++ clutter/clutter/evdev/clutter-seat-evdev.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/clutter/clutter/evdev/clutter-seat-evdev.c b/clutter/clutter/evdev/clutter-seat-evdev.c index 30e205d8c..68359808a 100644 --- a/clutter/clutter/evdev/clutter-seat-evdev.c +++ b/clutter/clutter/evdev/clutter-seat-evdev.c @@ -205,6 +205,25 @@ queue_event (ClutterEvent *event) _clutter_event_push (event, FALSE); } +static int +update_button_count (ClutterSeatEvdev *seat, + uint32_t button, + uint32_t state) +{ + if (state) + { + return ++seat->button_count[button]; + } + else + { + /* Handle cases where we newer saw the initial pressed event. */ + if (seat->button_count[button] == 0) + return 0; + + return --seat->button_count[button]; + } +} + void clutter_seat_evdev_notify_key (ClutterSeatEvdev *seat, ClutterInputDevice *device, @@ -217,6 +236,16 @@ clutter_seat_evdev_notify_key (ClutterSeatEvdev *seat, ClutterEvent *event = NULL; enum xkb_state_component changed_state; + if (state != AUTOREPEAT_VALUE) + { + /* Drop any repeated button press (for example from virtual devices. */ + int count = update_button_count (seat, key, state); + if (state && count > 1) + return; + if (!state && count != 0) + return; + } + /* We can drop the event on the floor if no stage has been * associated with the device yet. */ stage = _clutter_input_device_get_stage (device); @@ -410,6 +439,14 @@ clutter_seat_evdev_notify_button (ClutterSeatEvdev *seat, CLUTTER_BUTTON1_MASK, CLUTTER_BUTTON3_MASK, CLUTTER_BUTTON2_MASK, CLUTTER_BUTTON4_MASK, CLUTTER_BUTTON5_MASK, 0, 0, 0 }; + int button_count; + + /* Drop any repeated button press (for example from virtual devices. */ + button_count = update_button_count (seat, button, state); + if (state && button_count > 1) + return; + if (!state && button_count != 0) + return; /* We can drop the event on the floor if no stage has been * associated with the device yet. */ diff --git a/clutter/clutter/evdev/clutter-seat-evdev.h b/clutter/clutter/evdev/clutter-seat-evdev.h index f246434f6..35f4ea2f5 100644 --- a/clutter/clutter/evdev/clutter-seat-evdev.h +++ b/clutter/clutter/evdev/clutter-seat-evdev.h @@ -28,6 +28,7 @@ #define __CLUTTER_SEAT_EVDEV_H__ #include +#include #include "clutter-input-device.h" #include "clutter-device-manager-evdev.h" @@ -58,6 +59,7 @@ struct _ClutterSeatEvdev xkb_led_index_t num_lock_led; xkb_led_index_t scroll_lock_led; uint32_t button_state; + int button_count[KEY_CNT]; /* keyboard repeat */ gboolean repeat;