[mutter/wip/carlosg/input-thread: 97/130] backends: Make device tracking at MetaInputSettings ad-hoc API




commit 42208cff3757fd7286f5306f2847ae6e39597dc9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Aug 11 16:27:35 2020 +0200

    backends: Make device tracking at MetaInputSettings ad-hoc API
    
    Depending on the backend, we want to integrate this object at different
    levels. It will sit close to the MetaBackendX11/MetaSeatX11 in X11, but
    it will be put deep down with MetaSeatImpl in the native backend, in a
    separate thread.
    
    Since we can't depend on a single object type, nor are able to track
    ClutterSeat signals neatly, make this API something to be called
    explicitly by backends.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 clutter/clutter/clutter-seat.c             | 13 ----------
 src/backends/meta-input-settings-private.h | 11 ++++++++
 src/backends/meta-input-settings.c         | 40 +++++++++++-------------------
 src/backends/native/meta-seat-impl.c       | 16 +++++++++---
 src/backends/x11/meta-seat-x11.c           |  9 ++++++-
 src/backends/x11/meta-xkb-a11y-x11.c       | 13 +++++++---
 6 files changed, 55 insertions(+), 47 deletions(-)
---
diff --git a/clutter/clutter/clutter-seat.c b/clutter/clutter/clutter-seat.c
index ed78f43a59..f4309787c5 100644
--- a/clutter/clutter/clutter-seat.c
+++ b/clutter/clutter/clutter-seat.c
@@ -36,7 +36,6 @@ enum
 {
   DEVICE_ADDED,
   DEVICE_REMOVED,
-  TOOL_CHANGED,
   KBD_A11Y_MASK_CHANGED,
   KBD_A11Y_FLAGS_CHANGED,
   PTR_A11Y_DWELL_CLICK_TYPE_CHANGED,
@@ -149,18 +148,6 @@ clutter_seat_class_init (ClutterSeatClass *klass)
                   0, NULL, NULL, NULL,
                   G_TYPE_NONE, 1,
                   CLUTTER_TYPE_INPUT_DEVICE);
-  signals[TOOL_CHANGED] =
-    g_signal_new (I_("tool-changed"),
-                  G_TYPE_FROM_CLASS (klass),
-                  G_SIGNAL_RUN_LAST,
-                  0, NULL, NULL,
-                  _clutter_marshal_VOID__OBJECT_OBJECT,
-                  G_TYPE_NONE, 2,
-                  CLUTTER_TYPE_INPUT_DEVICE,
-                  CLUTTER_TYPE_INPUT_DEVICE_TOOL);
-  g_signal_set_va_marshaller (signals[TOOL_CHANGED],
-                              G_TYPE_FROM_CLASS (object_class),
-                              _clutter_marshal_VOID__OBJECT_OBJECTv);
 
   /**
    * ClutterSeat::kbd-a11y-mods-state-changed:
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index 5e51ea9406..93aae17fde 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -209,4 +209,15 @@ void meta_input_settings_set_device_aspect_ratio (MetaInputSettings  *input_sett
 void meta_input_settings_get_kbd_a11y_settings (MetaInputSettings   *input_settings,
                                                 MetaKbdA11ySettings *a11y_settings);
 
+void meta_input_settings_add_device (MetaInputSettings  *input_settings,
+                                     ClutterInputDevice *device);
+void meta_input_settings_remove_device (MetaInputSettings  *input_settings,
+                                        ClutterInputDevice *device);
+void meta_input_settings_notify_tool_change (MetaInputSettings      *input_settings,
+                                             ClutterInputDevice     *device,
+                                             ClutterInputDeviceTool *tool);
+void meta_input_settings_notify_kbd_a11y_change (MetaInputSettings     *input_settings,
+                                                 MetaKeyboardA11yFlags  new_flags,
+                                                 MetaKeyboardA11yFlags  what_changed);
+
 #endif /* META_INPUT_SETTINGS_PRIVATE_H */
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
index 36998868c5..35d46483b3 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -1209,11 +1209,10 @@ load_keyboard_a11y_settings (MetaInputSettings *input_settings)
   g_signal_emit (input_settings, signals[KBD_A11Y_CHANGED], 0, &priv->kbd_a11y_settings);
 }
 
-static void
-on_keyboard_a11y_settings_changed (ClutterSeat              *seat,
-                                   MetaKeyboardA11yFlags     new_flags,
-                                   MetaKeyboardA11yFlags     what_changed,
-                                   MetaInputSettings        *input_settings)
+void
+meta_input_settings_notify_kbd_a11y_change (MetaInputSettings     *input_settings,
+                                            MetaKeyboardA11yFlags  new_flags,
+                                            MetaKeyboardA11yFlags  what_changed)
 {
   MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings);
   guint i;
