[mutter/wip/carlosg/input-thread: 26/48] backends: Make MetaInputMapper take over MetaInputSettings public API




commit 80e661ef6f07adebf4411a417ba07f42886e1785
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Aug 4 14:17:39 2020 +0200

    backends: Make MetaInputMapper take over MetaInputSettings public API
    
    Banish MetaInputSettings from MetaBackend "public" API, it's now meant to
    spend the rest of its days in the backend dungeons, maybe hanging
    off a thread.
    
    MetaInputMapper replaces all external uses.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 src/backends/meta-backend-private.h        |  2 +
 src/backends/meta-backend.c                | 67 +++++++++++++++++++++++++++
 src/backends/meta-input-mapper-private.h   |  3 +-
 src/backends/meta-input-settings-private.h |  5 ---
 src/backends/meta-input-settings.c         | 72 ------------------------------
 src/backends/native/meta-backend-native.c  | 16 +++++--
 src/core/display.c                         | 20 ++++-----
 7 files changed, 93 insertions(+), 92 deletions(-)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 7a04e96002..ace4d7f6ec 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -34,6 +34,7 @@
 #include "backends/meta-backend-types.h"
 #include "backends/meta-cursor-renderer.h"
 #include "backends/meta-egl.h"
+#include "backends/meta-input-mapper-private.h"
 #include "backends/meta-input-settings-private.h"
 #include "backends/meta-monitor-manager-private.h"
 #include "backends/meta-orientation-manager.h"
@@ -178,6 +179,7 @@ gboolean meta_is_stage_views_enabled (void);
 
 gboolean meta_is_stage_views_scaled (void);
 
+MetaInputMapper *meta_backend_get_input_mapper (MetaBackend *backend);
 MetaInputSettings *meta_backend_get_input_settings (MetaBackend *backend);
 
 void meta_backend_notify_keymap_changed (MetaBackend *backend);
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 139a5a5b5e..ef73c0d183 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -56,6 +56,7 @@
 #include "backends/meta-cursor-renderer.h"
 #include "backends/meta-cursor-tracker-private.h"
 #include "backends/meta-idle-monitor-private.h"
+#include "backends/meta-input-mapper-private.h"
 #include "backends/meta-input-settings-private.h"
 #include "backends/meta-logical-monitor.h"
 #include "backends/meta-monitor-manager-dummy.h"
@@ -123,6 +124,7 @@ struct _MetaBackendPrivate
   MetaCursorTracker *cursor_tracker;
   GHashTable *cursor_renderers;
   MetaInputSettings *input_settings;
+  MetaInputMapper *input_mapper;
   MetaRenderer *renderer;
 #ifdef HAVE_EGL
   MetaEgl *egl;
@@ -380,8 +382,19 @@ on_device_added (ClutterSeat        *seat,
                  gpointer            user_data)
 {
   MetaBackend *backend = META_BACKEND (user_data);
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  ClutterInputDeviceType device_type;
 
   create_device_monitor (backend, device);
+  device_type = clutter_input_device_get_device_type (device);
+
+  if (device_type == CLUTTER_TOUCHSCREEN_DEVICE ||
+      device_type == CLUTTER_TABLET_DEVICE ||
+      device_type == CLUTTER_PEN_DEVICE ||
+      device_type == CLUTTER_ERASER_DEVICE ||
+      device_type == CLUTTER_CURSOR_DEVICE ||
+      device_type == CLUTTER_PAD_DEVICE)
+    meta_input_mapper_add_device (priv->input_mapper, device);
 }
 
 static inline gboolean
