aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-11-25 16:30:15 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-11-25 16:30:15 -0500
commit8caabe59c2e6f6174678e6c28be3381a7dabff10 (patch)
tree5425efb1f3b68e9b275d8429bba70a2b132b72c9 /sway/tree
parentFix rendering issues, wire up some xdg listeners (diff)
downloadsway-8caabe59c2e6f6174678e6c28be3381a7dabff10.tar.gz
sway-8caabe59c2e6f6174678e6c28be3381a7dabff10.tar.zst
sway-8caabe59c2e6f6174678e6c28be3381a7dabff10.zip
Handle view destruction properly
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c42
-rw-r--r--sway/tree/layout.c13
2 files changed, 55 insertions, 0 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index a83c0f6b..c7bce38a 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -109,6 +109,48 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
109 return swayc; 109 return swayc;
110} 110}
111 111
112static void free_swayc(swayc_t *cont) {
113 if (!sway_assert(cont, "free_swayc passed NULL")) {
114 return;
115 }
116 if (cont->children) {
117 // remove children until there are no more, free_swayc calls
118 // remove_child, which removes child from this container
119 while (cont->children->length) {
120 free_swayc(cont->children->items[0]);
121 }
122 list_free(cont->children);
123 }
124 if (cont->marks) {
125 list_foreach(cont->marks, free);
126 list_free(cont->marks);
127 }
128 if (cont->parent) {
129 remove_child(cont);
130 }
131 if (cont->name) {
132 free(cont->name);
133 }
134 free(cont);
135}
136
137swayc_t *destroy_view(swayc_t *view) {
138 if (!sway_assert(view, "null view passed to destroy_view")) {
139 return NULL;
140 }
141 sway_log(L_DEBUG, "Destroying view '%s'", view->name);
142 swayc_t *parent = view->parent;
143 free_swayc(view);
144
145 // TODO WLR: Destroy empty containers
146 /*
147 if (parent && parent->type == C_CONTAINER) {
148 return destroy_container(parent);
149 }
150 */
151 return parent;
152}
153
112swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { 154swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
113 if (!sway_assert(container, "container is NULL")) { 155 if (!sway_assert(container, "container is NULL")) {
114 return NULL; 156 return NULL;
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 6e2586a7..ea7bb8bb 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -40,6 +40,19 @@ void add_child(swayc_t *parent, swayc_t *child) {
40 */ 40 */
41} 41}
42 42
43swayc_t *remove_child(swayc_t *child) {
44 int i;
45 swayc_t *parent = child->parent;
46 for (i = 0; i < parent->children->length; ++i) {
47 if (parent->children->items[i] == child) {
48 list_del(parent->children, i);
49 break;
50 }
51 }
52 child->parent = NULL;
53 return parent;
54}
55
43enum swayc_layouts default_layout(swayc_t *output) { 56enum swayc_layouts default_layout(swayc_t *output) {
44 /* TODO WLR 57 /* TODO WLR
45 if (config->default_layout != L_NONE) { 58 if (config->default_layout != L_NONE) {