From 2263cbf2ea1dbfa85d2c081f11c346ea0a55020e Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Sun, 1 Feb 2026 14:45:38 -0300 Subject: [PATCH] xdg-shell: handle xdg_wm_base being destroyed before its children According to the xdg-shell protocol specification, if the xdg_wm_base object is destroyed while there are still xdg_surface objects associated with it, the compositor must post a protocol error (DEFUNCT_SURFACES) to the client. In this patch we do that. Signed-off-by: Leandro Ribeiro --- libweston/desktop/xdg-shell-v6.c | 21 ++++++++++++++++++++- libweston/desktop/xdg-shell.c | 21 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/libweston/desktop/xdg-shell-v6.c b/libweston/desktop/xdg-shell-v6.c index 1f11416d1..9b62727d9 100644 --- a/libweston/desktop/xdg-shell-v6.c +++ b/libweston/desktop/xdg-shell-v6.c @@ -1514,8 +1514,27 @@ weston_desktop_xdg_shell_protocol_pong(struct wl_client *wl_client, weston_desktop_client_pong(client, serial); } +static void +weston_desktop_xdg_shell_protocol_destroy(struct wl_client *wl_client, + struct wl_resource *resource) +{ + struct weston_desktop_client *client = + wl_resource_get_user_data(resource); + struct wl_list *surface_list = + weston_desktop_client_get_surface_list(client); + + if (!wl_list_empty(surface_list)) { + wl_resource_post_error(resource, + ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES, + "xdg_wm_base being destroyed before child surfaces"); + return; + } + + weston_desktop_destroy_request(wl_client, resource); +} + static const struct zxdg_shell_v6_interface weston_desktop_xdg_shell_implementation = { - .destroy = weston_desktop_destroy_request, + .destroy = weston_desktop_xdg_shell_protocol_destroy, .create_positioner = weston_desktop_xdg_shell_protocol_create_positioner, .get_xdg_surface = weston_desktop_xdg_shell_protocol_get_xdg_surface, .pong = weston_desktop_xdg_shell_protocol_pong, diff --git a/libweston/desktop/xdg-shell.c b/libweston/desktop/xdg-shell.c index cd784da24..818345569 100644 --- a/libweston/desktop/xdg-shell.c +++ b/libweston/desktop/xdg-shell.c @@ -2102,8 +2102,27 @@ weston_desktop_xdg_shell_protocol_pong(struct wl_client *wl_client, weston_desktop_client_pong(client, serial); } +static void +weston_desktop_xdg_shell_protocol_destroy(struct wl_client *wl_client, + struct wl_resource *resource) +{ + struct weston_desktop_client *client = + wl_resource_get_user_data(resource); + struct wl_list *surface_list = + weston_desktop_client_get_surface_list(client); + + if (!wl_list_empty(surface_list)) { + wl_resource_post_error(resource, + XDG_WM_BASE_ERROR_DEFUNCT_SURFACES, + "xdg_wm_base being destroyed before child surfaces"); + return; + } + + weston_desktop_destroy_request(wl_client, resource); +} + static const struct xdg_wm_base_interface weston_desktop_xdg_shell_implementation = { - .destroy = weston_desktop_destroy_request, + .destroy = weston_desktop_xdg_shell_protocol_destroy, .create_positioner = weston_desktop_xdg_shell_protocol_create_positioner, .get_xdg_surface = weston_desktop_xdg_shell_protocol_get_xdg_surface, .pong = weston_desktop_xdg_shell_protocol_pong,