From 27a0b8b74f5662551ae1e17c9ac27fb1595cdbbd Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Mon, 9 Jan 2023 15:21:22 +0300 Subject: [PATCH] xwayland/xwm: unpair even if surface is NULL This is a backport of a922428c41dedea2c27f614963e7876926bba7fb which partially reverts 32daa43a454bcea1306ad0976fd4161ce8c7e86f. Fixes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3561 --- xwayland/xwm.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 3a3d35f22..c6273fa06 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -384,11 +384,30 @@ static void xsurface_set_net_wm_state(struct wlr_xwayland_surface *xsurface) { i, property); } +static void xsurface_unpair(struct wlr_xwayland_surface *surface, + bool destroy_role_object) { + if (surface->mapped) { + wl_signal_emit_mutable(&surface->events.unmap, surface); + surface->mapped = false; + xwm_set_net_client_list(surface->xwm); + } + + // Make sure we're not on the unpaired surface list or we + // could be assigned a surface during surface creation that + // was mapped before this unmap request. + wl_list_remove(&surface->unpaired_link); + wl_list_init(&surface->unpaired_link); + surface->surface_id = 0; + + if (destroy_role_object && surface->surface != NULL) { + wlr_surface_destroy_role_object(surface->surface); + } + surface->surface = NULL; +} + static void xwayland_surface_destroy( struct wlr_xwayland_surface *xsurface) { - if (xsurface->surface != NULL) { - wlr_surface_destroy_role_object(xsurface->surface); - } + xsurface_unpair(xsurface, true); wl_signal_emit_mutable(&xsurface->events.destroy, xsurface); @@ -851,19 +870,7 @@ static void xwayland_surface_role_destroy(struct wlr_surface *wlr_surface) { assert(wlr_surface->role == &xwayland_surface_role); struct wlr_xwayland_surface *surface = wlr_surface->role_data; - if (surface->mapped) { - wl_signal_emit_mutable(&surface->events.unmap, surface); - surface->mapped = false; - xwm_set_net_client_list(surface->xwm); - } - - // Make sure we're not on the unpaired surface list or we - // could be assigned a surface during surface creation that - // was mapped before this unmap request. - wl_list_remove(&surface->unpaired_link); - wl_list_init(&surface->unpaired_link); - surface->surface_id = 0; - surface->surface = NULL; + xsurface_unpair(surface, false); } static const struct wlr_surface_role xwayland_surface_role = { @@ -1077,10 +1084,7 @@ static void xwm_handle_unmap_notify(struct wlr_xwm *xwm, return; } - if (xsurface->surface != NULL) { - wlr_surface_destroy_role_object(xsurface->surface); - } - + xsurface_unpair(xsurface, true); xsurface_set_wm_state(xsurface, XCB_ICCCM_WM_STATE_WITHDRAWN); }