diff options
author | Alexander Orzechowski <alex@ozal.ski> | 2024-01-18 10:00:45 -0500 |
---|---|---|
committer | Kirill Primak <vyivel@eclair.cafe> | 2024-01-18 18:36:54 +0300 |
commit | 1eb16d136774c8fb3c9085df45156264f0db8814 (patch) | |
tree | 9c348ab37edae50b76a388d7e8d8dcd011cea33b /sway/tree/container.c | |
parent | view: init function should return a success bool (diff) | |
download | sway-1eb16d136774c8fb3c9085df45156264f0db8814.tar.gz sway-1eb16d136774c8fb3c9085df45156264f0db8814.tar.zst sway-1eb16d136774c8fb3c9085df45156264f0db8814.zip |
scene_graph: Maintain `wlr_scene_node`s for the sway tree.
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 8c344a6d..9ed08929 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -27,6 +27,24 @@ | |||
27 | #include "log.h" | 27 | #include "log.h" |
28 | #include "stringop.h" | 28 | #include "stringop.h" |
29 | 29 | ||
30 | static struct wlr_scene_rect *alloc_rect_node(struct wlr_scene_tree *parent, | ||
31 | bool *failed) { | ||
32 | if (*failed) { | ||
33 | return NULL; | ||
34 | } | ||
35 | |||
36 | // just pass in random values. These will be overwritten when | ||
37 | // they need to be used. | ||
38 | struct wlr_scene_rect *rect = wlr_scene_rect_create( | ||
39 | parent, 0, 0, (float[4]){0.f, 0.f, 0.f, 1.f}); | ||
40 | if (!rect) { | ||
41 | sway_log(SWAY_ERROR, "Failed to allocate a wlr_scene_rect"); | ||
42 | *failed = true; | ||
43 | } | ||
44 | |||
45 | return rect; | ||
46 | } | ||
47 | |||
30 | struct sway_container *container_create(struct sway_view *view) { | 48 | struct sway_container *container_create(struct sway_view *view) { |
31 | struct sway_container *c = calloc(1, sizeof(struct sway_container)); | 49 | struct sway_container *c = calloc(1, sizeof(struct sway_container)); |
32 | if (!c) { | 50 | if (!c) { |
@@ -34,14 +52,62 @@ struct sway_container *container_create(struct sway_view *view) { | |||
34 | return NULL; | 52 | return NULL; |
35 | } | 53 | } |
36 | node_init(&c->node, N_CONTAINER, c); | 54 | node_init(&c->node, N_CONTAINER, c); |
37 | c->pending.layout = L_NONE; | 55 | |
38 | c->view = view; | 56 | // Container tree structure |
39 | c->alpha = 1.0f; | 57 | // - scene tree |
58 | // - title bar | ||
59 | // - border | ||
60 | // - background | ||
61 | // - title text | ||
62 | // - marks text | ||
63 | // - border | ||
64 | // - border top/bottom/left/right | ||
65 | // - content_tree (we put the content node here so when we disable the | ||
66 | // border everything gets disabled. We only render the content iff there | ||
67 | // is a border as well) | ||
68 | bool failed = false; | ||
69 | c->scene_tree = alloc_scene_tree(root->staging, &failed); | ||
70 | |||
71 | c->title_bar.tree = alloc_scene_tree(c->scene_tree, &failed); | ||
72 | c->title_bar.border = alloc_scene_tree(c->title_bar.tree, &failed); | ||
73 | c->title_bar.background = alloc_scene_tree(c->title_bar.tree, &failed); | ||
74 | |||
75 | // for opacity purposes we need to carfully create the scene such that | ||
76 | // none of our rect nodes as well as text buffers don't overlap. To do | ||
77 | // this we have to create rects such that they go around text buffers | ||
78 | for (int i = 0; i < 4; i++) { | ||
79 | alloc_rect_node(c->title_bar.border, &failed); | ||
80 | } | ||
81 | |||
82 | for (int i = 0; i < 5; i++) { | ||
83 | alloc_rect_node(c->title_bar.background, &failed); | ||
84 | } | ||
85 | |||
86 | c->border.tree = alloc_scene_tree(c->scene_tree, &failed); | ||
87 | c->content_tree = alloc_scene_tree(c->border.tree, &failed); | ||
88 | |||
89 | if (view) { | ||
90 | // only containers with views can have borders | ||
91 | c->border.top = alloc_rect_node(c->border.tree, &failed); | ||
92 | c->border.bottom = alloc_rect_node(c->border.tree, &failed); | ||
93 | c->border.left = alloc_rect_node(c->border.tree, &failed); | ||
94 | c->border.right = alloc_rect_node(c->border.tree, &failed); | ||
95 | } | ||
96 | |||
97 | if (failed) { | ||
98 | wlr_scene_node_destroy(&c->scene_tree->node); | ||
99 | free(c); | ||
100 | return NULL; | ||
101 | } | ||
40 | 102 | ||
41 | if (!view) { | 103 | if (!view) { |
42 | c->pending.children = create_list(); | 104 | c->pending.children = create_list(); |
43 | c->current.children = create_list(); | 105 | c->current.children = create_list(); |
44 | } | 106 | } |
107 | |||
108 | c->pending.layout = L_NONE; | ||
109 | c->view = view; | ||
110 | c->alpha = 1.0f; | ||
45 | c->marks = create_list(); | 111 | c->marks = create_list(); |
46 | c->outputs = create_list(); | 112 | c->outputs = create_list(); |
47 | 113 | ||
@@ -85,6 +151,8 @@ void container_destroy(struct sway_container *con) { | |||
85 | } | 151 | } |
86 | } | 152 | } |
87 | 153 | ||
154 | scene_node_disown_children(con->content_tree); | ||
155 | wlr_scene_node_destroy(&con->scene_tree->node); | ||
88 | free(con); | 156 | free(con); |
89 | } | 157 | } |
90 | 158 | ||