wayland/pointer: Track lifetime of current surface

Clear the pointer->current when the surface is destroyed.

https://bugzilla.gnome.org/show_bug.cgi?id=783113
This commit is contained in:
Jonas Ådahl 2017-05-31 17:27:52 +08:00
parent b19e4592df
commit b4120a75e0
2 changed files with 46 additions and 3 deletions

View File

@ -86,6 +86,10 @@ static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE (MetaWaylandPointer, meta_wayland_pointer,
META_TYPE_WAYLAND_INPUT_DEVICE)
static void
meta_wayland_pointer_set_current (MetaWaylandPointer *pointer,
MetaWaylandSurface *surface);
static void
meta_wayland_pointer_reset_grab (MetaWaylandPointer *pointer);
@ -510,6 +514,7 @@ meta_wayland_pointer_disable (MetaWaylandPointer *pointer)
meta_wayland_pointer_cancel_grab (pointer);
meta_wayland_pointer_reset_grab (pointer);
meta_wayland_pointer_set_focus (pointer, NULL);
meta_wayland_pointer_set_current (pointer, NULL);
g_clear_pointer (&pointer->pointer_clients, g_hash_table_unref);
pointer->cursor_surface = NULL;
@ -537,11 +542,40 @@ count_buttons (const ClutterEvent *event)
return count;
}
static void
current_surface_destroyed (MetaWaylandSurface *surface,
MetaWaylandPointer *pointer)
{
meta_wayland_pointer_set_current (pointer, NULL);
}
static void
meta_wayland_pointer_set_current (MetaWaylandPointer *pointer,
MetaWaylandSurface *surface)
{
if (pointer->current)
{
g_signal_handler_disconnect (pointer->current,
pointer->current_surface_destroyed_handler_id);
pointer->current = NULL;
}
if (surface)
{
pointer->current = surface;
pointer->current_surface_destroyed_handler_id =
g_signal_connect (surface, "destroy",
G_CALLBACK (current_surface_destroyed),
pointer);
}
}
static void
repick_for_event (MetaWaylandPointer *pointer,
const ClutterEvent *for_event)
{
ClutterActor *actor;
MetaWaylandSurface *surface;
if (for_event)
actor = clutter_event_get_source (for_event);
@ -549,10 +583,18 @@ repick_for_event (MetaWaylandPointer *pointer,
actor = clutter_input_device_get_pointer_actor (pointer->device);
if (META_IS_SURFACE_ACTOR_WAYLAND (actor))
pointer->current =
meta_surface_actor_wayland_get_surface (META_SURFACE_ACTOR_WAYLAND (actor));
{
MetaSurfaceActorWayland *actor_wayland =
META_SURFACE_ACTOR_WAYLAND (actor);
surface = meta_surface_actor_wayland_get_surface (actor_wayland);
}
else
pointer->current = NULL;
{
surface = NULL;
}
meta_wayland_pointer_set_current (pointer, surface);
sync_focus_surface (pointer);
meta_wayland_pointer_update_cursor_surface (pointer);

View File

@ -87,6 +87,7 @@ struct _MetaWaylandPointer
ClutterInputDevice *device;
MetaWaylandSurface *current;
gulong current_surface_destroyed_handler_id;
guint32 button_count;
};