@@ -453,6 +466,8 @@ on_device_removed (ClutterSeat        *seat,
 
   destroy_device_monitor (backend, device);
 
+  meta_input_mapper_remove_device (priv->input_mapper, device);
+
   /* If the device the user last interacted goes away, check again pointer
    * visibility.
    */
@@ -532,6 +547,42 @@ 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)
+{
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  MetaInputSettings *input_settings = priv->input_settings;
+
+  meta_input_settings_set_device_matrix (input_settings, device, matrix);
+}
+
+static void
+input_mapper_device_enabled_cb (MetaInputMapper    *mapper,
+                                ClutterInputDevice *device,
+                                gboolean            enabled,
+                                MetaBackend        *backend)
+{
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  MetaInputSettings *input_settings = priv->input_settings;
+
+  meta_input_settings_set_device_enabled (input_settings, device, enabled);
+}
+
+static void
+input_mapper_device_aspect_ratio_cb (MetaInputMapper    *mapper,
+                                     ClutterInputDevice *device,
+                                     double              aspect_ratio,
+                                     MetaBackend        *backend)
+{
+  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);
+}
+
 static void
 meta_backend_real_post_init (MetaBackend *backend)
 {
@@ -571,6 +622,14 @@ meta_backend_real_post_init (MetaBackend *backend)
       meta_input_settings_maybe_restore_numlock_state (priv->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,
@@ -1484,6 +1543,14 @@ meta_is_stage_views_scaled (void)
   return layout_mode == META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
 }
 
+MetaInputMapper *
+meta_backend_get_input_mapper (MetaBackend *backend)
+{
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+
+  return priv->input_mapper;
+}
+
 MetaInputSettings *
 meta_backend_get_input_settings (MetaBackend *backend)
 {
diff --git a/src/backends/meta-input-mapper-private.h b/src/backends/meta-input-mapper-private.h
index 67ffbe5652..63d480dba7 100644
--- a/src/backends/meta-input-mapper-private.h
+++ b/src/backends/meta-input-mapper-private.h
@@ -23,7 +23,8 @@
 #define META_INPUT_MAPPER_H
 
 #include <clutter/clutter.h>
-#include "meta-monitor-manager-private.h"
+
+#include "backends/meta-backend-types.h"
 
 #define META_TYPE_INPUT_MAPPER (meta_input_mapper_get_type ())
 
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index d1ba001db5..3c3abde5a3 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -136,11 +136,6 @@ struct _MetaInputSettingsClass
                                     ClutterInputDevice *device);
 };
 
-GSettings *           meta_input_settings_get_tablet_settings (MetaInputSettings  *settings,
-                                                               ClutterInputDevice *device);
-MetaLogicalMonitor *  meta_input_settings_get_tablet_logical_monitor (MetaInputSettings  *settings,
-                                                                      ClutterInputDevice *device);
-
 void meta_input_settings_maybe_save_numlock_state    (MetaInputSettings *input_settings);
 void meta_input_settings_maybe_restore_numlock_state (MetaInputSettings *input_settings);
 
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
index 2d75e0bb5c..a4b0593922 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -82,9 +82,6 @@ struct _MetaInputSettingsPrivate
   GHashTable *current_tools;
 
   GHashTable *two_finger_devices;
