aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/node.c')
-rw-r--r--sway/tree/node.c56
1 files changed, 42 insertions, 14 deletions
diff --git a/sway/tree/node.c b/sway/tree/node.c
index ffa7f2cc..7aaf9762 100644
--- a/sway/tree/node.c
+++ b/sway/tree/node.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include "sway/output.h" 1#include "sway/output.h"
3#include "sway/server.h" 2#include "sway/server.h"
4#include "sway/tree/container.h" 3#include "sway/tree/container.h"
@@ -18,13 +17,13 @@ void node_init(struct sway_node *node, enum sway_node_type type, void *thing) {
18const char *node_type_to_str(enum sway_node_type type) { 17const char *node_type_to_str(enum sway_node_type type) {
19 switch (type) { 18 switch (type) {
20 case N_ROOT: 19 case N_ROOT:
21 return "N_ROOT"; 20 return "root";
22 case N_OUTPUT: 21 case N_OUTPUT:
23 return "N_OUTPUT"; 22 return "output";
24 case N_WORKSPACE: 23 case N_WORKSPACE:
25 return "N_WORKSPACE"; 24 return "workspace";
26 case N_CONTAINER: 25 case N_CONTAINER:
27 return "N_CONTAINER"; 26 return "container";
28 } 27 }
29 return ""; 28 return "";
30} 29}
@@ -75,7 +74,7 @@ void node_get_box(struct sway_node *node, struct wlr_box *box) {
75struct sway_output *node_get_output(struct sway_node *node) { 74struct sway_output *node_get_output(struct sway_node *node) {
76 switch (node->type) { 75 switch (node->type) {
77 case N_CONTAINER: { 76 case N_CONTAINER: {
78 struct sway_workspace *ws = node->sway_container->workspace; 77 struct sway_workspace *ws = node->sway_container->pending.workspace;
79 return ws ? ws->output : NULL; 78 return ws ? ws->output : NULL;
80 } 79 }
81 case N_WORKSPACE: 80 case N_WORKSPACE:
@@ -91,7 +90,7 @@ struct sway_output *node_get_output(struct sway_node *node) {
91enum sway_container_layout node_get_layout(struct sway_node *node) { 90enum sway_container_layout node_get_layout(struct sway_node *node) {
92 switch (node->type) { 91 switch (node->type) {
93 case N_CONTAINER: 92 case N_CONTAINER:
94 return node->sway_container->layout; 93 return node->sway_container->pending.layout;
95 case N_WORKSPACE: 94 case N_WORKSPACE:
96 return node->sway_workspace->layout; 95 return node->sway_workspace->layout;
97 case N_OUTPUT: 96 case N_OUTPUT:
@@ -105,11 +104,11 @@ struct sway_node *node_get_parent(struct sway_node *node) {
105 switch (node->type) { 104 switch (node->type) {
106 case N_CONTAINER: { 105 case N_CONTAINER: {
107 struct sway_container *con = node->sway_container; 106 struct sway_container *con = node->sway_container;
108 if (con->parent) { 107 if (con->pending.parent) {
109 return &con->parent->node; 108 return &con->pending.parent->node;
110 } 109 }
111 if (con->workspace) { 110 if (con->pending.workspace) {
112 return &con->workspace->node; 111 return &con->pending.workspace->node;
113 } 112 }
114 } 113 }
115 return NULL; 114 return NULL;
@@ -131,7 +130,7 @@ struct sway_node *node_get_parent(struct sway_node *node) {
131list_t *node_get_children(struct sway_node *node) { 130list_t *node_get_children(struct sway_node *node) {
132 switch (node->type) { 131 switch (node->type) {
133 case N_CONTAINER: 132 case N_CONTAINER:
134 return node->sway_container->children; 133 return node->sway_container->pending.children;
135 case N_WORKSPACE: 134 case N_WORKSPACE:
136 return node->sway_workspace->tiling; 135 return node->sway_workspace->tiling;
137 case N_OUTPUT: 136 case N_OUTPUT:
@@ -143,7 +142,7 @@ list_t *node_get_children(struct sway_node *node) {
143 142
144bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor) { 143bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor) {
145 if (ancestor->type == N_ROOT && node->type == N_CONTAINER && 144 if (ancestor->type == N_ROOT && node->type == N_CONTAINER &&
146 node->sway_container->fullscreen_mode == FULLSCREEN_GLOBAL) { 145 node->sway_container->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
147 return true; 146 return true;
148 } 147 }
149 struct sway_node *parent = node_get_parent(node); 148 struct sway_node *parent = node_get_parent(node);
@@ -152,10 +151,39 @@ bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor) {
152 return true; 151 return true;
153 } 152 }
154 if (ancestor->type == N_ROOT && parent->type == N_CONTAINER && 153 if (ancestor->type == N_ROOT && parent->type == N_CONTAINER &&
155 parent->sway_container->fullscreen_mode == FULLSCREEN_GLOBAL) { 154 parent->sway_container->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
156 return true; 155 return true;
157 } 156 }
158 parent = node_get_parent(parent); 157 parent = node_get_parent(parent);
159 } 158 }
160 return false; 159 return false;
161} 160}
161
162void scene_node_disown_children(struct wlr_scene_tree *tree) {
163 // this function can be called as part of destruction code that will be invoked
164 // upon an allocation failure. Let's not crash on NULL due to an allocation error.
165 if (!tree) {
166 return;
167 }
168
169 struct wlr_scene_node *child, *tmp_child;
170 wl_list_for_each_safe(child, tmp_child, &tree->children, link) {
171 wlr_scene_node_reparent(child, root->staging);
172 }
173}
174
175struct wlr_scene_tree *alloc_scene_tree(struct wlr_scene_tree *parent,
176 bool *failed) {
177 // fallthrough
178 if (*failed) {
179 return NULL;
180 }
181
182 struct wlr_scene_tree *tree = wlr_scene_tree_create(parent);
183 if (!tree) {
184 sway_log(SWAY_ERROR, "Failed to allocate a scene node");
185 *failed = true;
186 }
187
188 return tree;
189}