mirror of
https://github.com/swaywm/sway.git
synced 2025-11-16 06:59:49 -05:00
Handle view destruction properly
This commit is contained in:
parent
a57d462926
commit
8caabe59c2
6 changed files with 73 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,19 @@ void add_child(swayc_t *parent, swayc_t *child) {
|
|||
*/
|
||||
}
|
||||
|
||||
swayc_t *remove_child(swayc_t *child) {
|
||||
int i;
|
||||
swayc_t *parent = child->parent;
|
||||
for (i = 0; i < parent->children->length; ++i) {
|
||||
if (parent->children->items[i] == child) {
|
||||
list_del(parent->children, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
child->parent = NULL;
|
||||
return parent;
|
||||
}
|
||||
|
||||
enum swayc_layouts default_layout(swayc_t *output) {
|
||||
/* TODO WLR
|
||||
if (config->default_layout != L_NONE) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue