[mutter/wip/carlosg/input-thread: 21/104] backends: Drop extra layer of touch info handling




commit 9cc32d94d8c07501fe7be3a0f4e992ac0fe1c67a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed May 6 14:12:55 2020 +0200

    backends: Drop extra layer of touch info handling
    
    We have a hashtable in the device that does not add much on top
    to the seat handling. Make all the places rely on the seat accounting
    instead.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 src/backends/native/meta-input-device-native.c     | 45 ----------------------
 src/backends/native/meta-input-device-native.h     | 11 ------
 src/backends/native/meta-seat-native.c             | 37 ++++++++++--------
 src/backends/native/meta-seat-native.h             |  2 +
 .../native/meta-virtual-input-device-native.c      | 20 ++++------
 5 files changed, 31 insertions(+), 84 deletions(-)
---
diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c
index 25360e6f51..0498238c19 100644
--- a/src/backends/native/meta-input-device-native.c
+++ b/src/backends/native/meta-input-device-native.c
@@ -67,10 +67,6 @@ meta_input_device_native_finalize (GObject *object)
   if (device_evdev->libinput_device)
     libinput_device_unref (device_evdev->libinput_device);
 
-  meta_input_device_native_release_touch_slots (device_evdev,
-                                                g_get_monotonic_time ());
-  g_clear_pointer (&device_evdev->touches, g_hash_table_unref);
-
   backend = clutter_get_default_backend ();
   seat = clutter_backend_get_default_seat (backend);
   meta_seat_native_release_device_id (META_SEAT_NATIVE (seat), device);
@@ -1228,44 +1224,6 @@ meta_input_device_native_a11y_maybe_notify_toggle_keys (MetaInputDeviceNative *d
     meta_input_device_native_bell_notify (device);
 }
 
-static void
-release_device_touch_slot (gpointer value)
-{
-  MetaTouchState *touch_state = value;
-
-  meta_seat_native_release_touch_state (touch_state->seat, touch_state);
-}
-
-MetaTouchState *
-meta_input_device_native_acquire_touch_state (MetaInputDeviceNative *device,
-                                              int                    device_slot)
-{
-  MetaTouchState *touch_state;
-
-  touch_state = meta_seat_native_acquire_touch_state (device->seat,
-                                                      device_slot);
-  g_hash_table_insert (device->touches,
-                       GINT_TO_POINTER (device_slot),
-                       touch_state);
-
-  return touch_state;
-}
-
-MetaTouchState *
-meta_input_device_native_lookup_touch_state (MetaInputDeviceNative *device,
-                                             int                    device_slot)
-{
-  return g_hash_table_lookup (device->touches, GINT_TO_POINTER (device_slot));
-}
-
-void
-meta_input_device_native_release_touch_state (MetaInputDeviceNative *device,
-                                              MetaTouchState        *touch_state)
-{
-  g_hash_table_remove (device->touches,
-                       GINT_TO_POINTER (touch_state->device_slot));
-}
-
 static void
 meta_input_device_native_class_init (MetaInputDeviceNativeClass *klass)
 {
@@ -1305,9 +1263,6 @@ meta_input_device_native_init (MetaInputDeviceNative *self)
   cairo_matrix_init_identity (&self->device_matrix);
   self->device_aspect_ratio = 0;
   self->output_ratio = 0;
-
-  self->touches = g_hash_table_new_full (NULL, NULL,
-                                         NULL, release_device_touch_slot);
 }
 
 /*
diff --git a/src/backends/native/meta-input-device-native.h b/src/backends/native/meta-input-device-native.h
index 87449fe2a5..999e670ffd 100644
--- a/src/backends/native/meta-input-device-native.h
+++ b/src/backends/native/meta-input-device-native.h
@@ -69,8 +69,6 @@ struct _MetaInputDeviceNative
   double device_aspect_ratio; /* w:h */
   double output_ratio;        /* w:h */
 
-  GHashTable *touches;
-
   /* Keyboard a11y */
   ClutterKeyboardA11yFlags a11y_flags;
   GList *slow_keys_list;
