From d782e482040604fb3b18403da42d028ea110c620 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 8 Sep 2020 20:35:20 +0100 Subject: [PATCH] view: move xwayland sub-views to front on focus --- src/view.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/view.c b/src/view.c index 0132efba..01ff3596 100644 --- a/src/view.c +++ b/src/view.c @@ -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)