]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: move xwayland sub-views to front on focus
authorJohan Malm <jgm323@gmail.com>
Tue, 8 Sep 2020 19:35:20 +0000 (20:35 +0100)
committerJohan Malm <jgm323@gmail.com>
Tue, 8 Sep 2020 19:35:20 +0000 (20:35 +0100)
src/view.c

index 0132efba9deefaeb6fa3fa2bbc055949d3dd600e..01ff35963cac1c993df80e282e17bfcd7f0080b2 100644 (file)
@@ -99,6 +99,35 @@ bool view_hasfocus(struct view *view)
        return (view->surface == seat->keyboard_state.focused_surface);
 }
 
+static struct wlr_xwayland_surface *top_parent_of(struct view *view)
+{
+       struct wlr_xwayland_surface *s = view->xwayland_surface;
+       while (s->parent)
+               s = s->parent;
+       return s;
+}
+
+static void move_xwayland_sub_views_to_front(struct view *parent)
+{
+       if (!parent || parent->type != LAB_XWAYLAND_VIEW)
+               return;
+       struct view *view, *next;
+       wl_list_for_each_reverse_safe(view, next, &parent->server->views, link)
+       {
+               /* need to stop here, otherwise loops keeps going forever */
+               if (view == parent)
+                       break;
+               if (view->type != LAB_XWAYLAND_VIEW)
+                       continue;
+               if (!view->mapped && !view->minimized)
+                       continue;
+               if (top_parent_of(view) != parent->xwayland_surface)
+                       continue;
+               move_to_front(view);
+               /* TODO: we should probably focus on these too here */
+       }
+}
+
 void view_focus(struct view *view)
 {
        /* Note: this function only deals with keyboard focus. */
@@ -137,7 +166,7 @@ void view_focus(struct view *view)
                                       keyboard->num_keycodes,
                                       &keyboard->modifiers);
 
-       /* TODO: move xwayland decendants to front */
+       move_xwayland_sub_views_to_front(view);
 }
 
 static struct view *first_view(struct server *server)