[mutter/wip/carlosg/input-thread: 154/165] backends/native: Move MetaInputSettings ownership to MetaSeatImpl




commit 28ec393990300035f3774add97bfd14c210a1758
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Aug 11 18:33:07 2020 +0200

    backends/native: Move MetaInputSettings ownership to MetaSeatImpl
    
    Together with keymaps and devices, MetaInputSettings will live in the
    ninth circle of hell with MetaSeatImpl, forever tied to it.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 src/backends/meta-input-settings.c               | 65 +++++++++++++++++++-
 src/backends/native/meta-backend-native.c        | 46 +++++++-------
 src/backends/native/meta-input-device-native.c   |  6 +-
 src/backends/native/meta-input-settings-native.c | 78 +++++++++++++++++++++++-
 src/backends/native/meta-input-settings-native.h |  3 +
 src/backends/native/meta-seat-impl.c             | 22 +++++--
 src/backends/native/meta-seat-impl.h             |  3 +
 7 files changed, 188 insertions(+), 35 deletions(-)
---
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
index cc83dddb47..0293161383 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -111,6 +111,15 @@ enum
 
 static guint signals[N_SIGNALS] = { 0 };
 
+enum
+{
+  PROP_0,
+  PROP_SEAT,
+  N_PROPS,
+};
+
+static GParamSpec *props[N_PROPS] = { 0 };
+
 static GSList *
 meta_input_settings_get_devices (MetaInputSettings      *settings,
                                  ClutterInputDeviceType  type)
@@ -152,10 +161,53 @@ meta_input_settings_dispose (GObject *object)
   g_clear_pointer (&priv->current_tools, g_hash_table_unref);
 
   g_clear_pointer (&priv->two_finger_devices, g_hash_table_destroy);
+  g_clear_object (&priv->seat);
 
   G_OBJECT_CLASS (meta_input_settings_parent_class)->dispose (object);
 }
 
