summaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index ea0b7d5c..4db93ce8 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -55,7 +55,7 @@ static void notify_new_container(struct sway_container *container) {
55 ipc_event_window(container, "new"); 55 ipc_event_window(container, "new");
56} 56}
57 57
58static struct sway_container *container_create(enum sway_container_type type) { 58struct sway_container *container_create(enum sway_container_type type) {
59 // next id starts at 1 because 0 is assigned to root_container in layout.c 59 // next id starts at 1 because 0 is assigned to root_container in layout.c
60 static size_t next_id = 1; 60 static size_t next_id = 1;
61 struct sway_container *c = calloc(1, sizeof(struct sway_container)); 61 struct sway_container *c = calloc(1, sizeof(struct sway_container));
@@ -76,7 +76,7 @@ static struct sway_container *container_create(enum sway_container_type type) {
76 return c; 76 return c;
77} 77}
78 78
79struct sway_container *container_destroy(struct sway_container *cont) { 79static struct sway_container *_container_destroy(struct sway_container *cont) {
80 if (cont == NULL) { 80 if (cont == NULL) {
81 return NULL; 81 return NULL;
82 } 82 }
@@ -84,13 +84,14 @@ struct sway_container *container_destroy(struct sway_container *cont) {
84 wl_signal_emit(&cont->events.destroy, cont); 84 wl_signal_emit(&cont->events.destroy, cont);
85 85
86 struct sway_container *parent = cont->parent; 86 struct sway_container *parent = cont->parent;
87 if (cont->children) { 87 if (cont->children != NULL) {
88 // remove children until there are no more, container_destroy calls 88 // remove children until there are no more, container_destroy calls
89 // container_remove_child, which removes child from this container 89 // container_remove_child, which removes child from this container
90 while (cont->children->length) { 90 while (cont->children != NULL && cont->children->length != 0) {
91 container_destroy(cont->children->items[0]); 91 struct sway_container *child = cont->children->items[0];
92 container_remove_child(child);
93 container_destroy(child);
92 } 94 }
93 list_free(cont->children);
94 } 95 }
95 if (cont->marks) { 96 if (cont->marks) {
96 list_foreach(cont->marks, free); 97 list_foreach(cont->marks, free);
@@ -102,10 +103,19 @@ struct sway_container *container_destroy(struct sway_container *cont) {
102 if (cont->name) { 103 if (cont->name) {
103 free(cont->name); 104 free(cont->name);
104 } 105 }
106 list_free(cont->children);
107 cont->children = NULL;
105 free(cont); 108 free(cont);
106 return parent; 109 return parent;
107} 110}
108 111
112struct sway_container *container_destroy(struct sway_container *cont) {
113 struct sway_container *parent = _container_destroy(cont);
114 parent = container_reap_empty(parent);
115 arrange_windows(&root_container, -1, -1);
116 return parent;
117}
118
109struct sway_container *container_output_create( 119struct sway_container *container_output_create(
110 struct sway_output *sway_output) { 120 struct sway_output *sway_output) {
111 struct wlr_box size; 121 struct wlr_box size;
@@ -413,3 +423,17 @@ bool container_has_anscestor(struct sway_container *descendant,
413 } 423 }
414 return false; 424 return false;
415} 425}
426
427static bool find_child_func(struct sway_container *con, void *data) {
428 struct sway_container *child = data;
429 return con == child;
430}
431
432bool container_has_child(struct sway_container *con,
433 struct sway_container *child) {
434 if (child == NULL || child->type == C_VIEW ||
435 child->children->length == 0) {
436 return false;
437 }
438 return container_find(con, find_child_func, child);
439}