@@ -125,15 +123,6 @@ void                      meta_input_device_native_translate_coordinates (Clutte
 void                      meta_input_device_native_apply_kbd_a11y_settings (MetaInputDeviceNative  *device,
                                                                             ClutterKbdA11ySettings 
*settings);
 
-MetaTouchState *          meta_input_device_native_acquire_touch_state (MetaInputDeviceNative *device,
-                                                                        int                    device_slot);
-
-MetaTouchState *          meta_input_device_native_lookup_touch_state (MetaInputDeviceNative *device,
-                                                                       int                    device_slot);
-
-void                      meta_input_device_native_release_touch_state (MetaInputDeviceNative *device,
-                                                                        MetaTouchState        *touch_state);
-
 void                      meta_input_device_native_a11y_maybe_notify_toggle_keys  (MetaInputDeviceNative 
*device_evdev);
 
 struct libinput_device * meta_input_device_native_get_libinput_device (ClutterInputDevice *device);
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index e940b13b0b..8fac0c90f8 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -170,6 +170,22 @@ ensure_seat_slot_allocated (MetaSeatNative *seat,
     }
 }
 
+MetaTouchState *
+meta_seat_native_lookup_touch_state (MetaSeatNative *seat,
+                                     int             device_slot)
+{
+  int seat_slot;
+
+  for (seat_slot = 0; seat_slot < seat->n_alloc_touch_states; seat_slot++)
+    {
+      if (seat->touch_states[seat_slot] &&
+          seat->touch_states[seat_slot]->device_slot == device_slot)
+        return seat->touch_states[seat_slot];
+    }
+
+  return NULL;
+}
+
 MetaTouchState *
 meta_seat_native_acquire_touch_state (MetaSeatNative *seat,
                                       int             device_slot)
