core: Centralize cursor renderer and tracker updates

These use now more of a "pull" model, where they receive update
notifications and the relevant input position is queried, instead
of the coordinates being passed along.

This allows to treat cursor renderers all the same independently
of the device they track. This notifying of position changes should
ideally be more backend-y than core-y, a better location will be
figured out in future commits.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403>
This commit is contained in:
Carlos Garnacho 2020-07-13 14:09:44 +02:00 committed by Marge Bot
parent a8e2935225
commit 00cbcb7ba1
14 changed files with 51 additions and 128 deletions

View File

@ -444,14 +444,14 @@ meta_cursor_renderer_force_update (MetaCursorRenderer *renderer)
}
void
meta_cursor_renderer_set_position (MetaCursorRenderer *renderer,
float x,
float y)
meta_cursor_renderer_update_position (MetaCursorRenderer *renderer)
{
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
graphene_point_t pos;
priv->current_x = x;
priv->current_y = y;
clutter_input_device_get_coords (priv->device, NULL, &pos);
priv->current_x = pos.x;
priv->current_y = pos.y;
meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
}

View File

@ -60,9 +60,7 @@ MetaCursorRenderer * meta_cursor_renderer_new (MetaBackend *backend,
void meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite);
void meta_cursor_renderer_set_position (MetaCursorRenderer *renderer,
float x,
float y);
void meta_cursor_renderer_update_position (MetaCursorRenderer *renderer);
void meta_cursor_renderer_force_update (MetaCursorRenderer *renderer);
MetaCursorSprite * meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer);

View File

@ -41,9 +41,7 @@ void meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker);
void meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
MetaCursorSprite *cursor_sprite);
void meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
float new_x,
float new_y);
void meta_cursor_tracker_invalidate_position (MetaCursorTracker *tracker);
void meta_cursor_tracker_track_position (MetaCursorTracker *tracker);

View File

@ -82,7 +82,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorTracker, meta_cursor_tracker,
enum
{
CURSOR_CHANGED,
CURSOR_MOVED,
POSITION_INVALIDATED,
VISIBILITY_CHANGED,
LAST_SIGNAL
};
@ -288,20 +288,12 @@ meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* MetaCursorTracker::cursor-moved:
* @cursor: The #MetaCursorTracker
* @x: The new X coordinate of the cursor
* @y: The new Y coordinate of the cursor
*
* Notifies when the cursor has moved to a new location.
*/
signals[CURSOR_MOVED] = g_signal_new ("cursor-moved",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[POSITION_INVALIDATED] = g_signal_new ("position-invalidated",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[VISIBILITY_CHANGED] = g_signal_new ("visibility-changed",
G_TYPE_FROM_CLASS (klass),
@ -428,31 +420,9 @@ meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
}
void
meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
float new_x,
float new_y)
meta_cursor_tracker_invalidate_position (MetaCursorTracker *tracker)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
MetaCursorRenderer *cursor_renderer =
meta_backend_get_cursor_renderer (priv->backend);
gboolean position_changed;
if (priv->x != new_x || priv->y != new_y)
{
position_changed = TRUE;
priv->x = new_x;
priv->y = new_y;
}
else
{
position_changed = FALSE;
}
meta_cursor_renderer_set_position (cursor_renderer, new_x, new_y);
if (position_changed)
g_signal_emit (tracker, signals[CURSOR_MOVED], 0);
g_signal_emit (tracker, signals[POSITION_INVALIDATED], 0);
}
void

View File

