aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 22:37:21 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 22:37:21 -0400
commit2992b72d61933568476e2bf4baf573e714f9ed40 (patch)
tree0682e081d94d73ef2b4b9a7f8d1646c11bb33b8e /sway/tree/container.c
parentfix more close segfaults (diff)
downloadsway-2992b72d61933568476e2bf4baf573e714f9ed40.tar.gz
sway-2992b72d61933568476e2bf4baf573e714f9ed40.tar.zst
sway-2992b72d61933568476e2bf4baf573e714f9ed40.zip
change reap container approach
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 8688edd6..686a52c7 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -1,4 +1,5 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <assert.h>
2#include <stdint.h> 3#include <stdint.h>
3#include <stdlib.h> 4#include <stdlib.h>
4#include <string.h> 5#include <string.h>
@@ -109,12 +110,55 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
109 return parent; 110 return parent;
110} 111}
111 112
112struct sway_container *container_destroy(struct sway_container *cont) { 113static void reap_empty_func(struct sway_container *con, void *data) {
113 struct sway_container *parent = _container_destroy(cont); 114 switch (con->type) {
114 parent = container_reap_empty(parent); 115 case C_TYPES:
116 case C_ROOT:
117 case C_OUTPUT:
118 // dont reap these
119 break;
120 case C_WORKSPACE:
121 if (!workspace_is_visible(con) && con->children->length == 0) {
122 container_workspace_destroy(con);
123 }
124 break;
125 case C_CONTAINER:
126 if (con->children->length == 0) {
127 _container_destroy(con);
128 } else if (con->children->length == 1) {
129 struct sway_container *only_child = con->children->items[0];
130 if (only_child->type == C_CONTAINER) {
131 container_remove_child(only_child);
132 container_replace_child(con, only_child);
133 _container_destroy(con);
134 }
135 }
136 case C_VIEW:
137 break;
138 }
139}
140
141struct sway_container *container_reap_empty(struct sway_container *container) {
142 struct sway_container *parent = container->parent;
143
144 container_for_each_descendant_dfs(container, reap_empty_func, NULL);
145
115 return parent; 146 return parent;
116} 147}
117 148
149void container_destroy(struct sway_container *cont) {
150 if (cont == NULL) {
151 return;
152 }
153
154 if (cont->children != NULL && cont->children->length) {
155 assert(false && "dont destroy containers with children");
156 }
157
158 _container_destroy(cont);
159 container_reap_empty(&root_container);
160}
161
118static void container_close_func(struct sway_container *container, void *data) { 162static void container_close_func(struct sway_container *container, void *data) {
119 if (container->type == C_VIEW) { 163 if (container->type == C_VIEW) {
120 view_close(container->sway_view); 164 view_close(container->sway_view);
@@ -126,6 +170,8 @@ struct sway_container *container_close(struct sway_container *con) {
126 return NULL; 170 return NULL;
127 } 171 }
128 172
173 struct sway_container *parent = con->parent;
174
129 switch (con->type) { 175 switch (con->type) {
130 case C_TYPES: 176 case C_TYPES:
131 wlr_log(L_ERROR, "tried to close an invalid container"); 177 wlr_log(L_ERROR, "tried to close an invalid container");
@@ -148,7 +194,7 @@ struct sway_container *container_close(struct sway_container *con) {
148 194
149 } 195 }
150 196
151 return con->parent; 197 return parent;
152} 198}
153 199
154struct sway_container *container_output_create( 200struct sway_container *container_output_create(