@@ -1986,9 +2002,7 @@ process_device_event (MetaSeatNative        *seat,
         y = libinput_event_touch_get_y_transformed (touch_event,
                                                     stage_height);
 
-        touch_state =
-          meta_input_device_native_acquire_touch_state (device_evdev,
-                                                        device_slot);
+        touch_state = meta_seat_native_acquire_touch_state (seat, device_slot);
         touch_state->coords.x = x;
         touch_state->coords.y = y;
 
@@ -2016,9 +2030,7 @@ process_device_event (MetaSeatNative        *seat,
 
         device_slot = libinput_event_touch_get_slot (touch_event);
         time_us = libinput_event_touch_get_time_usec (touch_event);
-        touch_state =
-          meta_input_device_native_lookup_touch_state (device_evdev,
-                                                       device_slot);
+        touch_state = meta_seat_native_lookup_touch_state (seat, device_slot);
         if (!touch_state)
           break;
 
@@ -2027,8 +2039,7 @@ process_device_event (MetaSeatNative        *seat,
                                              touch_state->seat_slot,
                                              touch_state->coords.x,
                                              touch_state->coords.y);
-        meta_input_device_native_release_touch_state (device_evdev,
-                                                      touch_state);
+        meta_seat_native_release_touch_state (seat, touch_state);
         break;
       }
 
@@ -2062,9 +2073,7 @@ process_device_event (MetaSeatNative        *seat,
         y = libinput_event_touch_get_y_transformed (touch_event,
                                                     stage_height);
 
-        touch_state =
-          meta_input_device_native_lookup_touch_state (device_evdev,
-                                                       device_slot);
+        touch_state = meta_seat_native_lookup_touch_state (seat, device_slot);
         if (!touch_state)
           break;
 
@@ -2094,9 +2103,7 @@ process_device_event (MetaSeatNative        *seat,
         time_us = libinput_event_touch_get_time_usec (touch_event);
 
         device_slot = libinput_event_touch_get_slot (touch_event);
-        touch_state =
-          meta_input_device_native_lookup_touch_state (device_evdev,
-                                                       device_slot);
+        touch_state = meta_seat_native_lookup_touch_state (seat, device_slot);
         if (!touch_state)
           break;
 
@@ -2108,7 +2115,7 @@ process_device_event (MetaSeatNative        *seat,
                                              touch_state->coords.x,
                                              touch_state->coords.y);
 
-        meta_input_device_native_release_touch_state (device_evdev, touch_state);
+        meta_seat_native_release_touch_state (touch_state->seat, touch_state);
         break;
       }
     case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 7945603758..befc5a041f 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -203,6 +203,8 @@ void meta_seat_native_sync_leds (MetaSeatNative *seat);
 
 MetaTouchState * meta_seat_native_acquire_touch_state (MetaSeatNative *seat,
                                                        int             device_slot);
+MetaTouchState * meta_seat_native_lookup_touch_state  (MetaSeatNative *seat,
+                                                       int             device_slot);
 
 void meta_seat_native_release_touch_state (MetaSeatNative *seat,
                                            MetaTouchState *touch_state);
diff --git a/src/backends/native/meta-virtual-input-device-native.c 
b/src/backends/native/meta-virtual-input-device-native.c
index 510414bde8..0b72b5ffcf 100644
--- a/src/backends/native/meta-virtual-input-device-native.c
+++ b/src/backends/native/meta-virtual-input-device-native.c
@@ -544,8 +544,6 @@ meta_virtual_input_device_native_notify_touch_down (ClutterVirtualInputDevice *v
 {
   MetaVirtualInputDeviceNative *virtual_evdev =
     META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
-  MetaInputDeviceNative *device_evdev =
-    META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
   MetaTouchState *touch_state;
 
   g_return_if_fail (virtual_evdev->device != NULL);
@@ -553,8 +551,8 @@ meta_virtual_input_device_native_notify_touch_down (ClutterVirtualInputDevice *v
   if (time_us == CLUTTER_CURRENT_TIME)
     time_us = g_get_monotonic_time ();
 
-  touch_state = meta_input_device_native_acquire_touch_state (device_evdev,
-                                                              device_slot);
+  touch_state = meta_seat_native_acquire_touch_state (virtual_evdev->seat,
+                                                      device_slot);
   if (!touch_state)
     return;
 
@@ -579,8 +577,6 @@ meta_virtual_input_device_native_notify_touch_motion (ClutterVirtualInputDevice
 {
   MetaVirtualInputDeviceNative *virtual_evdev =
     META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
-  MetaInputDeviceNative *device_evdev =
-    META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
   MetaTouchState *touch_state;
 
   g_return_if_fail (virtual_evdev->device != NULL);
@@ -588,8 +584,8 @@ meta_virtual_input_device_native_notify_touch_motion (ClutterVirtualInputDevice
   if (time_us == CLUTTER_CURRENT_TIME)
     time_us = g_get_monotonic_time ();
 
-  touch_state = meta_input_device_native_lookup_touch_state (device_evdev,
-                                                             device_slot);
+  touch_state = meta_seat_native_lookup_touch_state (virtual_evdev->seat,
+                                                     device_slot);
   if (!touch_state)
     return;
 
@@ -612,8 +608,6 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
 {
   MetaVirtualInputDeviceNative *virtual_evdev =
     META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
-  MetaInputDeviceNative *device_evdev =
-    META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
   MetaTouchState *touch_state;
 
   g_return_if_fail (virtual_evdev->device != NULL);
@@ -621,8 +615,8 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
   if (time_us == CLUTTER_CURRENT_TIME)
     time_us = g_get_monotonic_time ();
 
-  touch_state = meta_input_device_native_lookup_touch_state (device_evdev,
-                                                             device_slot);
+  touch_state = meta_seat_native_lookup_touch_state (virtual_evdev->seat,
+                                                     device_slot);
   if (!touch_state)
     return;
 
@@ -634,7 +628,7 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
                                        touch_state->coords.x,
                                        touch_state->coords.y);
 
-  meta_input_device_native_release_touch_state (device_evdev, touch_state);
+  meta_seat_native_release_touch_state (virtual_evdev->seat, touch_state);
 }
 
 static void


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