[mutter/wip/carlosg/input-thread: 1/48] backends: Add meta_backend_get_cursor_renderer_for_device()




commit 575d9cb492d8b4dc12bb8e2a605c8f13e1ea0886
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jul 10 23:28:50 2020 +0200

    backends: Add meta_backend_get_cursor_renderer_for_device()
    
    Different devices may get standalone cursor renderers, add this API
    to adapt slowly to this. The meta_backend_get_cursor_renderer() call
    still exists, but shortcuts to the mouse pointer's renderer (as it
    actually did before).
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403

 src/backends/meta-backend-private.h               |  5 +-
 src/backends/meta-backend.c                       | 58 +++++++++++++++++++++--
 src/backends/native/meta-backend-native.c         | 12 +++--
 src/backends/native/meta-seat-native.c            | 22 +++++++++
 src/backends/native/meta-seat-native.h            |  5 ++
 src/backends/x11/cm/meta-backend-x11-cm.c         | 20 ++++++--
 src/backends/x11/nested/meta-backend-x11-nested.c | 22 +++++++--
 7 files changed, 124 insertions(+), 20 deletions(-)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 2c375e84c4..b90e17e4a8 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -67,7 +67,8 @@ struct _MetaBackendClass
 
   MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend,
                                                    GError     **error);
-  MetaCursorRenderer * (* create_cursor_renderer) (MetaBackend *backend);
+  MetaCursorRenderer * (* get_cursor_renderer) (MetaBackend        *backend,
+                                                ClutterInputDevice *device);
   MetaCursorTracker * (* create_cursor_tracker) (MetaBackend *backend);
   MetaRenderer * (* create_renderer) (MetaBackend *backend,
                                       GError     **error);
@@ -131,6 +132,8 @@ META_EXPORT_TEST
 MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend);
 MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend);
 MetaCursorTracker * meta_backend_get_cursor_tracker (MetaBackend *backend);
+MetaCursorRenderer * meta_backend_get_cursor_renderer_for_device (MetaBackend        *backend,
+                                                                  ClutterInputDevice *device);
 MetaCursorRenderer * meta_backend_get_cursor_renderer (MetaBackend *backend);
 META_EXPORT_TEST
 MetaRenderer * meta_backend_get_renderer (MetaBackend *backend);
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 4a7300f202..a0a62abd0b 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -120,7 +120,7 @@ struct _MetaBackendPrivate
   MetaMonitorManager *monitor_manager;
   MetaOrientationManager *orientation_manager;
   MetaCursorTracker *cursor_tracker;
-  MetaCursorRenderer *cursor_renderer;
+  GHashTable *cursor_renderers;
   MetaInputSettings *input_settings;
   MetaRenderer *renderer;
 #ifdef HAVE_EGL
@@ -213,6 +213,8 @@ meta_backend_finalize (GObject *object)
   g_clear_pointer (&priv->wacom_db, libwacom_database_destroy);
 #endif
 
+  g_hash_table_unref (priv->cursor_renderers);
+
   if (priv->sleep_signal_id)
     g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id);
   if (priv->upower_watch_id)
@@ -264,6 +266,19 @@ reset_pointer_position (MetaBackend *backend)
                              primary->rect.y + primary->rect.height * 0.9);
 }
 
+static void
+update_cursors (MetaBackend *backend)
+{
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  MetaCursorRenderer *renderer;
+  GHashTableIter iter;
+
+  g_hash_table_iter_init (&iter, priv->cursor_renderers);
+
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &renderer))
+    meta_cursor_renderer_force_update (renderer);
+}
+
 void
 meta_backend_monitors_changed (MetaBackend *backend)
 {
@@ -289,7 +304,7 @@ meta_backend_monitors_changed (MetaBackend *backend)
         }
     }
 
-  meta_cursor_renderer_force_update (priv->cursor_renderer);
+  update_cursors (backend);
 }
 
 void
@@ -456,6 +471,8 @@ on_device_removed (ClutterSeat        *seat,
                                                    !has_touchscreen);
         }
     }
+
+  g_hash_table_remove (priv->cursor_renderers, device);
 }
 
 static void
@@ -520,8 +537,6 @@ meta_backend_real_post_init (MetaBackend *backend)
 
   meta_backend_sync_screen_size (backend);
 
-  priv->cursor_renderer = META_BACKEND_GET_CLASS (backend)->create_cursor_renderer (backend);
-
   priv->device_monitors =
     g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref);
 
@@ -1033,6 +1048,9 @@ initable_iface_init (GInitableIface *initable_iface)
 static void
 meta_backend_init (MetaBackend *backend)
 {
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+
+  priv->cursor_renderers = g_hash_table_new (NULL, NULL);
   _backend = backend;
 }
 