+static void
+meta_input_settings_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  MetaInputSettings *input_settings = META_INPUT_SETTINGS (object);
+  MetaInputSettingsPrivate *priv =
+    meta_input_settings_get_instance_private (input_settings);
+
+  switch (prop_id)
+    {
+    case PROP_SEAT:
+      priv->seat = g_value_get_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+meta_input_settings_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  MetaInputSettings *input_settings = META_INPUT_SETTINGS (object);
+  MetaInputSettingsPrivate *priv =
+    meta_input_settings_get_instance_private (input_settings);
+
+  switch (prop_id)
+    {
+    case PROP_SEAT:
+      g_value_set_object (value, priv->seat);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
 static void
 settings_device_set_bool_setting (MetaInputSettings  *input_settings,
                                   ClutterInputDevice *device,
@@ -1711,6 +1763,8 @@ meta_input_settings_class_init (MetaInputSettingsClass *klass)
 
   object_class->dispose = meta_input_settings_dispose;
   object_class->constructed = meta_input_settings_constructed;
+  object_class->set_property = meta_input_settings_set_property;
+  object_class->get_property = meta_input_settings_get_property;
 
   quark_tool_settings =
     g_quark_from_static_string ("meta-input-settings-tool-settings");
@@ -1722,6 +1776,16 @@ meta_input_settings_class_init (MetaInputSettingsClass *klass)
                   0, NULL, NULL, NULL,
                   G_TYPE_NONE, 1,
                   G_TYPE_POINTER);
+
+  props[PROP_SEAT] =
+    g_param_spec_object ("seat",
+                         "Seat",
+                         "Seat",
+                         CLUTTER_TYPE_SEAT,
+                         CLUTTER_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (object_class, N_PROPS, props);
 }
 
 static void
@@ -1730,7 +1794,6 @@ meta_input_settings_init (MetaInputSettings *settings)
   MetaInputSettingsPrivate *priv;
 
   priv = meta_input_settings_get_instance_private (settings);
-  priv->seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
 
   priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
   g_signal_connect (priv->mouse_settings, "changed",
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 065f81eb47..2cb75f8aaa 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -163,13 +163,36 @@ update_viewports (MetaBackend *backend)
   g_object_unref (viewports);
 }
 
+static void
+kbd_a11y_changed_cb (MetaInputSettings   *input_settings,
+                     MetaKbdA11ySettings *a11y_settings,
+                     MetaBackend         *backend)
+{
+  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
+  ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
+  ClutterInputDevice *device;
+
+  device = clutter_seat_get_keyboard (seat);
+  if (device)
+    meta_input_device_native_apply_kbd_a11y_settings (META_INPUT_DEVICE_NATIVE (device),
+                                                      a11y_settings);
+}
+
 static void
 meta_backend_native_post_init (MetaBackend *backend)
 {
+  MetaBackendNative *native = META_BACKEND_NATIVE (backend);
   MetaSettings *settings = meta_backend_get_settings (backend);
+  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
+  MetaSeatNative *seat =
+    META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
 
   META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
 
+  native->input_settings = meta_seat_impl_get_input_settings (seat->impl);
+  g_signal_connect_object (native->input_settings, "kbd-a11y-changed",
+                           G_CALLBACK (kbd_a11y_changed_cb), backend, 0);
+
   if (meta_settings_is_experimental_feature_enabled (settings,
                                                      META_EXPERIMENTAL_FEATURE_RT_SCHEDULER))
     {
@@ -235,34 +258,11 @@ meta_backend_native_create_renderer (MetaBackend *backend,
   return META_RENDERER (renderer_native);
 }
 
-static void
-kbd_a11y_changed_cb (MetaInputSettings   *input_settings,
-                     MetaKbdA11ySettings *a11y_settings,
-                     MetaBackend         *backend)
-{
-  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
-  ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
-  ClutterInputDevice *device;
-
-  device = clutter_seat_get_keyboard (seat);
-  if (device)
-    meta_input_device_native_apply_kbd_a11y_settings (META_INPUT_DEVICE_NATIVE (device),
-                                                      a11y_settings);
-}
-
 static MetaInputSettings *
 meta_backend_native_create_input_settings (MetaBackend *backend)
 {
   MetaBackendNative *native = META_BACKEND_NATIVE (backend);
 
-  if (!native->input_settings)
-    {
-      native->input_settings = g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE,
-                                             NULL);
-      g_signal_connect_object (native->input_settings, "kbd-a11y-changed",
-                               G_CALLBACK (kbd_a11y_changed_cb), backend, 0);
-    }
-
   return native->input_settings;
 }
 
diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c
index 1cc30dce06..ceb0b43bf9 100644
--- a/src/backends/native/meta-input-device-native.c
+++ b/src/backends/native/meta-input-device-native.c
@@ -246,10 +246,11 @@ clear_slow_keys (MetaInputDeviceNative *device)
 static guint
 get_slow_keys_delay (ClutterInputDevice *device)
 {
+  MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
   MetaKbdA11ySettings a11y_settings;
   MetaInputSettings *input_settings;
 
-  input_settings = meta_backend_get_input_settings (meta_get_backend ());
+  input_settings = meta_seat_impl_get_input_settings (device_native->seat_impl);
   meta_input_settings_get_kbd_a11y_settings (input_settings, &a11y_settings);
   /* Settings use int, we use uint, make sure we dont go negative */
   return MAX (0, a11y_settings.slowkeys_delay);
@@ -342,10 +343,11 @@ stop_slow_keys (ClutterEvent                *event,
 static guint
 get_debounce_delay (ClutterInputDevice *device)
 {
+  MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
   MetaKbdA11ySettings a11y_settings;
   MetaInputSettings *input_settings;
 
-  input_settings = meta_backend_get_input_settings (meta_get_backend ());
+  input_settings = meta_seat_impl_get_input_settings (device_native->seat_impl);
   meta_input_settings_get_kbd_a11y_settings (input_settings, &a11y_settings);
   /* Settings use int, we use uint, make sure we dont go negative */
   return MAX (0, a11y_settings.debounce_delay);
diff --git a/src/backends/native/meta-input-settings-native.c 
b/src/backends/native/meta-input-settings-native.c
index 247afbe6d1..b50ad8a775 100644
--- a/src/backends/native/meta-input-settings-native.c
+++ b/src/backends/native/meta-input-settings-native.c
@@ -33,6 +33,55 @@
 
 G_DEFINE_TYPE (MetaInputSettingsNative, meta_input_settings_native, META_TYPE_INPUT_SETTINGS)
 
+enum
+{
+  PROP_0,
+  PROP_SEAT_IMPL,
+  N_PROPS,
+};
+
+static GParamSpec *props[N_PROPS] = { 0 };
+
+static void
+meta_input_settings_native_set_property (GObject      *object,
+                                         guint         prop_id,
+                                         const GValue *value,
+                                         GParamSpec   *pspec)
+{
+  MetaInputSettingsNative *input_settings_native =
+    META_INPUT_SETTINGS_NATIVE (object);
+
+  switch (prop_id)
+    {
+    case PROP_SEAT_IMPL:
+      input_settings_native->seat_impl = g_value_get_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+meta_input_settings_native_get_property (GObject    *object,
+                                         guint       prop_id,
+                                         GValue     *value,
+                                         GParamSpec *pspec)
+{
+  MetaInputSettingsNative *input_settings_native =
+    META_INPUT_SETTINGS_NATIVE (object);
+
+  switch (prop_id)
+    {
+    case PROP_SEAT_IMPL:
+      g_value_set_object (value, input_settings_native->seat_impl);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
 static void
 meta_input_settings_native_set_send_events (MetaInputSettings        *settings,
                                             ClutterInputDevice       *device,
@@ -400,10 +449,10 @@ meta_input_settings_native_set_keyboard_repeat (MetaInputSettings *settings,
                                                 guint              delay,
                                                 guint              interval)
 {
-  ClutterSeat *seat;
+  MetaInputSettingsNative *input_settings_native;
 
-  seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
-  meta_seat_impl_set_keyboard_repeat (META_SEAT_NATIVE (seat)->impl,
+  input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);
+  meta_seat_impl_set_keyboard_repeat (input_settings_native->seat_impl,
                                       enabled, delay, interval);
 }
 
@@ -689,6 +738,10 @@ static void
 meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
 {
   MetaInputSettingsClass *input_settings_class = META_INPUT_SETTINGS_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = meta_input_settings_native_set_property;
+  object_class->get_property = meta_input_settings_native_get_property;
 
   input_settings_class->set_send_events = meta_input_settings_native_set_send_events;
   input_settings_class->set_matrix = meta_input_settings_native_set_matrix;
@@ -723,9 +776,28 @@ meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
 
   input_settings_class->has_two_finger_scroll = meta_input_settings_native_has_two_finger_scroll;
   input_settings_class->is_trackball_device = meta_input_settings_native_is_trackball_device;
+
+  props[PROP_SEAT_IMPL] =
+    g_param_spec_object ("seat-impl",
+                         "Seat Impl",
+                         "Seat Impl",
+                         META_TYPE_SEAT_IMPL,
+                         CLUTTER_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (object_class, N_PROPS, props);
 }
 
 static void
 meta_input_settings_native_init (MetaInputSettingsNative *settings)
 {
 }
+
+MetaInputSettings *
+meta_input_settings_native_new (MetaSeatImpl *seat_impl)
+{
+  return g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE,
+                       "seat-impl", seat_impl,
+                       "seat", seat_impl->seat,
+                       NULL);
+}
diff --git a/src/backends/native/meta-input-settings-native.h 
b/src/backends/native/meta-input-settings-native.h
index ee600d5d83..61c5335201 100644
--- a/src/backends/native/meta-input-settings-native.h
+++ b/src/backends/native/meta-input-settings-native.h
@@ -37,6 +37,7 @@ typedef struct _MetaInputSettingsNativeClass MetaInputSettingsNativeClass;
 struct _MetaInputSettingsNative
 {
   MetaInputSettings parent_instance;
+  MetaSeatImpl *seat_impl;
 };
 
 struct _MetaInputSettingsNativeClass
@@ -46,4 +47,6 @@ struct _MetaInputSettingsNativeClass
 
 GType meta_input_settings_native_get_type (void) G_GNUC_CONST;
 
+MetaInputSettings * meta_input_settings_native_new (MetaSeatImpl *seat);
+
 #endif /* META_INPUT_SETTINGS_NATIVE_H */
diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c
index 14e20b8440..2677176e44 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -39,6 +39,7 @@
 #include "backends/native/meta-event-native.h"
 #include "backends/native/meta-input-device-native.h"
 #include "backends/native/meta-input-device-tool-native.h"
+#include "backends/native/meta-input-settings-native.h"
 #include "backends/native/meta-keymap-native.h"
 #include "backends/native/meta-virtual-input-device-native.h"
 #include "clutter/clutter-mutter.h"
@@ -1532,7 +1533,7 @@ process_base_event (MetaSeatImpl          *seat,
   struct libinput_device *libinput_device;
   MetaInputSettings *input_settings;
 
-  input_settings = meta_backend_get_input_settings (meta_get_backend ());
+  input_settings = seat->input_settings;
 
   switch (libinput_event_get_type (event))
     {
@@ -1614,7 +1615,8 @@ translate_tool_type (struct libinput_tablet_tool *libinput_tool)
 }
 
 static void
-input_device_update_tool (ClutterInputDevice          *input_device,
+input_device_update_tool (MetaSeatImpl                *seat,
+                          ClutterInputDevice          *input_device,
                           struct libinput_tablet_tool *libinput_tool)
 {
   MetaInputDeviceNative *evdev_device = META_INPUT_DEVICE_NATIVE (input_device);
@@ -1641,7 +1643,7 @@ input_device_update_tool (ClutterInputDevice          *input_device,
   if (evdev_device->last_tool != tool)
     {
       evdev_device->last_tool = tool;
-      input_settings = meta_backend_get_input_settings (meta_get_backend ());
+      input_settings = seat->input_settings;
       meta_input_settings_notify_tool_change (input_settings, input_device, tool);
     }
 }
@@ -2224,10 +2226,10 @@ process_device_event (MetaSeatImpl          *seat,
         libinput_tool = libinput_event_tablet_tool_get_tool (tablet_event);
 
         if (in)
-          input_device_update_tool (device, libinput_tool);
+          input_device_update_tool (seat, device, libinput_tool);
         notify_proximity (device, time, in);
         if (!in)
-          input_device_update_tool (device, NULL);
+          input_device_update_tool (seat, device, NULL);
 
         break;
       }
@@ -2480,6 +2482,8 @@ meta_seat_impl_constructed (GObject *object)
 
   udev_unref (udev);
 
+  seat->input_settings = meta_input_settings_native_new (seat);
+
   seat->udev_client = g_udev_client_new ((const char *[]) { "input", NULL });
 
   source = meta_event_source_new (seat);
@@ -3124,7 +3128,7 @@ meta_seat_impl_notify_kbd_a11y_flags_changed (MetaSeatImpl          *impl,
 {
   MetaInputSettings *input_settings;
 
-  input_settings = meta_backend_get_input_settings (meta_get_backend ());
+  input_settings = impl->input_settings;
   meta_input_settings_notify_kbd_a11y_change (input_settings,
                                               new_flags, what_changed);
   g_signal_emit (impl, signals[KBD_A11Y_FLAGS_CHANGED], 0,
@@ -3145,3 +3149,9 @@ meta_seat_impl_notify_bell (MetaSeatImpl *impl)
 {
   g_signal_emit (impl, signals[BELL], 0);
 }
+
+MetaInputSettings *
+meta_seat_impl_get_input_settings (MetaSeatImpl *impl)
+{
+  return impl->input_settings;
+}
diff --git a/src/backends/native/meta-seat-impl.h b/src/backends/native/meta-seat-impl.h
index 9d6c1d3e4f..b35b14191a 100644
--- a/src/backends/native/meta-seat-impl.h
+++ b/src/backends/native/meta-seat-impl.h
@@ -83,6 +83,7 @@ struct _MetaSeatImpl
   MetaPointerConstraintImpl *pointer_constraint;
 
   MetaKeymapNative *keymap;
+  MetaInputSettings *input_settings;
 
   MetaViewportInfo *viewports;
 
@@ -263,4 +264,6 @@ void meta_seat_impl_notify_kbd_a11y_mods_state_changed (MetaSeatImpl   *impl,
                                                         xkb_mod_mask_t  new_locked_mods);
 void meta_seat_impl_notify_bell (MetaSeatImpl *impl);
 
+MetaInputSettings * meta_seat_impl_get_input_settings (MetaSeatImpl *impl);
+
 #endif /* META_SEAT_IMPL_H */


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