[mutter/wip/carlosg/input-refactors-pt1: 74/96] backends/native: Assign unique ranges of slots to virtual devices




commit 4b79e9910f47a4d57b9e679c8fdb16668381d674
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Oct 22 11:23:03 2020 +0200

    backends/native: Assign unique ranges of slots to virtual devices
    
    We are moving to seat-wide touch slot accounting, so move these virtual
    devices to using their own range each.
    
    There's the theoretical case of overflow/rollover, if enough virtual
    devices are created/destroyed in the session lifetime. In that case the
    slots are prevented from colliding with real touch devices, although there's
    no prevention for newer virtual devices colliding with older persisting ones.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1486

 src/backends/native/meta-seat-native.c             | 14 ++++++++++++
 src/backends/native/meta-seat-native.h             |  1 +
 .../native/meta-virtual-input-device-native.c      | 26 +++++++++++++++++++---
 3 files changed, 38 insertions(+), 3 deletions(-)
---
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 222acbd0bf..bedb9805f6 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -2700,12 +2700,26 @@ meta_seat_native_apply_kbd_a11y_settings (ClutterSeat            *seat,
                                                       settings);
 }
 
+static void
+bump_touch_slot_base (MetaSeatNative *seat_native)
+{
+  if (seat_native->touch_slot_base < 0x100)
+    seat_native->touch_slot_base = 0x100;
+
+  seat_native->touch_slot_base += CLUTTER_VIRTUAL_INPUT_DEVICE_MAX_TOUCH_SLOTS;
+}
+
 static ClutterVirtualInputDevice *
 meta_seat_native_create_virtual_device (ClutterSeat            *seat,
                                         ClutterInputDeviceType  device_type)
 {
+  MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
+
+  bump_touch_slot_base (seat_native);
+
   return g_object_new (META_TYPE_VIRTUAL_INPUT_DEVICE_NATIVE,
                        "seat", seat,
+                       "slot-base", seat_native->touch_slot_base,
                        "device-type", device_type,
                        NULL);
 }
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 7945603758..e197d7fafa 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -90,6 +90,7 @@ struct _MetaSeatNative
 
   MetaTouchState **touch_states;
   int n_alloc_touch_states;
+  guint touch_slot_base;
 
   struct xkb_state *xkb;
   xkb_led_index_t caps_lock_led;
diff --git a/src/backends/native/meta-virtual-input-device-native.c 
b/src/backends/native/meta-virtual-input-device-native.c
index 510414bde8..eb25ed5979 100644
--- a/src/backends/native/meta-virtual-input-device-native.c
+++ b/src/backends/native/meta-virtual-input-device-native.c
@@ -34,6 +34,7 @@ enum
   PROP_0,
 
   PROP_SEAT,
+  PROP_SLOT_BASE,
 
   PROP_LAST
 };
@@ -46,6 +47,7 @@ struct _MetaVirtualInputDeviceNative
 
   ClutterInputDevice *device;
   MetaSeatNative *seat;
+  guint slot_base;
   int button_count[KEY_CNT];
 };
 
@@ -547,14 +549,16 @@ meta_virtual_input_device_native_notify_touch_down (ClutterVirtualInputDevice *v
   MetaInputDeviceNative *device_evdev =
     META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
   MetaTouchState *touch_state;
+  int seat_slot;
 
   g_return_if_fail (virtual_evdev->device != NULL);
 
   if (time_us == CLUTTER_CURRENT_TIME)
     time_us = g_get_monotonic_time ();
 
+  seat_slot = virtual_evdev->slot_base + device_slot;
   touch_state = meta_input_device_native_acquire_touch_state (device_evdev,
-                                                              device_slot);
+                                                              seat_slot);
   if (!touch_state)
     return;
 
@@ -582,14 +586,16 @@ meta_virtual_input_device_native_notify_touch_motion (ClutterVirtualInputDevice
   MetaInputDeviceNative *device_evdev =
     META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
   MetaTouchState *touch_state;
+  int seat_slot;
 
   g_return_if_fail (virtual_evdev->device != NULL);
 
   if (time_us == CLUTTER_CURRENT_TIME)
     time_us = g_get_monotonic_time ();
 
+  seat_slot = virtual_evdev->slot_base + device_slot;
   touch_state = meta_input_device_native_lookup_touch_state (device_evdev,
-                                                             device_slot);
+                                                             seat_slot);
   if (!touch_state)
     return;
 
@@ -615,14 +621,16 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
   MetaInputDeviceNative *device_evdev =
     META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
   MetaTouchState *touch_state;
+  int seat_slot;
 
   g_return_if_fail (virtual_evdev->device != NULL);
 
   if (time_us == CLUTTER_CURRENT_TIME)
     time_us = g_get_monotonic_time ();
 
+  seat_slot = virtual_evdev->slot_base + device_slot;
   touch_state = meta_input_device_native_lookup_touch_state (device_evdev,
-                                                             device_slot);
+                                                             seat_slot);
   if (!touch_state)
     return;
 
@@ -651,6 +659,9 @@ meta_virtual_input_device_native_get_property (GObject    *object,
     case PROP_SEAT:
       g_value_set_pointer (value, virtual_evdev->seat);
       break;
+    case PROP_SLOT_BASE:
+      g_value_set_uint (value, virtual_evdev->slot_base);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -671,6 +682,9 @@ meta_virtual_input_device_native_set_property (GObject      *object,
     case PROP_SEAT:
       virtual_evdev->seat = g_value_get_pointer (value);
       break;
+    case PROP_SLOT_BASE:
+      virtual_evdev->slot_base = g_value_get_uint (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -762,5 +776,11 @@ meta_virtual_input_device_native_class_init (MetaVirtualInputDeviceNativeClass *
                                                "Seat",
                                                CLUTTER_PARAM_READWRITE |
                                                G_PARAM_CONSTRUCT_ONLY);
+  obj_props[PROP_SLOT_BASE] = g_param_spec_uint ("slot-base",
+                                                 "Slot base",
+                                                 "Base for touch slots",
+                                                 0, G_MAXUINT, 0,
+                                                 CLUTTER_PARAM_READWRITE |
+                                                 G_PARAM_CONSTRUCT_ONLY);
   g_object_class_install_properties (object_class, PROP_LAST, obj_props);
 }


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