[mutter/wip/garnacho/virtual-input-device: 9/22] ClutterSeatEvdev: Keep track of button count



commit 3635862fd43ecb33b65f49de51259753caab1b52
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Wed Jun 22 17:55:58 2016 +0800

    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.

 clutter/clutter/evdev/clutter-seat-evdev.c |   37 ++++++++++++++++++++++++++++
 clutter/clutter/evdev/clutter-seat-evdev.h |    2 +
 2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter/evdev/clutter-seat-evdev.c b/clutter/clutter/evdev/clutter-seat-evdev.c
index 6a7c5ef..fffaa1f 100644
--- a/clutter/clutter/evdev/clutter-seat-evdev.c
+++ b/clutter/clutter/evdev/clutter-seat-evdev.c
@@ -204,6 +204,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,
@@ -216,6 +235,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);
@@ -408,6 +437,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 f246434..35f4ea2 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 <libinput.h>
+#include <linux/input.h>
 
 #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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]