diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-25 16:30:15 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-11-25 16:30:15 -0500 |
commit | 8caabe59c2e6f6174678e6c28be3381a7dabff10 (patch) | |
tree | 5425efb1f3b68e9b275d8429bba70a2b132b72c9 /sway/tree/container.c | |
parent | a57d46292694e388d74add7b0869bcafdb42b2bd (diff) |
Handle view destruction properly
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 42 |
1 files changed, 42 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) { return swayc; } +static void free_swayc(swayc_t *cont) { + if (!sway_assert(cont, "free_swayc passed NULL")) { + return; + } + if (cont->children) { + // remove children until there are no more, free_swayc calls + // remove_child, which removes child from this container + while (cont->children->length) { + free_swayc(cont->children->items[0]); + } + list_free(cont->children); + } + if (cont->marks) { + list_foreach(cont->marks, free); + list_free(cont->marks); + } + if (cont->parent) { + remove_child(cont); + } + if (cont->name) { + free(cont->name); + } + free(cont); +} + +swayc_t *destroy_view(swayc_t *view) { + if (!sway_assert(view, "null view passed to destroy_view")) { + return NULL; + } + sway_log(L_DEBUG, "Destroying view '%s'", view->name); + swayc_t *parent = view->parent; + free_swayc(view); + + // TODO WLR: Destroy empty containers + /* + if (parent && parent->type == C_CONTAINER) { + return destroy_container(parent); + } + */ + return parent; +} + swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { if (!sway_assert(container, "container is NULL")) { return NULL; |