-
-  /* For absolute devices with no mapping in settings */
-  MetaInputMapper *input_mapper;
 };
 
 typedef gboolean (* ConfigBoolMappingFunc) (MetaInputSettings  *input_settings,
@@ -141,7 +138,6 @@ meta_input_settings_dispose (GObject *object)
   g_clear_object (&priv->gsd_settings);
   g_clear_object (&priv->keyboard_a11y_settings);
   g_clear_object (&priv->mouse_a11y_settings);
-  g_clear_object (&priv->input_mapper);
   g_clear_pointer (&priv->mappable_devices, g_hash_table_unref);
   g_clear_pointer (&priv->current_tools, g_hash_table_unref);
 
@@ -1406,33 +1402,6 @@ lookup_tool_settings (ClutterInputDeviceTool *tool,
   return tool_settings;
 }
 
-static void
-input_mapper_device_mapped_cb (MetaInputMapper    *mapper,
-                               ClutterInputDevice *device,
-                               float               matrix[6],
-                               MetaInputSettings  *input_settings)
-{
-  meta_input_settings_set_device_matrix (input_settings, device, matrix);
-}
-
-static void
-input_mapper_device_enabled_cb (MetaInputMapper    *mapper,
-                                ClutterInputDevice *device,
-                                gboolean            enabled,
-                                MetaInputSettings  *input_settings)
-{
-  meta_input_settings_set_device_enabled (input_settings, device, enabled);
-}
-
-static void
-input_mapper_device_aspect_ratio_cb (MetaInputMapper    *mapper,
-                                     ClutterInputDevice *device,
-                                     double              aspect_ratio,
-                                     MetaInputSettings  *input_settings)
-{
-  meta_input_settings_set_device_aspect_ratio (input_settings, device, aspect_ratio);
-}
-
 static void
 device_mapping_info_free (DeviceMappingInfo *info)
 {
@@ -1465,8 +1434,6 @@ check_add_mappable_device (MetaInputSettings  *input_settings,
   if (!settings)
     return FALSE;
 
-  meta_input_mapper_add_device (priv->input_mapper, device);
-
   priv = meta_input_settings_get_instance_private (input_settings);
 
   info = g_slice_new0 (DeviceMappingInfo);
@@ -1640,7 +1607,6 @@ meta_input_settings_device_removed (ClutterSeat        *seat,
   MetaInputSettingsPrivate *priv;
 
   priv = meta_input_settings_get_instance_private (input_settings);
-  meta_input_mapper_remove_device (priv->input_mapper, device);
   g_hash_table_remove (priv->mappable_devices, device);
   g_hash_table_remove (priv->current_tools, device);
 
@@ -1813,44 +1779,6 @@ meta_input_settings_init (MetaInputSettings *settings)
     g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) current_tool_info_free);
 
   priv->two_finger_devices = g_hash_table_new (NULL, NULL);
-
-  priv->input_mapper = meta_input_mapper_new ();
-  g_signal_connect (priv->input_mapper, "device-mapped",
-                    G_CALLBACK (input_mapper_device_mapped_cb), settings);
-  g_signal_connect (priv->input_mapper, "device-enabled",
-                    G_CALLBACK (input_mapper_device_enabled_cb), settings);
-  g_signal_connect (priv->input_mapper, "device-aspect-ratio",
-                    G_CALLBACK (input_mapper_device_aspect_ratio_cb), settings);
-}
-
-GSettings *
-meta_input_settings_get_tablet_settings (MetaInputSettings  *settings,
-                                         ClutterInputDevice *device)
-{
-  MetaInputSettingsPrivate *priv;
-  DeviceMappingInfo *info;
-
-  g_return_val_if_fail (META_IS_INPUT_SETTINGS (settings), NULL);
-  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
-
-  priv = meta_input_settings_get_instance_private (settings);
-  info = g_hash_table_lookup (priv->mappable_devices, device);
-
-  return info ? g_object_ref (info->settings) : NULL;
-}
-
-MetaLogicalMonitor *
-meta_input_settings_get_tablet_logical_monitor (MetaInputSettings  *settings,
-                                                ClutterInputDevice *device)
-{
-  MetaInputSettingsPrivate *priv;
-
-  g_return_val_if_fail (META_IS_INPUT_SETTINGS (settings), NULL);
-  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
-
-  priv = meta_input_settings_get_instance_private (settings);
-
-  return meta_input_mapper_get_device_logical_monitor (priv->input_mapper, device);
 }
 
 void
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 13575043a8..6a5f253d14 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -73,6 +73,7 @@ struct _MetaBackendNative
   MetaLauncher *launcher;
   MetaUdev *udev;
   MetaKms *kms;
+  MetaInputSettings *input_settings;
 
   gulong udev_device_added_handler_id;
 };
@@ -100,6 +101,7 @@ meta_backend_native_finalize (GObject *object)
   g_clear_object (&native->udev);
   g_clear_object (&native->kms);
   meta_launcher_free (native->launcher);
+  g_clear_object (&native->input_settings);
 
   G_OBJECT_CLASS (meta_backend_native_parent_class)->finalize (object);
 }
