From 1eb16d136774c8fb3c9085df45156264f0db8814 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Thu, 18 Jan 2024 10:00:45 -0500 Subject: scene_graph: Maintain `wlr_scene_node`s for the sway tree. --- include/sway/output.h | 15 +++++++++++++++ include/sway/tree/container.h | 21 +++++++++++++++++++++ include/sway/tree/node.h | 12 ++++++++++++ include/sway/tree/root.h | 26 ++++++++++++++++++++++++++ include/sway/tree/view.h | 4 ++++ include/sway/tree/workspace.h | 7 +++++++ 6 files changed, 85 insertions(+) (limited to 'include') diff --git a/include/sway/output.h b/include/sway/output.h index 96bd10db..691ac8dd 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "config.h" #include "sway/tree/node.h" #include "sway/tree/view.h" @@ -19,7 +20,21 @@ struct sway_output_state { struct sway_output { struct sway_node node; + + struct { + struct wlr_scene_tree *tiling; + struct wlr_scene_tree *fullscreen; + } layers; + + // when a container is fullscreen, in case the fullscreen surface is + // translucent (can see behind) we must make sure that the background is a + // solid color in order to conform to the wayland protocol. This rect + // ensures that when looking through a surface, all that will be seen + // is black. + struct wlr_scene_rect *fullscreen_background; + struct wlr_output *wlr_output; + struct wlr_scene_output *scene_output; struct sway_server *server; struct wl_list link; diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index fe3ee8a8..ee22a0d0 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "list.h" #include "sway/tree/node.h" @@ -68,6 +69,26 @@ struct sway_container { struct sway_node node; struct sway_view *view; + struct wlr_scene_tree *scene_tree; + + struct { + struct wlr_scene_tree *tree; + + struct wlr_scene_tree *border; + struct wlr_scene_tree *background; + } title_bar; + + struct { + struct wlr_scene_tree *tree; + + struct wlr_scene_rect *top; + struct wlr_scene_rect *bottom; + struct wlr_scene_rect *left; + struct wlr_scene_rect *right; + } border; + + struct wlr_scene_tree *content_tree; + struct sway_container_state current; struct sway_container_state pending; diff --git a/include/sway/tree/node.h b/include/sway/tree/node.h index 03a389a4..e2dbcdf0 100644 --- a/include/sway/tree/node.h +++ b/include/sway/tree/node.h @@ -2,6 +2,7 @@ #define _SWAY_NODE_H #include #include +#include #include "list.h" #define MIN_SANE_W 100 @@ -75,4 +76,15 @@ list_t *node_get_children(struct sway_node *node); bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor); +// when destroying a sway tree, it's not known which order the tree will be +// destroyed. To prevent freeing of scene_nodes recursing up the tree, +// let's use this helper function to disown them to the staging node. +void scene_node_disown_children(struct wlr_scene_tree *tree); + +// a helper function used to allocate tree nodes. If an allocation failure +// occurs a flag is flipped that can be checked later to destroy a parent +// of this scene node preventing memory leaks. +struct wlr_scene_tree *alloc_scene_tree(struct wlr_scene_tree *parent, + bool *failed); + #endif diff --git a/include/sway/tree/root.h b/include/sway/tree/root.h index b3dda12f..9cb3d7bf 100644 --- a/include/sway/tree/root.h +++ b/include/sway/tree/root.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "sway/tree/container.h" #include "sway/tree/node.h" @@ -16,6 +17,31 @@ struct sway_root { struct wlr_output_layout *output_layout; struct wl_listener output_layout_change; + + // scene node layout: + // - root + // - staging + // - layer shell stuff + // - tiling + // - floating + // - fullscreen stuff + // - seat stuff + // - ext_session_lock + struct wlr_scene *root_scene; + + // since wlr_scene nodes can't be orphaned and must always + // have a parent, use this staging scene_tree so that a + // node always have a valid parent. Nothing in this + // staging node will be visible. + struct wlr_scene_tree *staging; + + struct { + struct wlr_scene_tree *tiling; + struct wlr_scene_tree *floating; + struct wlr_scene_tree *fullscreen; + struct wlr_scene_tree *fullscreen_global; + } layers; + #if HAVE_XWAYLAND struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link #endif diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 822e7bb3..4aaed9e3 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -2,6 +2,7 @@ #define _SWAY_VIEW_H #include #include +#include #include "sway/config.h" #if HAVE_XWAYLAND #include @@ -69,6 +70,9 @@ struct sway_view { enum sway_view_type type; const struct sway_view_impl *impl; + struct wlr_scene_tree *scene_tree; + struct wlr_scene_tree *content_tree; + struct sway_container *container; // NULL if unmapped and transactions finished struct wlr_surface *surface; // NULL for unmapped views struct sway_xdg_decoration *xdg_decoration; diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index b0fef4ca..58bde20c 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -2,6 +2,7 @@ #define _SWAY_WORKSPACE_H #include +#include #include "sway/config.h" #include "sway/tree/container.h" #include "sway/tree/node.h" @@ -23,6 +24,12 @@ struct sway_workspace_state { struct sway_workspace { struct sway_node node; + + struct { + struct wlr_scene_tree *tiling; + struct wlr_scene_tree *fullscreen; + } layers; + struct sway_container *fullscreen; char *name; -- cgit v1.2.3-54-g00ecf