From b19e4592df42fd4bf7440e785a7fc58fe8378c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 31 May 2017 17:24:07 +0800 Subject: [PATCH] wayland/pointer: Use glib signals tracking focus surface Use the "destroy" MetaWaylandSurface signal instead of the wl_resource destroy signal for tracking the lifetime of the surface with pointer focus. As unsetting the focus may have side effects due to handlers of the "focus-surface-changed" signal, connect the signal after the default handler to make sure other clean up facilities have the chance deal with the surface destruction before we try to unset the focus. https://bugzilla.gnome.org/show_bug.cgi?id=783113 --- src/wayland/meta-wayland-pointer.c | 28 +++++++++++++++------------- src/wayland/meta-wayland-pointer.h | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index 4578f3ee1..7c05912b0 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -246,14 +246,6 @@ sync_focus_surface (MetaWaylandPointer *pointer) } -static void -pointer_handle_focus_surface_destroy (struct wl_listener *listener, void *data) -{ - MetaWaylandPointer *pointer = wl_container_of (listener, pointer, focus_surface_listener); - - meta_wayland_pointer_set_focus (pointer, NULL); -} - static void meta_wayland_pointer_send_frame (MetaWaylandPointer *pointer, struct wl_resource *resource) @@ -488,8 +480,6 @@ meta_wayland_pointer_enable (MetaWaylandPointer *pointer) g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) meta_wayland_pointer_client_free); - pointer->focus_surface_listener.notify = pointer_handle_focus_surface_destroy; - pointer->cursor_surface = NULL; manager = clutter_device_manager_get_default (); @@ -815,6 +805,13 @@ meta_wayland_pointer_broadcast_leave (MetaWaylandPointer *pointer, meta_wayland_pointer_broadcast_frame (pointer); } +static void +focus_surface_destroyed (MetaWaylandSurface *surface, + MetaWaylandPointer *pointer) +{ + meta_wayland_pointer_set_focus (pointer, NULL); +} + void meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer, MetaWaylandSurface *surface) @@ -838,7 +835,9 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer, pointer->focus_client = NULL; } - wl_list_remove (&pointer->focus_surface_listener.link); + g_signal_handler_disconnect (pointer->focus_surface, + pointer->focus_surface_destroyed_handler_id); + pointer->focus_surface_destroyed_handler_id = 0; pointer->focus_surface = NULL; } @@ -848,8 +847,11 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer, ClutterPoint pos; pointer->focus_surface = surface; - wl_resource_add_destroy_listener (pointer->focus_surface->resource, - &pointer->focus_surface_listener); + + pointer->focus_surface_destroyed_handler_id = + g_signal_connect_after (pointer->focus_surface, "destroy", + G_CALLBACK (focus_surface_destroyed), + pointer); clutter_input_device_get_coords (pointer->device, NULL, &pos); diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h index 547cd5610..9f55590e9 100644 --- a/src/wayland/meta-wayland-pointer.h +++ b/src/wayland/meta-wayland-pointer.h @@ -71,7 +71,7 @@ struct _MetaWaylandPointer GHashTable *pointer_clients; MetaWaylandSurface *focus_surface; - struct wl_listener focus_surface_listener; + gulong focus_surface_destroyed_handler_id; guint32 focus_serial; guint32 click_serial;