diff --git a/view.c b/view.c index 724bc6e..3361a34 100644 --- a/view.c +++ b/view.c @@ -68,6 +68,18 @@ view_is_primary(struct cg_view *view) return view->is_primary(view); } +bool +view_has_children(struct cg_server *server, struct cg_view *parent) +{ + struct cg_view *child; + wl_list_for_each(child, &server->views, link) { + if (parent != child && parent->is_parent(parent, child)) { + return true; + } + } + return false; +} + void view_position(struct cg_view *view) { diff --git a/view.h b/view.h index b38a2c7..718238d 100644 --- a/view.h +++ b/view.h @@ -49,6 +49,7 @@ struct cg_view { struct wlr_surface *(*wlr_surface_at)(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y); bool (*is_primary)(struct cg_view *view); + bool (*is_parent)(struct cg_view *parent, struct cg_view *child); }; void view_activate(struct cg_view *view, bool activate); @@ -56,6 +57,7 @@ void view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t ite struct wlr_surface *view_wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y); bool view_is_primary(struct cg_view *view); +bool view_has_children(struct cg_server *server, struct cg_view *view); void view_position(struct cg_view *view); void view_unmap(struct cg_view *view); void view_map(struct cg_view *view, struct wlr_surface *surface); diff --git a/xdg_shell.c b/xdg_shell.c index 6b6a2f6..23be4aa 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -58,6 +58,12 @@ is_primary(struct cg_view *view) return parent == NULL; /*&& role == WLR_XDG_SURFACE_ROLE_TOPLEVEL */ } +static bool +is_parent(struct cg_view *parent, struct cg_view *child) +{ + return child->xdg_surface->toplevel->parent == parent->xdg_surface; +} + static void handle_xdg_shell_surface_unmap(struct wl_listener *listener, void *data) { @@ -106,4 +112,5 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data) view->for_each_surface = for_each_surface; view->wlr_surface_at = wlr_surface_at; view->is_primary = is_primary; + view->is_parent = is_parent; } diff --git a/xwayland.c b/xwayland.c index b025822..64eb58c 100644 --- a/xwayland.c +++ b/xwayland.c @@ -54,6 +54,12 @@ is_primary(struct cg_view *view) return parent == NULL; } +static bool +is_parent(struct cg_view *parent, struct cg_view *child) +{ + return child->xwayland_surface->parent == parent->xwayland_surface; +} + static void handle_xwayland_surface_unmap(struct wl_listener *listener, void *data) { @@ -98,4 +104,5 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data) view->for_each_surface = for_each_surface; view->wlr_surface_at = wlr_surface_at; view->is_primary = is_primary; + view->is_parent = is_parent; }