[mutter/wip/carlosg/input-thread: 22/90] backends: Add meta_backend_get_cursor_renderer_for_device()




commit c40d07981f92ed61fc60542d9126be29dc109e68
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).

 src/backends/meta-backend-private.h               |  5 +-
 src/backends/meta-backend.c                       | 72 +++++++++++++++++++++--
 src/backends/native/meta-backend-native.c         | 12 ++--
 src/backends/native/meta-seat-native.c            | 23 ++++++++
 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, 139 insertions(+), 20 deletions(-)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index afce64fd7a..daee54c66d 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -63,7 +63,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);
@@ -128,6 +129,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 1e4f00a75a..c174b260e2 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -120,7 +120,6 @@ struct _MetaBackendPrivate
   MetaMonitorManager *monitor_manager;
   MetaOrientationManager *orientation_manager;
   MetaCursorTracker *cursor_tracker;
-  MetaCursorRenderer *cursor_renderer;
   MetaInputSettings *input_settings;
   MetaRenderer *renderer;
 #ifdef HAVE_EGL
@@ -265,6 +264,53 @@ reset_pointer_position (MetaBackend *backend)
                              primary->rect.y + primary->rect.height * 0.9);
 }
 
+static gboolean
+should_have_cursor_renderer (ClutterInputDevice *device)
+{
+  switch (clutter_input_device_get_device_type (device))
+    {
+    case CLUTTER_POINTER_DEVICE:
+      if (clutter_input_device_get_device_mode (device) ==
+          CLUTTER_INPUT_MODE_LOGICAL)
+        return TRUE;
+
+      return FALSE;
+    case CLUTTER_TABLET_DEVICE:
+      return TRUE;
+    default:
+      return FALSE;
+    }
+}
+
+static void
+update_cursors (MetaBackend *backend)
+{
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
+  MetaCursorRenderer *cursor_renderer;
+  ClutterInputDevice *pointer, *device;
+  GList *devices, *l;
+
+  pointer = clutter_seat_get_pointer (seat);
+  devices = clutter_seat_list_devices (seat);
+  devices = g_list_prepend (devices, pointer);
+
+  for (l = devices; l; l = l->next)
+    {
+      device = l->data;
+
+      if (!should_have_cursor_renderer (device))
+        continue;
+
+      cursor_renderer = meta_backend_get_cursor_renderer_for_device (backend,
+                                                                     device);
+      if (cursor_renderer)
+        meta_cursor_renderer_force_update (cursor_renderer);
+    }
+
+  g_list_free (devices);
+}
+
 void
 meta_backend_monitors_changed (MetaBackend *backend)
 {
@@ -290,7 +336,7 @@ meta_backend_monitors_changed (MetaBackend *backend)
         }
     }
 
-  meta_cursor_renderer_force_update (priv->cursor_renderer);
+  update_cursors (backend);
 }
 
 void
@@ -482,8 +528,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);
 
@@ -1045,8 +1089,26 @@ 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)
+{
+  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);
 
-  return priv->cursor_renderer;
+  return META_BACKEND_GET_CLASS (backend)->get_cursor_renderer (backend,
+                                                                device);
 }
 
 /**
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 94fce30b38..acafd46f29 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_native =
+    META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
+
+  return meta_seat_native_maybe_ensure_cursor_renderer (seat_native, device);
 }
 
 static MetaRenderer *
@@ -524,7 +528,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 bf62788789..a4486be516 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -2630,6 +2630,7 @@ meta_seat_native_finalize (GObject *object)
 
   g_hash_table_destroy (seat->reserved_virtual_slots);
 
+  g_object_unref (seat->cursor_renderer);
   g_object_unref (seat->udev_client);
 
   meta_event_source_free (seat->event_source);
@@ -3287,3 +3288,25 @@ meta_seat_native_set_pointer_constraint (MetaSeatNative            *seat,
                                                        seat->core_pointer);
     }
 }
+
+MetaCursorRenderer *
+meta_seat_native_maybe_ensure_cursor_renderer (MetaSeatNative     *seat_native,
+                                               ClutterInputDevice *device)
+{
+  if (device == seat_native->core_pointer)
+    {
+      if (!seat_native->cursor_renderer)
+        {
+          MetaCursorRendererNative *cursor_renderer_native;
+
+          cursor_renderer_native =
+            meta_cursor_renderer_native_new (meta_get_backend ());
+          seat_native->cursor_renderer =
+            META_CURSOR_RENDERER (cursor_renderer_native);
+        }
+
+      return seat_native->cursor_renderer;
+    }
+
+  return NULL;
+}
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 2a1faaee00..9f7f2d3a1e 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"
@@ -63,6 +64,7 @@ struct _MetaSeatNative
   GHashTable *touch_states;
   guint virtual_touch_slot_base;
   GHashTable *reserved_virtual_slots;
+  GHashTable *cursor_renderers;
 
   struct xkb_state *xkb;
   xkb_led_index_t caps_lock_led;
@@ -84,6 +86,7 @@ struct _MetaSeatNative
   MetaPointerConstraintImpl *pointer_constraint;
 
   MetaKeymapNative *keymap;
+  MetaCursorRenderer *cursor_renderer;
 
   GUdevClient *udev_client;
   guint tablet_mode_switch_state : 1;
@@ -257,5 +260,7 @@ MetaBarrierManagerNative * meta_seat_native_get_barrier_manager (MetaSeatNative
 
 void meta_seat_native_set_pointer_constraint (MetaSeatNative            *seat,
                                               MetaPointerConstraintImpl *constraint_impl);
+MetaCursorRenderer * meta_seat_native_maybe_ensure_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]