[PATCH weston v2] libweston-desktop: destroy wl_shell_surface after the wl_surface is destroyed

Giulio Camuffo giuliocamuffo at gmail.com
Wed Sep 28 19:32:11 UTC 2016


The wl_shell_surface spec says that it is destroyed automatically by the
server when the wl_surface is destroyed, and indeed it does not have a
destroy request. So, do that.
---

v2: remove the destroy listener when the wl_shell_surface is destroyed

 libweston-desktop/wl-shell.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libweston-desktop/wl-shell.c b/libweston-desktop/wl-shell.c
index 3a81f42..e39be26 100644
--- a/libweston-desktop/wl-shell.c
+++ b/libweston-desktop/wl-shell.c
@@ -56,6 +56,7 @@ struct weston_desktop_wl_shell_surface {
 	bool added;
 	struct weston_desktop_seat *popup_seat;
 	enum weston_desktop_wl_shell_surface_state state;
+	struct wl_listener wl_surface_resource_destroy_listener;
 };
 
 struct wl_shell_client {
@@ -207,6 +208,8 @@ weston_desktop_wl_shell_surface_destroy(struct weston_desktop_surface *dsurface,
 		weston_desktop_surface_get_client(dsurface);
 	struct wl_shell_client *wsc = weston_desktop_client_get_user_data(client);
 
+	wl_list_remove(&surface->wl_surface_resource_destroy_listener.link);
+
 	/* If the surface being destroyed was the one that was pinged before
 	 * we need to fake a pong here, because it cannot answer the ping anymore,
 	 * even if the client is responsive. */
@@ -432,6 +435,19 @@ static const struct weston_desktop_surface_implementation weston_desktop_wl_shel
 };
 
 static void
+wl_surface_resource_destroyed(struct wl_listener *listener,
+					     void *data)
+{
+	struct weston_desktop_wl_shell_surface *surface =
+		wl_container_of(listener, surface,
+				wl_surface_resource_destroy_listener);
+
+	/* the wl_shell_surface spec says that wl_shell_surfaces are to be
+	 * destroyed automatically when the wl_surface is destroyed. */
+	weston_desktop_surface_destroy(surface->surface);
+}
+
+static void
 weston_desktop_wl_shell_protocol_get_shell_surface(struct wl_client *wl_client,
 						   struct wl_resource *resource,
 						   uint32_t id,
@@ -463,6 +479,11 @@ weston_desktop_wl_shell_protocol_get_shell_surface(struct wl_client *wl_client,
 		return;
 	}
 
+	surface->wl_surface_resource_destroy_listener.notify =
+		wl_surface_resource_destroyed;
+	wl_resource_add_destroy_listener(wsurface->resource,
+					 &surface->wl_surface_resource_destroy_listener);
+
 	surface->resource =
 		weston_desktop_surface_add_resource(surface->surface,
 						    &wl_shell_surface_interface,
-- 
2.10.0



More information about the wayland-devel mailing list