diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2020-07-13 14:09:44 +0200 |
---|---|---|
committer | Marge Bot <marge-bot@gnome.org> | 2020-11-27 15:14:33 +0000 |
commit | 00cbcb7ba1d40f415711890fa0cb1dce5f752581 (patch) | |
tree | 6e4654c32970ac27ea5b26525ea7fe10972e49b8 | |
parent | a8e293522517fad1b1b9ef0139fe120f6675b8f3 (diff) | |
download | mutter-00cbcb7ba1d40f415711890fa0cb1dce5f752581.tar.gz |
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>
-rw-r--r-- | src/backends/meta-cursor-renderer.c | 10 | ||||
-rw-r--r-- | src/backends/meta-cursor-renderer.h | 4 | ||||
-rw-r--r-- | src/backends/meta-cursor-tracker-private.h | 4 | ||||
-rw-r--r-- | src/backends/meta-cursor-tracker.c | 48 | ||||
-rw-r--r-- | src/backends/meta-screen-cast-area-stream-src.c | 14 | ||||
-rw-r--r-- | src/backends/meta-screen-cast-monitor-stream-src.c | 14 | ||||
-rw-r--r-- | src/backends/meta-screen-cast-window-stream-src.c | 14 | ||||
-rw-r--r-- | src/backends/native/meta-seat-native.c | 5 | ||||
-rw-r--r-- | src/backends/x11/meta-cursor-tracker-x11.c | 4 | ||||
-rw-r--r-- | src/core/events.c | 19 | ||||
-rw-r--r-- | src/wayland/meta-wayland-tablet-manager.c | 27 | ||||
-rw-r--r-- | src/wayland/meta-wayland-tablet-manager.h | 3 | ||||
-rw-r--r-- | src/wayland/meta-wayland-tablet-tool.c | 9 | ||||
-rw-r--r-- | src/wayland/meta-wayland-tablet-tool.h | 4 |
14 files changed, 51 insertions, 128 deletions
diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c index ba27eb848..b80081774 100644 --- a/src/backends/meta-cursor-renderer.c +++ b/src/backends/meta-cursor-renderer.c @@ -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); } diff --git a/src/backends/meta-cursor-renderer.h b/src/backends/meta-cursor-renderer.h index 2156d9125..37ddb9100 100644 --- a/src/backends/meta-cursor-renderer.h +++ b/src/backends/meta-cursor-renderer.h @@ -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); diff --git a/src/backends/meta-cursor-tracker-private.h b/src/backends/meta-cursor-tracker-private.h index 779c2fe52..6d3c88c35 100644 --- a/src/backends/meta-cursor-tracker-private.h +++ b/src/backends/meta-cursor-tracker-private.h @@ -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); diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c index 3c6f6a0c4..6b3d2289a 100644 --- a/src/backends/meta-cursor-tracker.c +++ b/src/backends/meta-cursor-tracker.c @@ -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 diff --git a/src/backends/meta-screen-cast-area-stream-src.c b/src/backends/meta-screen-cast-area-stream-src.c index b69c26ac4..6a64bcb66 100644 --- a/src/backends/meta-screen-cast-area-stream-src.c +++ b/src/backends/meta-screen-cast-area-stream-src.c @@ -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); diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c index 8675ae342..2155cc84d 100644 --- a/src/backends/meta-screen-cast-monitor-stream-src.c +++ b/src/backends/meta-screen-cast-monitor-stream-src.c @@ -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); diff --git a/src/backends/meta-screen-cast-window-stream-src.c b/src/backends/meta-screen-cast-window-stream-src.c index e881d80f4..76f53d160 100644 --- a/src/backends/meta-screen-cast-window-stream-src.c +++ b/src/backends/meta-screen-cast-window-stream-src.c @@ -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", diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c index fcf0ad96e..45da429dc 100644 --- a/src/backends/native/meta-seat-native.c +++ b/src/backends/native/meta-seat-native.c @@ -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 diff --git a/src/backends/x11/meta-cursor-tracker-x11.c b/src/backends/x11/meta-cursor-tracker-x11.c index 1e6c39e71..7355f828e 100644 --- a/src/backends/x11/meta-cursor-tracker-x11.c +++ b/src/backends/x11/meta-cursor-tracker-x11.c @@ -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 diff --git a/src/core/events.c b/src/core/events.c index 17dcaa0fe..52828bdc9 100644 --- a/src/core/events.c +++ b/src/core/events.c @@ -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 diff --git a/src/wayland/meta-wayland-tablet-manager.c b/src/wayland/meta-wayland-tablet-manager.c index 38cec064e..9c81d5afc 100644 --- a/src/wayland/meta-wayland-tablet-manager.c +++ b/src/wayland/meta-wayland-tablet-manager.c @@ -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); - } -} diff --git a/src/wayland/meta-wayland-tablet-manager.h b/src/wayland/meta-wayland-tablet-manager.h index 5d4b28c2d..83f9d3d0f 100644 --- a/src/wayland/meta-wayland-tablet-manager.h +++ b/src/wayland/meta-wayland-tablet-manager.h @@ -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 */ diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c index 589e92ddd..8ff2accb2 100644 --- a/src/wayland/meta-wayland-tablet-tool.c +++ b/src/wayland/meta-wayland-tablet-tool.c @@ -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) diff --git a/src/wayland/meta-wayland-tablet-tool.h b/src/wayland/meta-wayland-tablet-tool.h index 7cf1d9077..e9ad7db40 100644 --- a/src/wayland/meta-wayland-tablet-tool.h +++ b/src/wayland/meta-wayland-tablet-tool.h @@ -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); |