@@ -1085,8 +1103,38 @@ MetaCursorRenderer *
 meta_backend_get_cursor_renderer (MetaBackend *backend)
 {
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  ClutterInputDevice *pointer;
+  ClutterSeat *seat;
+
+  seat = clutter_backend_get_default_seat (priv->clutter_backend);
+  pointer = clutter_seat_get_pointer (seat);
+
+  return meta_backend_get_cursor_renderer_for_device (backend, pointer);
+}
+
+MetaCursorRenderer *
+meta_backend_get_cursor_renderer_for_device (MetaBackend        *backend,
+                                             ClutterInputDevice *device)
+{
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  MetaCursorRenderer *renderer;
+
+  g_return_val_if_fail (META_IS_BACKEND (backend), NULL);
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
+  g_return_val_if_fail (clutter_input_device_get_device_type (device) !=
+                        CLUTTER_KEYBOARD_DEVICE, NULL);
+
+  renderer = g_hash_table_lookup (priv->cursor_renderers, device);
+
+  if (!renderer)
+    {
+      renderer = META_BACKEND_GET_CLASS (backend)->get_cursor_renderer (backend,
+                                                                        device);
+      if (renderer)
+        g_hash_table_insert (priv->cursor_renderers, device, renderer);
+    }
 
-  return priv->cursor_renderer;
+  return renderer;
 }
 
 /**
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index f0dbbf8795..95f930066b 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -49,7 +49,6 @@
 #include "backends/meta-settings-private.h"
 #include "backends/meta-stage-private.h"
 #include "backends/native/meta-clutter-backend-native.h"
-#include "backends/native/meta-cursor-renderer-native.h"
 #include "backends/native/meta-event-native.h"
 #include "backends/native/meta-input-settings-native.h"
 #include "backends/native/meta-kms.h"
@@ -186,9 +185,14 @@ meta_backend_native_create_monitor_manager (MetaBackend *backend,
 }
 
 static MetaCursorRenderer *
-meta_backend_native_create_cursor_renderer (MetaBackend *backend)
+meta_backend_native_get_cursor_renderer (MetaBackend        *backend,
+                                         ClutterInputDevice *device)
 {
-  return META_CURSOR_RENDERER (meta_cursor_renderer_native_new (backend));
+  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
+  MetaSeatNative *seat =
+    META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
+
+  return meta_seat_native_get_cursor_renderer (seat, device);
 }
 
 static MetaRenderer *
@@ -516,7 +520,7 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
   backend_class->post_init = meta_backend_native_post_init;
 
   backend_class->create_monitor_manager = meta_backend_native_create_monitor_manager;
-  backend_class->create_cursor_renderer = meta_backend_native_create_cursor_renderer;
+  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;
 
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index dd3f846a15..01863cf68c 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -2600,6 +2600,7 @@ meta_seat_native_finalize (GObject *object)
   if (seat->touch_states)
     g_hash_table_destroy (seat->touch_states);
 
+  g_object_unref (seat->cursor_renderer);
   g_object_unref (seat->udev_client);
 
   meta_event_source_free (seat->event_source);
@@ -3240,3 +3241,24 @@ meta_seat_native_set_pointer_constraint (MetaSeatNative            *seat,
         meta_pointer_constraint_impl_ensure_constrained (impl, seat->core_pointer);
     }
 }
+
+MetaCursorRenderer *
+meta_seat_native_get_cursor_renderer (MetaSeatNative     *seat,
+                                      ClutterInputDevice *device)
+{
+  if (device == seat->core_pointer)
+    {
+      if (!seat->cursor_renderer)
+        {
+          MetaCursorRendererNative *renderer_native;
+
+          renderer_native =
+            meta_cursor_renderer_native_new (meta_get_backend ());
+          seat->cursor_renderer = META_CURSOR_RENDERER (renderer_native);
+        }
+
+      return seat->cursor_renderer;
+    }
+
+  return NULL;
+}
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 13c7aaf77d..8e4e2a663e 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -28,6 +28,7 @@
 #include <linux/input-event-codes.h>
 
 #include "backends/native/meta-barrier-native.h"
+#include "backends/native/meta-cursor-renderer-native.h"
 #include "backends/native/meta-keymap-native.h"
 #include "backends/native/meta-pointer-constraint-native.h"
 #include "backends/native/meta-xkb-utils.h"
@@ -61,6 +62,7 @@ struct _MetaSeatNative
   ClutterInputDevice *core_keyboard;
 
   GHashTable *touch_states;
+  GHashTable *cursor_renderers;
 
   struct xkb_state *xkb;
   xkb_led_index_t caps_lock_led;
@@ -82,6 +84,7 @@ struct _MetaSeatNative
   MetaPointerConstraintImpl *pointer_constraint;
 
   MetaKeymapNative *keymap;
+  MetaCursorRenderer *cursor_renderer;
 
   GUdevClient *udev_client;
   guint tablet_mode_switch_state : 1;
@@ -252,5 +255,7 @@ MetaBarrierManagerNative * meta_seat_native_get_barrier_manager (MetaSeatNative
 
 void meta_seat_native_set_pointer_constraint (MetaSeatNative            *seat,
                                               MetaPointerConstraintImpl *impl);
+MetaCursorRenderer * meta_seat_native_get_cursor_renderer (MetaSeatNative     *seat,
+                                                           ClutterInputDevice *device);
 
 #endif /* META_SEAT_NATIVE_H */
