backends: Manage tablet cursors in backend

Instead of letting the wayland bits maintain an always-software
cursor renderer, let the cursor renderer be managed by the backend,
and only hook to it (as we do for pointer cursor) in the wayland
bits.

ATM, make the cursor renderer still always-software, although
ideally we should allow moving the HW cursor management between
renderers.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403
This commit is contained in:
Carlos Garnacho 2020-07-11 13:47:51 +02:00
parent 667b2726f5
commit 6c5bba94fd
3 changed files with 46 additions and 4 deletions

View File

@ -1821,6 +1821,31 @@ process_tablet_axis (MetaSeatNative *seat,
} }
} }
static void
update_tablet_cursor_state (MetaSeatNative *seat,
ClutterInputDevice *device,
gboolean in)
{
if (in)
{
MetaCursorRenderer *renderer;
if (!seat->tablet_cursors)
{
seat->tablet_cursors = g_hash_table_new_full (NULL, NULL, NULL,
g_object_unref);
}
renderer = meta_cursor_renderer_new (meta_get_backend ());
g_hash_table_insert (seat->tablet_cursors, device, renderer);
}
else
{
if (seat->tablet_cursors)
g_hash_table_remove (seat->tablet_cursors, device);
}
}
static gboolean static gboolean
process_device_event (MetaSeatNative *seat, process_device_event (MetaSeatNative *seat,
struct libinput_event *event) struct libinput_event *event)
@ -2228,18 +2253,22 @@ process_device_event (MetaSeatNative *seat,
libinput_event_get_tablet_tool_event (event); libinput_event_get_tablet_tool_event (event);
struct libinput_tablet_tool *libinput_tool = NULL; struct libinput_tablet_tool *libinput_tool = NULL;
enum libinput_tablet_tool_proximity_state state; enum libinput_tablet_tool_proximity_state state;
gboolean in;
state = libinput_event_tablet_tool_get_proximity_state (tablet_event); state = libinput_event_tablet_tool_get_proximity_state (tablet_event);
time = libinput_event_tablet_tool_get_time_usec (tablet_event); time = libinput_event_tablet_tool_get_time_usec (tablet_event);
device = libinput_device_get_user_data (libinput_device); device = libinput_device_get_user_data (libinput_device);
in = state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN;
libinput_tool = libinput_event_tablet_tool_get_tool (tablet_event); libinput_tool = libinput_event_tablet_tool_get_tool (tablet_event);
if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) if (in)
input_device_update_tool (device, libinput_tool); input_device_update_tool (device, libinput_tool);
notify_proximity (device, time, state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); notify_proximity (device, time, in);
if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) if (!in)
input_device_update_tool (device, NULL); input_device_update_tool (device, NULL);
update_tablet_cursor_state (seat, device, in);
break; break;
} }
case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
@ -2600,6 +2629,7 @@ meta_seat_native_finalize (GObject *object)
if (seat->touch_states) if (seat->touch_states)
g_hash_table_destroy (seat->touch_states); g_hash_table_destroy (seat->touch_states);
g_clear_pointer (&seat->tablet_cursors, g_hash_table_unref);
g_object_unref (seat->cursor_renderer); g_object_unref (seat->cursor_renderer);
g_object_unref (seat->udev_client); g_object_unref (seat->udev_client);
@ -3278,5 +3308,9 @@ meta_seat_native_get_cursor_renderer (MetaSeatNative *seat,
return seat->cursor_renderer; return seat->cursor_renderer;
} }
if (seat->tablet_cursors &&
clutter_input_device_get_device_type (device) == CLUTTER_TABLET_DEVICE)
return g_hash_table_lookup (seat->tablet_cursors, device);
return NULL; return NULL;
} }

View File

@ -85,6 +85,7 @@ struct _MetaSeatNative
MetaKeymapNative *keymap; MetaKeymapNative *keymap;
MetaCursorRenderer *cursor_renderer; MetaCursorRenderer *cursor_renderer;
GHashTable *tablet_cursors;
GUdevClient *udev_client; GUdevClient *udev_client;
guint tablet_mode_switch_state : 1; guint tablet_mode_switch_state : 1;

View File

@ -932,7 +932,14 @@ meta_wayland_tablet_tool_update (MetaWaylandTabletTool *tool,
break; break;
case CLUTTER_PROXIMITY_IN: case CLUTTER_PROXIMITY_IN:
if (!tool->cursor_renderer) if (!tool->cursor_renderer)
tool->cursor_renderer = meta_cursor_renderer_new (meta_get_backend ()); {
MetaCursorRenderer *renderer;
renderer =
meta_backend_get_cursor_renderer_for_device (meta_get_backend (),
clutter_event_get_source_device (event));
g_set_object (&tool->cursor_renderer, renderer);
}
tool->current_tablet = tool->current_tablet =
meta_wayland_tablet_seat_lookup_tablet (tool->seat, meta_wayland_tablet_seat_lookup_tablet (tool->seat,
clutter_event_get_source_device (event)); clutter_event_get_source_device (event));