@@ -235,7 +237,15 @@ meta_backend_native_create_renderer (MetaBackend *backend,
 static MetaInputSettings *
 meta_backend_native_create_input_settings (MetaBackend *backend)
 {
-  return g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE, NULL);
+  MetaBackendNative *native = META_BACKEND_NATIVE (backend);
+
+  if (!native->input_settings)
+    {
+      native->input_settings = g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE,
+                                             NULL);
+    }
+
+  return native->input_settings;
 }
 
 static MetaLogicalMonitor *
@@ -654,7 +664,6 @@ void meta_backend_native_resume (MetaBackendNative *native)
     meta_backend_get_monitor_manager (backend);
   MetaMonitorManagerKms *monitor_manager_kms =
     META_MONITOR_MANAGER_KMS (monitor_manager);
-  MetaInputSettings *input_settings;
   MetaIdleMonitor *idle_monitor;
   ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
   MetaSeatNative *seat =
@@ -676,8 +685,7 @@ void meta_backend_native_resume (MetaBackendNative *native)
   idle_monitor = meta_idle_monitor_get_core ();
   meta_idle_monitor_reset_idletime (idle_monitor);
 
-  input_settings = meta_backend_get_input_settings (backend);
-  meta_input_settings_maybe_restore_numlock_state (input_settings);
+  meta_input_settings_maybe_restore_numlock_state (native->input_settings);
 
   clutter_seat_ensure_a11y_state (CLUTTER_SEAT (seat));
 }
diff --git a/src/core/display.c b/src/core/display.c
index a665de40c3..8521e0ad6d 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -45,7 +45,7 @@
 #include "backends/meta-cursor-tracker-private.h"
 #include "backends/meta-idle-monitor-dbus.h"
 #include "backends/meta-input-device-private.h"
-#include "backends/meta-input-settings-private.h"
+#include "backends/meta-input-mapper-private.h"
 #include "backends/meta-stage-private.h"
 #include "backends/x11/meta-backend-x11.h"
 #include "backends/x11/meta-event-x11.h"
@@ -2909,7 +2909,7 @@ meta_display_request_pad_osd (MetaDisplay        *display,
                               gboolean            edition_mode)
 {
   MetaBackend *backend = meta_get_backend ();
-  MetaInputSettings *input_settings;
+  MetaInputMapper *input_mapper;
   const gchar *layout_path = NULL;
   ClutterActor *osd;
   MetaLogicalMonitor *logical_monitor;
@@ -2925,13 +2925,13 @@ meta_display_request_pad_osd (MetaDisplay        *display,
   if (display->current_pad_osd)
     return;
 
-  input_settings = meta_backend_get_input_settings (meta_get_backend ());
+  input_mapper = meta_backend_get_input_mapper (meta_get_backend ());
 
-  if (input_settings)
+  if (input_mapper)
     {
-      settings = meta_input_settings_get_tablet_settings (input_settings, pad);
+      settings = meta_input_mapper_get_tablet_settings (input_mapper, pad);
       logical_monitor =
-        meta_input_settings_get_tablet_logical_monitor (input_settings, pad);
+        meta_input_mapper_get_device_logical_monitor (input_mapper, pad);
 #ifdef HAVE_LIBWACOM
       wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (pad));
       layout_path = libwacom_get_layout_filename (wacom_device);
@@ -3015,15 +3015,15 @@ static gint
 lookup_tablet_monitor (MetaDisplay        *display,
                        ClutterInputDevice *device)
 {
-  MetaInputSettings *input_settings;
+  MetaInputMapper *input_mapper;
   MetaLogicalMonitor *monitor;
   gint monitor_idx = -1;
 
-  input_settings = meta_backend_get_input_settings (meta_get_backend ());
-  if (!input_settings)
+  input_mapper = meta_backend_get_input_mapper (meta_get_backend ());
+  if (!input_mapper)
     return -1;
 
-  monitor = meta_input_settings_get_tablet_logical_monitor (input_settings, device);
+  monitor = meta_input_mapper_get_device_logical_monitor (input_mapper, device);
 
   if (monitor)
     {


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