xwayland/xwm: dissociate even if surface is NULL

If a window is unmapped too quickly, we might receive UnmapNotify before
we get the corresponding wl_surface, which will later lead to
associating the same window twice. To fix this, move the NULL surface
check to xwayland_surface_dissociate(), which makes resetting the
unpaired link and the wl_surface object ID unconditional.

Fixes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3552
This commit is contained in:
Kirill Primak 2022-12-22 13:18:47 +03:00 committed by Simon Ser
parent 884237e9af
commit a922428c41

View file

@ -393,22 +393,23 @@ static void xwayland_surface_set_mapped(struct wlr_xwayland_surface *xsurface, b
static void xwayland_surface_dissociate(struct wlr_xwayland_surface *xsurface) { static void xwayland_surface_dissociate(struct wlr_xwayland_surface *xsurface) {
xwayland_surface_set_mapped(xsurface, false); xwayland_surface_set_mapped(xsurface, false);
if (xsurface->surface != NULL) {
wl_list_remove(&xsurface->surface_commit.link);
wl_list_remove(&xsurface->surface_precommit.link);
wlr_addon_finish(&xsurface->surface_addon);
xsurface->surface = NULL;
}
// Make sure we're not on the unpaired surface list or we // Make sure we're not on the unpaired surface list or we
// could be assigned a surface during surface creation that // could be assigned a surface during surface creation that
// was mapped before this unmap request. // was mapped before this unmap request.
wl_list_remove(&xsurface->unpaired_link); wl_list_remove(&xsurface->unpaired_link);
wl_list_init(&xsurface->unpaired_link); wl_list_init(&xsurface->unpaired_link);
wl_list_remove(&xsurface->surface_commit.link);
wl_list_remove(&xsurface->surface_precommit.link);
wlr_addon_finish(&xsurface->surface_addon);
xsurface->surface_id = 0; xsurface->surface_id = 0;
xsurface->surface = NULL;
} }
static void xwayland_surface_destroy(struct wlr_xwayland_surface *xsurface) { static void xwayland_surface_destroy(struct wlr_xwayland_surface *xsurface) {
if (xsurface->surface != NULL) {
xwayland_surface_dissociate(xsurface); xwayland_surface_dissociate(xsurface);
}
wl_signal_emit_mutable(&xsurface->events.destroy, xsurface); wl_signal_emit_mutable(&xsurface->events.destroy, xsurface);
@ -1087,9 +1088,7 @@ static void xwm_handle_unmap_notify(struct wlr_xwm *xwm,
return; return;
} }
if (xsurface->surface != NULL) {
xwayland_surface_dissociate(xsurface); xwayland_surface_dissociate(xsurface);
}
xsurface_set_wm_state(xsurface, XCB_ICCCM_WM_STATE_WITHDRAWN); xsurface_set_wm_state(xsurface, XCB_ICCCM_WM_STATE_WITHDRAWN);
} }