cursor-tracker: Add way to force tracking cursor position

On X11 we won't always receive cursor positions, as some other client
might have grabbed the pointer (e.g. for implementing a popup menu). To
make screen casting show a somewhat correct cursor position, we need to
actively poll the X server about the current cursor position.

We only really want to do this when screen casting or taking a
screenshot, so add an API that forces the cursor tracker to track the
cursor position.

On the native backend this is a no-op as we by default always track the
cursor position anyway.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
This commit is contained in:
Jonas Ådahl
2020-07-29 11:22:19 +02:00
parent b24b95db15
commit eeee7bed1d
5 changed files with 128 additions and 4 deletions

View File

@ -62,6 +62,8 @@ typedef struct _MetaCursorTrackerPrivate
gboolean is_showing;
int track_position_count;
float x;
float y;
@ -175,6 +177,12 @@ sync_cursor (MetaCursorTracker *tracker)
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
}
static void
meta_cursor_tracker_real_set_force_track_position (MetaCursorTracker *tracker,
gboolean is_enabled)
{
}
static void
meta_cursor_tracker_init (MetaCursorTracker *tracker)
{
@ -251,6 +259,9 @@ meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
object_class->set_property = meta_cursor_tracker_set_property;
object_class->finalize = meta_cursor_tracker_finalize;
klass->set_force_track_position =
meta_cursor_tracker_real_set_force_track_position;
obj_props[PROP_BACKEND] =
g_param_spec_object ("backend",
"backend",
@ -491,8 +502,6 @@ meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
meta_backend_get_cursor_renderer (priv->backend);
gboolean position_changed;
g_assert (meta_is_wayland_compositor ());
if (priv->x != new_x || priv->y != new_y)
{
position_changed = TRUE;
@ -567,6 +576,40 @@ meta_cursor_tracker_get_pointer (MetaCursorTracker *tracker,
get_pointer_position_gdk (x, y, (int*)mods);
}
void
meta_cursor_tracker_track_position (MetaCursorTracker *tracker)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
priv->track_position_count++;
if (priv->track_position_count == 1)
{
MetaCursorTrackerClass *klass =
META_CURSOR_TRACKER_GET_CLASS (tracker);
klass->set_force_track_position (tracker, TRUE);
}
}
void
meta_cursor_tracker_untrack_position (MetaCursorTracker *tracker)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
g_return_if_fail (priv->track_position_count <= 0);
priv->track_position_count--;
if (priv->track_position_count == 0)
{
MetaCursorTrackerClass *klass =
META_CURSOR_TRACKER_GET_CLASS (tracker);
klass->set_force_track_position (tracker, FALSE);
}
}
gboolean
meta_cursor_tracker_get_pointer_visible (MetaCursorTracker *tracker)
{