diff --git a/src/backends/x11/cm/meta-backend-x11-cm.c b/src/backends/x11/cm/meta-backend-x11-cm.c
index 28726f7d7d..b00f1ca064 100644
--- a/src/backends/x11/cm/meta-backend-x11-cm.c
+++ b/src/backends/x11/cm/meta-backend-x11-cm.c
@@ -41,6 +41,7 @@ struct _MetaBackendX11Cm
 {
   MetaBackendX11 parent;
 
+  MetaCursorRenderer *cursor_renderer;
   char *keymap_layouts;
   char *keymap_variants;
   char *keymap_options;
@@ -116,11 +117,20 @@ meta_backend_x11_cm_create_monitor_manager (MetaBackend *backend,
 }
 
 static MetaCursorRenderer *
-meta_backend_x11_cm_create_cursor_renderer (MetaBackend *backend)
+meta_backend_x11_cm_get_cursor_renderer (MetaBackend        *backend,
+                                         ClutterInputDevice *device)
 {
-  return g_object_new (META_TYPE_CURSOR_RENDERER_X11,
-                       "backend", backend,
-                       NULL);
+  MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend);
+
+  if (!x11_cm->cursor_renderer)
+    {
+      x11_cm->cursor_renderer =
+        g_object_new (META_TYPE_CURSOR_RENDERER_X11,
+                      "backend", backend,
+                      NULL);
+    }
+
+  return x11_cm->cursor_renderer;
 }
 
 static MetaCursorTracker *
@@ -444,7 +454,7 @@ meta_backend_x11_cm_class_init (MetaBackendX11CmClass *klass)
   backend_class->post_init = meta_backend_x11_cm_post_init;
   backend_class->create_renderer = meta_backend_x11_cm_create_renderer;
   backend_class->create_monitor_manager = meta_backend_x11_cm_create_monitor_manager;
-  backend_class->create_cursor_renderer = meta_backend_x11_cm_create_cursor_renderer;
+  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->update_screen_size = meta_backend_x11_cm_update_screen_size;
diff --git a/src/backends/x11/nested/meta-backend-x11-nested.c 
b/src/backends/x11/nested/meta-backend-x11-nested.c
index 009a809787..27143ce141 100644
--- a/src/backends/x11/nested/meta-backend-x11-nested.c
+++ b/src/backends/x11/nested/meta-backend-x11-nested.c
@@ -31,6 +31,7 @@
 typedef struct _MetaBackendX11NestedPrivate
 {
   MetaGpu *gpu;
+  MetaCursorRenderer *cursor_renderer;
 } MetaBackendX11NestedPrivate;
 
 static GInitableIface *initable_parent_iface;
@@ -63,11 +64,22 @@ meta_backend_x11_nested_create_monitor_manager (MetaBackend *backend,
 }
 
 static MetaCursorRenderer *
-meta_backend_x11_nested_create_cursor_renderer (MetaBackend *backend)
+meta_backend_x11_nested_get_cursor_renderer (MetaBackend        *backend,
+                                             ClutterInputDevice *device)
 {
-  return g_object_new (META_TYPE_CURSOR_RENDERER_X11_NESTED,
-                       "backend", backend,
-                       NULL);
+  MetaBackendX11Nested *backend_x11_nested = META_BACKEND_X11_NESTED (backend);
+  MetaBackendX11NestedPrivate *priv =
+    meta_backend_x11_nested_get_instance_private (backend_x11_nested);
+
+  if (!priv->cursor_renderer)
+    {
+      priv->cursor_renderer =
+        g_object_new (META_TYPE_CURSOR_RENDERER_X11_NESTED,
+                      "backend", backend,
+                      NULL);
+    }
+
+  return priv->cursor_renderer;
 }
 
 static MetaInputSettings *
@@ -275,7 +287,7 @@ meta_backend_x11_nested_class_init (MetaBackendX11NestedClass *klass)
   backend_class->post_init = meta_backend_x11_nested_post_init;
   backend_class->create_renderer = meta_backend_x11_nested_create_renderer;
   backend_class->create_monitor_manager = meta_backend_x11_nested_create_monitor_manager;
-  backend_class->create_cursor_renderer = meta_backend_x11_nested_create_cursor_renderer;
+  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->update_screen_size = meta_backend_x11_nested_update_screen_size;
   backend_class->select_stage_events = meta_backend_x11_nested_select_stage_events;


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