[mutter/wip/carlosg/input-thread: 121/130] backends: Straighten MetaInputSettings creation




commit 951727e10ffb44bd2861daed5d97006d9573a0d4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Nov 19 16:00:12 2020 +0100

    backends: Straighten MetaInputSettings creation
    
    We have "create" and "get" methods, and a "create" vmethod. Make it all
    "get" so the backend implementations can keep their own reference without
    completely lying.

 src/backends/meta-backend-private.h               |  2 +-
 src/backends/meta-backend.c                       | 55 +++++++++--------------
 src/backends/native/meta-backend-native.c         |  4 +-
 src/backends/x11/cm/meta-backend-x11-cm.c         | 13 ++++--
 src/backends/x11/nested/meta-backend-x11-nested.c |  4 +-
 5 files changed, 36 insertions(+), 42 deletions(-)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 3d32f05a39..0ea419069f 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -69,7 +69,7 @@ struct _MetaBackendClass
   MetaCursorTracker * (* create_cursor_tracker) (MetaBackend *backend);
   MetaRenderer * (* create_renderer) (MetaBackend *backend,
                                       GError     **error);
-  MetaInputSettings * (* create_input_settings) (MetaBackend *backend);
+  MetaInputSettings * (* get_input_settings) (MetaBackend *backend);
 
   gboolean (* grab_device) (MetaBackend *backend,
                             int          device_id,
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 97f47f09bb..b823f2080d 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -213,7 +213,6 @@ meta_backend_finalize (GObject *object)
   g_clear_object (&priv->current_device);
   g_clear_object (&priv->monitor_manager);
   g_clear_object (&priv->orientation_manager);
-  g_clear_object (&priv->input_settings);
 #ifdef HAVE_REMOTE_DESKTOP
   g_clear_object (&priv->remote_desktop);
   g_clear_object (&priv->screen_cast);
@@ -532,21 +531,12 @@ create_device_monitors (MetaBackend *backend,
   g_list_free (devices);
 }
 
-static MetaInputSettings *
-meta_backend_create_input_settings (MetaBackend *backend)
-{
-  return META_BACKEND_GET_CLASS (backend)->create_input_settings (backend);
-}
-
 static void
 input_mapper_device_mapped_cb (MetaInputMapper    *mapper,
                                ClutterInputDevice *device,
                                float               matrix[6],
-                               MetaBackend        *backend)
+                               MetaInputSettings  *input_settings)
 {
-  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-  MetaInputSettings *input_settings = priv->input_settings;
-
   meta_input_settings_set_device_matrix (input_settings, device, matrix);
 }
 
@@ -554,11 +544,8 @@ static void
 input_mapper_device_enabled_cb (MetaInputMapper    *mapper,
                                 ClutterInputDevice *device,
                                 gboolean            enabled,
-                                MetaBackend        *backend)
+                                MetaInputSettings  *input_settings)
 {
-  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-  MetaInputSettings *input_settings = priv->input_settings;
-
   meta_input_settings_set_device_enabled (input_settings, device, enabled);
 }
 
@@ -566,11 +553,8 @@ static void
 input_mapper_device_aspect_ratio_cb (MetaInputMapper    *mapper,
                                      ClutterInputDevice *device,
                                      double              aspect_ratio,
-                                     MetaBackend        *backend)
+                                     MetaInputSettings  *input_settings)
 {
-  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-  MetaInputSettings *input_settings = priv->input_settings;
-
   meta_input_settings_set_device_aspect_ratio (input_settings, device, aspect_ratio);
 }
 
@@ -588,6 +572,7 @@ meta_backend_real_post_init (MetaBackend *backend)
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
   ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
   ClutterKeymap *keymap = clutter_seat_get_keymap (seat);
+  MetaInputSettings *input_settings;
 
   priv->stage = meta_stage_new (backend);
   clutter_actor_realize (priv->stage);
@@ -611,25 +596,29 @@ meta_backend_real_post_init (MetaBackend *backend)
                            G_CALLBACK (on_device_removed), backend,
                            G_CONNECT_AFTER);
 
-  priv->input_settings = meta_backend_create_input_settings (backend);
+  priv->input_mapper = meta_input_mapper_new ();
+
+  input_settings = meta_backend_get_input_settings (backend);
 
-  if (priv->input_settings)
+  if (input_settings)
     {
       priv->keymap_state_changed_id =
         g_signal_connect_swapped (keymap, "state-changed",
                                   G_CALLBACK (meta_input_settings_maybe_save_numlock_state),
-                                  priv->input_settings);
-      meta_input_settings_maybe_restore_numlock_state (priv->input_settings);
+                                  input_settings);
+      meta_input_settings_maybe_restore_numlock_state (input_settings);
+
+      g_signal_connect (priv->input_mapper, "device-mapped",
+                        G_CALLBACK (input_mapper_device_mapped_cb),
+                        input_settings);
+      g_signal_connect (priv->input_mapper, "device-enabled",
+                        G_CALLBACK (input_mapper_device_enabled_cb),
+                        input_settings);
+      g_signal_connect (priv->input_mapper, "device-aspect-ratio",
+                        G_CALLBACK (input_mapper_device_aspect_ratio_cb),
+                        input_settings);
     }
 
