From 5a50a02ba3e5d5a83f163ee603a2255779d941ab Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 11 Jun 2025 16:12:56 -0400 Subject: [PATCH] xwayland: fix possible loss of focus when multiple views are unmapped Due to the asynchronous nature of view_offer_focus(), there was a race condition that could result in no view remaining active when multiple views were unmapped at once. Check for this and prevent it. --- src/view-impl-common.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/view-impl-common.c b/src/view-impl-common.c index 9e8e9a1e..3357367b 100644 --- a/src/view-impl-common.c +++ b/src/view-impl-common.c @@ -46,7 +46,15 @@ void view_impl_unmap(struct view *view) { struct server *server = view->server; - if (view == server->active_view) { + /* + * When exiting an xwayland application with multiple views + * mapped, a race condition can occur: after the topmost view + * is unmapped, the next view under it is offered focus, but is + * also unmapped before accepting focus (so server->active_view + * remains NULL). To avoid being left with no active view at + * all, check for that case also. + */ + if (view == server->active_view || !server->active_view) { desktop_focus_topmost_view(server); } } -- 2.52.0