@@ -1585,10 +1584,9 @@ evaluate_two_finger_scrolling (MetaInputSettings  *input_settings,
     g_hash_table_add (priv->two_finger_devices, device);
 }
 
-static void
-meta_input_settings_device_added (ClutterSeat        *seat,
-                                  ClutterInputDevice *device,
-                                  MetaInputSettings  *input_settings)
+void
+meta_input_settings_add_device (MetaInputSettings  *input_settings,
+                                ClutterInputDevice *device)
 {
   if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_LOGICAL)
     return;
@@ -1599,10 +1597,9 @@ meta_input_settings_device_added (ClutterSeat        *seat,
   check_add_mappable_device (input_settings, device);
 }
 
-static void
-meta_input_settings_device_removed (ClutterSeat        *seat,
-                                    ClutterInputDevice *device,
-                                    MetaInputSettings  *input_settings)
+void
+meta_input_settings_remove_device (MetaInputSettings  *input_settings,
+                                   ClutterInputDevice *device)
 {
   MetaInputSettingsPrivate *priv;
 
@@ -1651,11 +1648,10 @@ current_tool_info_free (CurrentToolInfo *info)
   g_free (info);
 }
 
-static void
-meta_input_settings_tool_changed (ClutterSeat            *seat,
-                                  ClutterInputDevice     *device,
-                                  ClutterInputDeviceTool *tool,
-                                  MetaInputSettings      *input_settings)
+void
+meta_input_settings_notify_tool_change (MetaInputSettings      *input_settings,
+                                        ClutterInputDevice     *device,
+                                        ClutterInputDeviceTool *tool)
 {
   MetaInputSettingsPrivate *priv;
 
@@ -1744,12 +1740,6 @@ meta_input_settings_init (MetaInputSettings *settings)
 
   priv = meta_input_settings_get_instance_private (settings);
   priv->seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
-  g_signal_connect (priv->seat, "device-added",
-                    G_CALLBACK (meta_input_settings_device_added), settings);
-  g_signal_connect (priv->seat, "device-removed",
-                    G_CALLBACK (meta_input_settings_device_removed), settings);
-  g_signal_connect (priv->seat, "tool-changed",
-                    G_CALLBACK (meta_input_settings_tool_changed), settings);
 
   priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
   g_signal_connect (priv->mouse_settings, "changed",
@@ -1776,8 +1766,6 @@ meta_input_settings_init (MetaInputSettings *settings)
   priv->keyboard_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.keyboard");
   g_signal_connect (priv->keyboard_a11y_settings, "changed",
                     G_CALLBACK (meta_input_keyboard_a11y_settings_changed), settings);
-  g_signal_connect (priv->seat, "kbd-a11y-flags-changed",
-                    G_CALLBACK (on_keyboard_a11y_settings_changed), settings);
 
   priv->mouse_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.mouse");
   g_signal_connect (priv->mouse_a11y_settings, "changed",
diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c
index 7329568f95..53e2fb50db 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -1551,6 +1551,9 @@ process_base_event (MetaSeatImpl          *seat_impl,
   ClutterInputDevice *device;
   ClutterEvent *device_event = NULL;
   struct libinput_device *libinput_device;
+  MetaInputSettings *input_settings;
+
+  input_settings = meta_backend_get_input_settings (meta_get_backend ());
 
   switch (libinput_event_get_type (event))
     {
@@ -1560,6 +1563,7 @@ process_base_event (MetaSeatImpl          *seat_impl,
       device = evdev_add_device (seat_impl, libinput_device);
       device_event = clutter_event_new (CLUTTER_DEVICE_ADDED);
       clutter_event_set_device (device_event, device);
+      meta_input_settings_add_device (input_settings, device);
       break;
 
     case LIBINPUT_EVENT_DEVICE_REMOVED:
@@ -1570,6 +1574,7 @@ process_base_event (MetaSeatImpl          *seat_impl,
       clutter_event_set_device (device_event, device);
       evdev_remove_device (seat_impl,
                            META_INPUT_DEVICE_NATIVE (device));
+      meta_input_settings_remove_device (input_settings, device);
       break;
 
     default:
@@ -1634,9 +1639,9 @@ input_device_update_tool (ClutterInputDevice          *input_device,
                           struct libinput_tablet_tool *libinput_tool)
 {
   MetaInputDeviceNative *evdev_device = META_INPUT_DEVICE_NATIVE (input_device);
-  MetaSeatImpl *seat_impl = seat_impl_from_device (input_device);
   ClutterInputDeviceTool *tool = NULL;
   ClutterInputDeviceToolType tool_type;
+  MetaInputSettings *input_settings;
   uint64_t tool_serial;
 
   if (libinput_tool)
@@ -1660,8 +1665,8 @@ input_device_update_tool (ClutterInputDevice          *input_device,
         clutter_input_device_update_from_tool (input_device, tool);
 
       evdev_device->last_tool = tool;
-      g_signal_emit_by_name (seat_impl->seat_native, "tool-changed",
-                             input_device, tool);
+      input_settings = meta_backend_get_input_settings (meta_get_backend ());
+      meta_input_settings_notify_tool_change (input_settings, input_device, tool);
     }
 }
 
@@ -3075,6 +3080,11 @@ meta_seat_impl_notify_kbd_a11y_flags_changed (MetaSeatImpl          *seat_impl,
                                               MetaKeyboardA11yFlags  new_flags,
                                               MetaKeyboardA11yFlags  what_changed)
 {
+  MetaInputSettings *input_settings;
+
+  input_settings = meta_backend_get_input_settings (meta_get_backend ());
+  meta_input_settings_notify_kbd_a11y_change (input_settings,
+                                              new_flags, what_changed);
   g_signal_emit (seat_impl, signals[KBD_A11Y_FLAGS_CHANGED], 0,
                  new_flags, what_changed);
 }
diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c
index 4437a247a8..24d6369b88 100644
--- a/src/backends/x11/meta-seat-x11.c
+++ b/src/backends/x11/meta-seat-x11.c
@@ -21,6 +21,7 @@
 #include <X11/extensions/XInput2.h>
 #include <X11/extensions/XKB.h>
 
+#include "backends/meta-input-settings-private.h"
 #include "backends/x11/meta-backend-x11.h"
 #include "backends/x11/meta-event-x11.h"
 #include "backends/x11/meta-input-device-tool-x11.h"
@@ -725,6 +726,7 @@ meta_seat_x11_handle_event_post (ClutterSeat        *seat,
 {
   MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
   ClutterInputDevice *device;
+  MetaInputSettings *input_settings;
   gboolean is_touch;
 
   if (event->type != CLUTTER_DEVICE_ADDED &&
@@ -734,15 +736,18 @@ meta_seat_x11_handle_event_post (ClutterSeat        *seat,
   device = clutter_event_get_device (event);
   is_touch =
     clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE;
+  input_settings = meta_backend_get_input_settings (meta_get_backend ());
 
   switch (event->type)
     {
       case CLUTTER_DEVICE_ADDED:
+        meta_input_settings_add_device (input_settings, device);
         seat_x11->has_touchscreens |= is_touch;
         break;
       case CLUTTER_DEVICE_REMOVED:
         if (is_touch)
           seat_x11->has_touchscreens = has_touchscreens (seat_x11);
+        meta_input_settings_remove_device (input_settings, device);
         break;
       default:
         break;
@@ -939,6 +944,7 @@ translate_property_event (MetaSeatX11 *seat_x11,
     {
       ClutterInputDeviceTool *tool = NULL;
       ClutterInputDeviceToolType type;
+      MetaInputSettings *input_settings;
       int serial_id;
 
       serial_id = device_get_tool_serial (device);
@@ -959,7 +965,8 @@ translate_property_event (MetaSeatX11 *seat_x11,
         }
 
       meta_input_device_x11_update_tool (device, tool);
-      g_signal_emit_by_name (seat_x11, "tool-changed", device, tool);
+      input_settings = meta_backend_get_input_settings (meta_get_backend ());
+      meta_input_settings_notify_tool_change (input_settings, device, tool);
 
       if (tool)
         clutter_input_device_update_from_tool (device, tool);
diff --git a/src/backends/x11/meta-xkb-a11y-x11.c b/src/backends/x11/meta-xkb-a11y-x11.c
index 024618be6b..d2e76b3f75 100644
--- a/src/backends/x11/meta-xkb-a11y-x11.c
+++ b/src/backends/x11/meta-xkb-a11y-x11.c
@@ -118,10 +118,15 @@ check_settings_changed (ClutterSeat *seat)
     }
 
   if (what_changed)
-    g_signal_emit_by_name (seat,
-                           "kbd-a11y-flags-changed",
-                           kbd_a11y_settings.controls,
-                           what_changed);
+    {
+      meta_input_settings_notify_kbd_a11y_change (input_settings,
+                                                  kbd_a11y_settings.controls,
+                                                  what_changed);
+      g_signal_emit_by_name (seat,
+                             "kbd-a11y-flags-changed",
+                             kbd_a11y_settings.controls,
+                             what_changed);
+    }
 
   XkbFreeKeyboard (desc, XkbAllComponentsMask, TRUE);
 }


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