-  priv->input_mapper = meta_input_mapper_new ();
-  g_signal_connect (priv->input_mapper, "device-mapped",
-                    G_CALLBACK (input_mapper_device_mapped_cb), backend);
-  g_signal_connect (priv->input_mapper, "device-enabled",
-                    G_CALLBACK (input_mapper_device_enabled_cb), backend);
-  g_signal_connect (priv->input_mapper, "device-aspect-ratio",
-                    G_CALLBACK (input_mapper_device_aspect_ratio_cb), backend);
-
 #ifdef HAVE_REMOTE_DESKTOP
   priv->dbus_session_watcher = g_object_new (META_TYPE_DBUS_SESSION_WATCHER, NULL);
   priv->screen_cast = meta_screen_cast_new (backend,
@@ -1550,9 +1539,7 @@ meta_backend_get_input_mapper (MetaBackend *backend)
 MetaInputSettings *
 meta_backend_get_input_settings (MetaBackend *backend)
 {
-  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
-  return priv->input_settings;
+  return META_BACKEND_GET_CLASS (backend)->get_input_settings (backend);
 }
 
 /**
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index c7809a8b58..c5aaa42d47 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -259,7 +259,7 @@ meta_backend_native_create_renderer (MetaBackend *backend,
 }
 
 static MetaInputSettings *
-meta_backend_native_create_input_settings (MetaBackend *backend)
+meta_backend_native_get_input_settings (MetaBackend *backend)
 {
   MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
 
@@ -567,7 +567,7 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
   backend_class->create_monitor_manager = meta_backend_native_create_monitor_manager;
   backend_class->get_cursor_renderer = meta_backend_native_get_cursor_renderer;
   backend_class->create_renderer = meta_backend_native_create_renderer;
-  backend_class->create_input_settings = meta_backend_native_create_input_settings;
+  backend_class->get_input_settings = meta_backend_native_get_input_settings;
 
   backend_class->get_current_logical_monitor = meta_backend_native_get_current_logical_monitor;
 
diff --git a/src/backends/x11/cm/meta-backend-x11-cm.c b/src/backends/x11/cm/meta-backend-x11-cm.c
index 35e1acf9f0..3b39178e0d 100644
--- a/src/backends/x11/cm/meta-backend-x11-cm.c
+++ b/src/backends/x11/cm/meta-backend-x11-cm.c
@@ -46,6 +46,8 @@ struct _MetaBackendX11Cm
   char *keymap_variants;
   char *keymap_options;
   int locked_group;
+
+  MetaInputSettings *input_settings;
 };
 
 G_DEFINE_TYPE (MetaBackendX11Cm, meta_backend_x11_cm, META_TYPE_BACKEND_X11)
@@ -87,8 +89,11 @@ meta_backend_x11_cm_post_init (MetaBackend *backend)
 {
   MetaBackendClass *parent_backend_class =
     META_BACKEND_CLASS (meta_backend_x11_cm_parent_class);
+  MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend);
   ClutterSeat *seat;
 
+  x11_cm->input_settings = g_object_new (META_TYPE_INPUT_SETTINGS_X11, NULL);
+
   parent_backend_class->post_init (backend);
 
   seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
@@ -143,9 +148,11 @@ meta_backend_x11_cm_create_cursor_tracker (MetaBackend *backend)
 }
 
 static MetaInputSettings *
-meta_backend_x11_cm_create_input_settings (MetaBackend *backend)
+meta_backend_x11_cm_get_input_settings (MetaBackend *backend)
 {
-  return g_object_new (META_TYPE_INPUT_SETTINGS_X11, NULL);
+  MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend);
+
+  return x11_cm->input_settings;
 }
 
 static void
@@ -457,7 +464,7 @@ meta_backend_x11_cm_class_init (MetaBackendX11CmClass *klass)
   backend_class->create_monitor_manager = meta_backend_x11_cm_create_monitor_manager;
   backend_class->get_cursor_renderer = meta_backend_x11_cm_get_cursor_renderer;
   backend_class->create_cursor_tracker = meta_backend_x11_cm_create_cursor_tracker;
-  backend_class->create_input_settings = meta_backend_x11_cm_create_input_settings;
+  backend_class->get_input_settings = meta_backend_x11_cm_get_input_settings;
   backend_class->update_screen_size = meta_backend_x11_cm_update_screen_size;
   backend_class->select_stage_events = meta_backend_x11_cm_select_stage_events;
   backend_class->lock_layout_group = meta_backend_x11_cm_lock_layout_group;
diff --git a/src/backends/x11/nested/meta-backend-x11-nested.c 
b/src/backends/x11/nested/meta-backend-x11-nested.c
index 041f4b87af..425ddcb1a1 100644
--- a/src/backends/x11/nested/meta-backend-x11-nested.c
+++ b/src/backends/x11/nested/meta-backend-x11-nested.c
@@ -84,7 +84,7 @@ meta_backend_x11_nested_get_cursor_renderer (MetaBackend        *backend,
 }
 
 static MetaInputSettings *
-meta_backend_x11_nested_create_input_settings (MetaBackend *backend)
+meta_backend_x11_nested_get_input_settings (MetaBackend *backend)
 {
   return NULL;
 }
@@ -289,7 +289,7 @@ meta_backend_x11_nested_class_init (MetaBackendX11NestedClass *klass)
   backend_class->create_renderer = meta_backend_x11_nested_create_renderer;
   backend_class->create_monitor_manager = meta_backend_x11_nested_create_monitor_manager;
   backend_class->get_cursor_renderer = meta_backend_x11_nested_get_cursor_renderer;
-  backend_class->create_input_settings = meta_backend_x11_nested_create_input_settings;
+  backend_class->get_input_settings = meta_backend_x11_nested_get_input_settings;
   backend_class->update_screen_size = meta_backend_x11_nested_update_screen_size;
   backend_class->select_stage_events = meta_backend_x11_nested_select_stage_events;
   backend_class->lock_layout_group = meta_backend_x11_nested_lock_layout_group;


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