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




commit d8c29c0f4dc9c11fb0f9def920f39f5e11f9689f
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.

 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 9a40430fbe..3d32f05a39 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"
@@ -175,6 +176,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 ddcf29aafe..e163866050 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"
@@ -122,6 +123,7 @@ struct _MetaBackendPrivate
   MetaOrientationManager *orientation_manager;
   MetaCursorTracker *cursor_tracker;
   MetaInputSettings *input_settings;
+  MetaInputMapper *input_mapper;
   MetaRenderer *renderer;
 #ifdef HAVE_EGL
   MetaEgl *egl;
@@ -447,11 +449,22 @@ on_device_added (ClutterSeat        *seat,
 {
   MetaBackend *backend = META_BACKEND (user_data);
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  ClutterInputDeviceType device_type;
 
   create_device_monitor (backend, device);
 
   if (device_is_physical_touchscreen (device))
     meta_cursor_tracker_set_pointer_visible (priv->cursor_tracker, FALSE);
+
+  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 void
@@ -464,6 +477,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.
    */
@@ -523,6 +538,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)
 {
@@ -560,6 +611,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,
@@ -1464,6 +1523,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 cfaf6bcfde..17f41a7c62 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -137,11 +137,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 38028e2772..4cc68bb323 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,
@@ -143,7 +140,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);
 
@@ -1411,33 +1407,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)
 {
@@ -1470,8 +1439,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);
@@ -1645,7 +1612,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);
 
@@ -1818,44 +1784,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 f3dcd4f4b3..745e20031d 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 *backend_native = META_BACKEND_NATIVE (backend);
+
+  if (!backend_native->input_settings)
+    {
+      backend_native->input_settings =
+        g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE, NULL);
+    }
+
+  return backend_native->input_settings;
 }
 
 static MetaLogicalMonitor *
@@ -661,7 +671,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 =
@@ -683,8 +692,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 7bb47d4b3b..26abf2bd79 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]