1
0
Fork 0

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

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403>
This commit is contained in:
Carlos Garnacho 2020-07-10 23:28:50 +02:00 committed by Marge Bot
parent d41dbf92ea
commit 35abb8ab53
7 changed files with 139 additions and 20 deletions

View file

@ -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);

View file

@ -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;
return priv->cursor_renderer;
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 META_BACKEND_GET_CLASS (backend)->get_cursor_renderer (backend,
device);
}
/**

View file

@ -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 *
@ -532,7 +536,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;

View file

@ -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);
@ -3288,3 +3289,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;
}

View file

@ -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 */

View file

@ -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,
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;

View file

@ -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,
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;