From 83e87cd3de612ef6938cf45290ab77ec15d63094 Mon Sep 17 00:00:00 2001 From: Keith Bowes Date: Sun, 23 Feb 2020 08:15:29 -0500 Subject: [PATCH] Less flaky refocus code --- waybox/xdg_shell.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/waybox/xdg_shell.c b/waybox/xdg_shell.c index 4a92acd..4fa8889 100644 --- a/waybox/xdg_shell.c +++ b/waybox/xdg_shell.c @@ -49,9 +49,16 @@ static void xdg_surface_unmap(struct wl_listener *listener, void *data) { struct wb_view *view = wl_container_of(listener, view, unmap); view->mapped = false; - /* Focus previous view's surface, if any */ - if (view->server->views.prev) { - focus_view((struct wb_view *) view->server->views.prev, ((struct wb_view *) view->server->views.prev)->xdg_surface->surface); + struct wb_view *current_view = (struct wb_view *) view->server->views.next; + struct wb_view *next_view = (struct wb_view *) current_view->link.next; + + /* If the current view is mapped, focus it. */ + if (current_view->mapped) { + focus_view(current_view, current_view->xdg_surface->surface); + } + /* Otherwise, focus the next view, if any. */ + else if (next_view->xdg_surface->surface) { + focus_view(next_view, next_view->xdg_surface->surface); } }