]> git.mdlowis.com Git - proto/labwc.git/commitdiff
desktop: focus next 'mapped' view on minimize
authorJohan Malm <jgm323@gmail.com>
Fri, 18 Sep 2020 19:28:48 +0000 (20:28 +0100)
committerJohan Malm <jgm323@gmail.com>
Fri, 18 Sep 2020 19:28:48 +0000 (20:28 +0100)
include/labwc.h
src/desktop.c
src/xdg.c
src/xwayland.c

index c210ae7f1616a18d76f3086550ad2d59130fbeb1..94811474d28532391bf131715cb1a3fcd91dd2ba 100644 (file)
@@ -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);
index 5bae409c671fdfa11d06ace536f8e24e75b959be..8729aaf5ef308b0be0d022d52ca8cd80168bc5d8 100644 (file)
@@ -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)
 {
index c5c761b224dce826fc831bb687f191c1d2dcb6b6..a28610cf4d42f2c586f5f6e3c78a72d099a84ef8 100644 (file)
--- 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 = {
index 006d137574181e83c965b5e108eba5c6b3a38f62..836b9c6dcbaf76baee50a9b5216be6ed0519bfed 100644 (file)
@@ -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 = {