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




commit 2687abe6e7137930c031a0d1cda071a1e992a323
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

 src/backends/meta-input-settings-private.h | 11 ++++++++
 src/backends/meta-input-settings.c         | 40 +++++++++++-------------------
 src/backends/native/meta-seat-impl.c       | 15 +++++++++--
 src/backends/x11/meta-seat-x11.c           |  9 ++++++-
 src/backends/x11/meta-xkb-a11y-x11.c       | 13 +++++++---
 5 files changed, 55 insertions(+), 33 deletions(-)
---
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index 9a0cd859aa..aa8c2c6979 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -208,4 +208,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 1b9a8af903..767797b4a3 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -1204,11 +1204,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;
@@ -1580,10 +1579,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;
@@ -1594,10 +1592,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;
 
@@ -1646,11 +1643,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;
 
@@ -1739,12 +1735,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",
@@ -1771,8 +1761,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 06ae7d3aa1..a810cb95f1 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -1530,6 +1530,9 @@ process_base_event (MetaSeatImpl          *seat,
   ClutterInputDevice *device;
   ClutterEvent *device_event;
   struct libinput_device *libinput_device;
+  MetaInputSettings *input_settings;
+
+  input_settings = meta_backend_get_input_settings (meta_get_backend ());
 
   switch (libinput_event_get_type (event))
     {
@@ -1539,6 +1542,7 @@ process_base_event (MetaSeatImpl          *seat,
       device = evdev_add_device (seat, 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:
@@ -1549,6 +1553,7 @@ process_base_event (MetaSeatImpl          *seat,
       clutter_event_set_device (device_event, device);
       evdev_remove_device (seat,
                            META_INPUT_DEVICE_NATIVE (device));
+      meta_input_settings_remove_device (input_settings, device);
       break;
 
     default:
@@ -1613,9 +1618,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 = seat_from_device (input_device);
   ClutterInputDeviceTool *tool = NULL;
   ClutterInputDeviceToolType tool_type;
+  MetaInputSettings *input_settings;
   uint64_t tool_serial;
 
   if (libinput_tool)
@@ -1636,7 +1641,8 @@ input_device_update_tool (ClutterInputDevice          *input_device,
   if (evdev_device->last_tool != tool)
     {
       evdev_device->last_tool = tool;
-      g_signal_emit_by_name (seat->seat, "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);
     }
 }
 
@@ -3118,6 +3124,11 @@ meta_seat_impl_notify_kbd_a11y_flags_changed (MetaSeatImpl          *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 (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 de9a76640a..169aeba6c5 100644
--- a/src/backends/x11/meta-seat-x11.c
+++ b/src/backends/x11/meta-seat-x11.c
@@ -20,6 +20,7 @@
 
 #include <X11/extensions/XInput2.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"
@@ -724,19 +725,23 @@ meta_seat_x11_handle_event_post (ClutterSeat        *seat,
 {
   MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
   ClutterInputDevice *device = event->device.device;
+  MetaInputSettings *input_settings;
   gboolean is_touch;
 
   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;
@@ -933,6 +938,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);
@@ -953,7 +959,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);
     }
 }
 
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]