@ -42,7 +42,7 @@ struct _MetaScreenCastAreaStreamSrc
GList *watches;
gulong cursor_moved_handler_id;
gulong position_invalidated_handler_id;
gulong cursor_changed_handler_id;
guint maybe_record_idle_id;
@ -182,8 +182,8 @@ sync_cursor_state (MetaScreenCastAreaStreamSrc *area_src)
}
static void
cursor_moved (MetaCursorTracker *cursor_tracker,
MetaScreenCastAreaStreamSrc *area_src)
pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
MetaScreenCastAreaStreamSrc *area_src)
{
sync_cursor_state (area_src);
}
@ -332,9 +332,9 @@ meta_screen_cast_area_stream_src_enable (MetaScreenCastStreamSrc *src)
switch (meta_screen_cast_stream_get_cursor_mode (stream))
{
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
area_src->cursor_moved_handler_id =
g_signal_connect_after (cursor_tracker, "cursor-moved",
G_CALLBACK (cursor_moved),
area_src->position_invalidated_handler_id =
g_signal_connect_after (cursor_tracker, "position-invalidated",
G_CALLBACK (pointer_position_invalidated),
area_src);
area_src->cursor_changed_handler_id =
g_signal_connect_after (cursor_tracker, "cursor-changed",
@ -383,7 +383,7 @@ meta_screen_cast_area_stream_src_disable (MetaScreenCastStreamSrc *src)
if (area_src->hw_cursor_inhibited)
uninhibit_hw_cursor (area_src);
g_clear_signal_handler (&area_src->cursor_moved_handler_id,
g_clear_signal_handler (&area_src->position_invalidated_handler_id,
cursor_tracker);
g_clear_signal_handler (&area_src->cursor_changed_handler_id,
cursor_tracker);

View File

@ -46,7 +46,7 @@ struct _MetaScreenCastMonitorStreamSrc
GList *watches;
gulong cursor_moved_handler_id;
gulong position_invalidated_handler_id;
gulong cursor_changed_handler_id;
};
@ -238,8 +238,8 @@ sync_cursor_state (MetaScreenCastMonitorStreamSrc *monitor_src)
}
static void
cursor_moved (MetaCursorTracker *cursor_tracker,
MetaScreenCastMonitorStreamSrc *monitor_src)
pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
MetaScreenCastMonitorStreamSrc *monitor_src)
{
sync_cursor_state (monitor_src);
}
@ -352,9 +352,9 @@ meta_screen_cast_monitor_stream_src_enable (MetaScreenCastStreamSrc *src)
switch (meta_screen_cast_stream_get_cursor_mode (stream))
{
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
monitor_src->cursor_moved_handler_id =
g_signal_connect_after (cursor_tracker, "cursor-moved",
G_CALLBACK (cursor_moved),
monitor_src->position_invalidated_handler_id =
g_signal_connect_after (cursor_tracker, "position-invalidated",
G_CALLBACK (pointer_position_invalidated),
monitor_src);
monitor_src->cursor_changed_handler_id =
g_signal_connect_after (cursor_tracker, "cursor-changed",
@ -408,7 +408,7 @@ meta_screen_cast_monitor_stream_src_disable (MetaScreenCastStreamSrc *src)
if (monitor_src->hw_cursor_inhibited)
uninhibit_hw_cursor (monitor_src);
g_clear_signal_handler (&monitor_src->cursor_moved_handler_id,
g_clear_signal_handler (&monitor_src->position_invalidated_handler_id,
cursor_tracker);
g_clear_signal_handler (&monitor_src->cursor_changed_handler_id,
cursor_tracker);

View File

@ -37,7 +37,7 @@ struct _MetaScreenCastWindowStreamSrc
unsigned long screen_cast_window_damaged_handler_id;
unsigned long screen_cast_window_destroyed_handler_id;
unsigned long cursor_moved_handler_id;
unsigned long position_invalidated_handler_id;
unsigned long cursor_changed_handler_id;
gboolean cursor_bitmap_invalid;
@ -323,7 +323,7 @@ meta_screen_cast_window_stream_src_stop (MetaScreenCastWindowStreamSrc *window_s
window_src->screen_cast_window);
g_clear_signal_handler (&window_src->screen_cast_window_destroyed_handler_id,
window_src->screen_cast_window);
g_clear_signal_handler (&window_src->cursor_moved_handler_id,
g_clear_signal_handler (&window_src->position_invalidated_handler_id,
cursor_tracker);
g_clear_signal_handler (&window_src->cursor_changed_handler_id,
cursor_tracker);
@ -372,8 +372,8 @@ sync_cursor_state (MetaScreenCastWindowStreamSrc *window_src)
}
static void
cursor_moved (MetaCursorTracker *cursor_tracker,
MetaScreenCastWindowStreamSrc *window_src)
pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
MetaScreenCastWindowStreamSrc *window_src)
{
sync_cursor_state (window_src);
}
@ -420,9 +420,9 @@ meta_screen_cast_window_stream_src_enable (MetaScreenCastStreamSrc *src)
{
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
window_src->cursor_moved_handler_id =
g_signal_connect_after (cursor_tracker, "cursor-moved",
G_CALLBACK (cursor_moved),
window_src->position_invalidated_handler_id =
g_signal_connect_after (cursor_tracker, "position-invalidated",
G_CALLBACK (pointer_position_invalidated),
window_src);
window_src->cursor_changed_handler_id =
g_signal_connect_after (cursor_tracker, "cursor-changed",

View File

@ -2840,11 +2840,14 @@ meta_seat_native_warp_pointer (ClutterSeat *seat,
{
MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
MetaBackend *backend = meta_get_backend ();
MetaCursorRenderer *cursor_renderer =
meta_backend_get_cursor_renderer (backend);
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
notify_absolute_motion (seat_native->core_pointer, 0, x, y, NULL);
meta_cursor_tracker_update_position (cursor_tracker, x, y);
meta_cursor_renderer_update_position (cursor_renderer);
meta_cursor_tracker_invalidate_position (cursor_tracker);
}
static gboolean

View File

@ -69,10 +69,8 @@ static void
update_position (MetaCursorTrackerX11 *tracker_x11)
{
MetaCursorTracker *tracker = META_CURSOR_TRACKER (tracker_x11);
graphene_point_t point;
meta_cursor_tracker_get_pointer (tracker, &point, NULL);
meta_cursor_tracker_update_position (tracker, point.x, point.y);
meta_cursor_tracker_invalidate_position (tracker);
}
static gboolean

View File

@ -288,22 +288,21 @@ meta_display_handle_event (MetaDisplay *display,
#ifdef HAVE_WAYLAND
if (meta_is_wayland_compositor () && event->type == CLUTTER_MOTION)
{
MetaWaylandCompositor *compositor;
MetaCursorRenderer *cursor_renderer;
ClutterInputDevice *device;
compositor = meta_wayland_compositor_get_default ();
device = clutter_event_get_device (event);
cursor_renderer = meta_backend_get_cursor_renderer_for_device (backend,
device);
if (cursor_renderer)
meta_cursor_renderer_update_position (cursor_renderer);
if (meta_wayland_tablet_manager_consumes_event (compositor->tablet_manager, event))
{
meta_wayland_tablet_manager_update_cursor_position (compositor->tablet_manager, event);
}
else
if (device == clutter_seat_get_pointer (clutter_input_device_get_seat (device)))
{
MetaCursorTracker *cursor_tracker =
meta_backend_get_cursor_tracker (backend);
meta_cursor_tracker_update_position (cursor_tracker,
event->motion.x,
event->motion.y);
meta_cursor_tracker_invalidate_position (cursor_tracker);
}
}
#endif

View File

@ -242,30 +242,3 @@ meta_wayland_tablet_manager_ensure_seat (MetaWaylandTabletManager *manager,
return tablet_seat;
}
void
meta_wayland_tablet_manager_update_cursor_position (MetaWaylandTabletManager *manager,
const ClutterEvent *event)
{
MetaWaylandTabletSeat *tablet_seat = NULL;
MetaWaylandTabletTool *tool = NULL;
ClutterInputDeviceTool *device_tool;
ClutterInputDevice *device;
device = clutter_event_get_source_device (event);
device_tool = clutter_event_get_device_tool (event);
if (device)
tablet_seat = meta_wayland_tablet_manager_lookup_seat (manager, device);
if (tablet_seat && device_tool)
tool = meta_wayland_tablet_seat_lookup_tool (tablet_seat, device_tool);
if (tool)
{
gfloat new_x, new_y;
clutter_event_get_coords (event, &new_x, &new_y);
meta_wayland_tablet_tool_set_cursor_position (tool, new_x, new_y);
}
}

View File

@ -50,7 +50,4 @@ MetaWaylandTabletSeat *
meta_wayland_tablet_manager_ensure_seat (MetaWaylandTabletManager *manager,
MetaWaylandSeat *seat);
void meta_wayland_tablet_manager_update_cursor_position (MetaWaylandTabletManager *manager,
const ClutterEvent *event);
#endif /* META_WAYLAND_TABLET_MANAGER_H */

View File

@ -965,15 +965,6 @@ meta_wayland_tablet_tool_handle_event (MetaWaylandTabletTool *tool,
return CLUTTER_EVENT_STOP;
}
void
meta_wayland_tablet_tool_set_cursor_position (MetaWaylandTabletTool *tool,
float new_x,
float new_y)
{
if (tool->cursor_renderer)
meta_cursor_renderer_set_position (tool->cursor_renderer, new_x, new_y);
}
static gboolean
tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
MetaWaylandSurface *surface)

View File

@ -78,10 +78,6 @@ void meta_wayland_tablet_tool_update (MetaWaylandTabletTool *t
gboolean meta_wayland_tablet_tool_handle_event (MetaWaylandTabletTool *tool,
const ClutterEvent *event);
void meta_wayland_tablet_tool_set_cursor_position (MetaWaylandTabletTool *tool,
float new_x,
float new_y);
gboolean meta_wayland_tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
MetaWaylandSurface *surface,
uint32_t serial);