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.
This commit is contained in:
John Lindgren 2025-06-11 16:12:56 -04:00 committed by Johan Malm
parent 1b937ed247
commit 5a50a02ba3

View file

@ -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);
}
}