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