aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 19:23:59 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 19:23:59 -0400
commit481a8275c178f81bb2d9927c5047e959fdbc383a (patch)
tree4a2f1f85be06a17f2885a53676bd446d8fd8c502 /sway/tree/container.c
parentfix old todos (diff)
downloadsway-481a8275c178f81bb2d9927c5047e959fdbc383a.tar.gz
sway-481a8275c178f81bb2d9927c5047e959fdbc383a.tar.zst
sway-481a8275c178f81bb2d9927c5047e959fdbc383a.zip
address feedback
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c127
1 files changed, 70 insertions, 57 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index f616af09..77c61b3f 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -186,45 +186,44 @@ static struct sway_container *container_workspace_destroy(
186 return parent; 186 return parent;
187} 187}
188 188
189static void container_root_finish(struct sway_container *con) {
190 wlr_log(L_ERROR, "TODO: destroy the root container");
191}
189 192
190static void reap_empty_func(struct sway_container *con, void *data) { 193static bool container_reap_empty(struct sway_container *con) {
191 switch (con->type) { 194 switch (con->type) {
192 case C_TYPES: 195 case C_ROOT:
193 case C_ROOT: 196 case C_OUTPUT:
194 case C_OUTPUT: 197 // dont reap these
195 // dont reap these 198 break;
196 break; 199 case C_WORKSPACE:
197 case C_WORKSPACE: 200 if (!workspace_is_visible(con) && con->children->length == 0) {
198 if (!workspace_is_visible(con) && con->children->length == 0) { 201 container_workspace_destroy(con);
199 container_workspace_destroy(con); 202 return true;
200 } 203 }
201 break; 204 break;
202 case C_CONTAINER: 205 case C_CONTAINER:
203 if (con->children->length == 0) { 206 if (con->children->length == 0) {
207 container_finish(con);
208 return true;
209 } else if (con->children->length == 1) {
210 struct sway_container *child = con->children->items[0];
211 if (child->type == C_CONTAINER) {
212 container_remove_child(child);
213 container_replace_child(con, child);
204 container_finish(con); 214 container_finish(con);
205 } else if (con->children->length == 1) { 215 return true;
206 struct sway_container *only_child = con->children->items[0];
207 if (only_child->type == C_CONTAINER) {
208 container_remove_child(only_child);
209 container_replace_child(con, only_child);
210 container_finish(con);
211 }
212 } 216 }
213 case C_VIEW: 217 }
214 break; 218 case C_VIEW:
219 break;
220 case C_TYPES:
221 sway_assert(false, "container_reap_empty called on an invalid "
222 "container");
223 break;
215 } 224 }
216}
217
218struct sway_container *container_reap_empty(struct sway_container *container) {
219 struct sway_container *parent = container->parent;
220
221 container_for_each_descendant_dfs(container, reap_empty_func, NULL);
222 225
223 return parent; 226 return false;
224}
225
226static void container_root_finish(struct sway_container *con) {
227 wlr_log(L_ERROR, "TODO: destroy the root container");
228} 227}
229 228
230struct sway_container *container_destroy(struct sway_container *con) { 229struct sway_container *container_destroy(struct sway_container *con) {
@@ -232,38 +231,52 @@ struct sway_container *container_destroy(struct sway_container *con) {
232 return NULL; 231 return NULL;
233 } 232 }
234 233
235 struct sway_container *anscestor = NULL; 234 struct sway_container *parent = con->parent;
236 235
237 switch (con->type) { 236 switch (con->type) {
238 case C_ROOT: 237 case C_ROOT:
239 container_root_finish(con); 238 container_root_finish(con);
240 break; 239 break;
241 case C_OUTPUT: 240 case C_OUTPUT:
242 anscestor = container_output_destroy(con); 241 // dont try to reap the root after this
242 container_output_destroy(con);
243 break; 243 break;
244 case C_WORKSPACE: 244 case C_WORKSPACE:
245 anscestor = container_workspace_destroy(con); 245 // dont try to reap the output after this
246 container_workspace_destroy(con);
246 break; 247 break;
247 case C_CONTAINER: 248 case C_CONTAINER:
248 if (con->children != NULL && con->children->length) { 249 if (con->children->length) {
249 assert(false && 250 for (int i = 0; i < con->children->length; ++i) {
250 "dont destroy container containers with children"); 251 struct sway_container *child = con->children->items[0];
252 container_remove_child(child);
253 container_add_child(parent, child);
254 }
255 container_finish(con);
251 } 256 }
252 container_finish(con); 257 container_finish(con);
253 // TODO return parent to arrange maybe?
254 break; 258 break;
255 case C_VIEW: 259 case C_VIEW:
256 container_finish(con); 260 container_finish(con);
257 // TODO return parent to arrange maybe?
258 break; 261 break;
259 case C_TYPES: 262 case C_TYPES:
260 wlr_log(L_ERROR, "tried to destroy an invalid container"); 263 wlr_log(L_ERROR, "container_destroy called on an invalid "
264 "container");
261 break; 265 break;
262 } 266 }
263 267
264 container_reap_empty(&root_container); 268 struct sway_container *tmp = parent;
269 while (parent) {
270 tmp = parent->parent;
271
272 if (!container_reap_empty(parent)) {
273 break;
274 }
275
276 parent = tmp;
277 }
265 278
266 return anscestor; 279 return tmp;
267} 280}
268 281
269static void container_close_func(struct sway_container *container, void *data) { 282static void container_close_func(struct sway_container *container, void *data) {
@@ -274,23 +287,23 @@ static void container_close_func(struct sway_container *container, void *data) {
274 287
275struct sway_container *container_close(struct sway_container *con) { 288struct sway_container *container_close(struct sway_container *con) {
276 if (!sway_assert(con != NULL, 289 if (!sway_assert(con != NULL,
277 "container_close called with a NULL container")) { 290 "container_close called with a NULL container")) {
278 return NULL; 291 return NULL;
279 } 292 }
280 293
281 struct sway_container *parent = con->parent; 294 struct sway_container *parent = con->parent;
282 295
283 switch (con->type) { 296 switch (con->type) {
284 case C_TYPES: 297 case C_TYPES:
285 case C_ROOT: 298 case C_ROOT:
286 case C_OUTPUT: 299 case C_OUTPUT:
287 case C_WORKSPACE: 300 case C_WORKSPACE:
288 case C_CONTAINER: 301 case C_CONTAINER:
289 container_for_each_descendant_dfs(con, container_close_func, NULL); 302 container_for_each_descendant_dfs(con, container_close_func, NULL);
290 break; 303 break;
291 case C_VIEW: 304 case C_VIEW:
292 view_close(con->sway_view); 305 view_close(con->sway_view);
293 break; 306 break;
294 307
295 } 308 }
296 309
@@ -365,8 +378,8 @@ struct sway_container *container_output_create(
365static struct sway_container *get_workspace_initial_output(const char *name) { 378static struct sway_container *get_workspace_initial_output(const char *name) {
366 struct sway_container *parent; 379 struct sway_container *parent;
367 // Search for workspace<->output pair 380 // Search for workspace<->output pair
368 int i, e = config->workspace_outputs->length; 381 int e = config->workspace_outputs->length;
369 for (i = 0; i < e; ++i) { 382 for (int i = 0; i < config->workspace_outputs->length; ++i) {
370 struct workspace_output *wso = config->workspace_outputs->items[i]; 383 struct workspace_output *wso = config->workspace_outputs->items[i];
371 if (strcasecmp(wso->workspace, name) == 0) { 384 if (strcasecmp(wso->workspace, name) == 0) {
372 // Find output to use if it exists 385 // Find output to use if it exists