From: Johan Malm Date: Fri, 18 Sep 2020 19:28:48 +0000 (+0100) Subject: desktop: focus next 'mapped' view on minimize X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=3c90cb79450fb7a11c2036681e99dfaf9d91482a;p=proto%2Flabwc.git desktop: focus next 'mapped' view on minimize --- diff --git a/include/labwc.h b/include/labwc.h index c210ae7f..94811474 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -207,6 +207,7 @@ void desktop_focus_view(struct view *view); * Note: If current==NULL, the list's second view is returned */ struct view *desktop_next_view(struct server *server, struct view *current); +void desktop_focus_next_mapped_view(struct view *current); struct view *desktop_view_at(struct server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy, int *view_area); diff --git a/src/desktop.c b/src/desktop.c index 5bae409c..8729aaf5 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -77,8 +77,10 @@ static void focus_view(struct view *view) void desktop_focus_view(struct view *view) { - if (!view) + if (!view) { + seat_focus_surface(NULL); return; + } if (view->minimized) view_unminimize(view); /* this will unmap+focus */ else if (view->mapped) @@ -100,7 +102,7 @@ static bool isfocusable(struct view *view) return (view->mapped || view->minimized); } -static int has_focusable_view(struct wl_list *wl_list) +static bool has_focusable_view(struct wl_list *wl_list) { struct view *view; wl_list_for_each (view, wl_list, link) { @@ -131,6 +133,35 @@ struct view *desktop_next_view(struct server *server, struct view *current) return view; } +static bool has_mapped_view(struct wl_list *wl_list) +{ + struct view *view; + wl_list_for_each (view, wl_list, link) { + if (view->mapped) + return true; + } + return false; +} + +struct view *desktop_next_mapped_view(struct view *current) +{ + BUG_ON(!current); + struct server *server = current->server; + if (!has_mapped_view(&server->views)) + return NULL; + struct view *view = first_view(server); + do { + view = wl_container_of(view->link.next, view, link); + } while (&view->link == &server->views || !view->mapped); + return view; +} +void desktop_focus_next_mapped_view(struct view *current) +{ + BUG_ON(!current); + struct view *view = desktop_next_mapped_view(current); + desktop_focus_view(view); +} + static bool _view_at(struct view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { diff --git a/src/xdg.c b/src/xdg.c index c5c761b2..a28610cf 100644 --- a/src/xdg.c +++ b/src/xdg.c @@ -171,7 +171,7 @@ static void xdg_toplevel_view_unmap(struct view *view) { view->mapped = false; wl_list_remove(&view->commit.link); - desktop_focus_view(desktop_next_view(view->server, view)); + desktop_focus_next_mapped_view(view); } static const struct view_impl xdg_toplevel_view_impl = { diff --git a/src/xwayland.c b/src/xwayland.c index 006d1375..836b9c6d 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -100,7 +100,7 @@ static void unmap(struct view *view) { view->mapped = false; wl_list_remove(&view->commit.link); - desktop_focus_view(desktop_next_view(view->server, view)); + desktop_focus_next_mapped_view(view); } static const struct view_impl xwl_view_impl = {