properly remove children in loops

This commit is contained in:
taiyu 2015-08-31 08:49:24 -07:00
parent 4d9b05e649
commit 09c9ee76c3
1 changed files with 6 additions and 10 deletions

View File

@ -35,11 +35,8 @@ static void free_swayc(swayc_t *cont) {
list_free(cont->children); list_free(cont->children);
} }
if (cont->floating) { if (cont->floating) {
if (cont->floating->length) { while (cont->floating->length) {
int i; free_swayc(cont->floating->items[0]);
for (i = 0; i < cont->floating->length; ++i) {
free_swayc(cont->floating->items[i]);
}
} }
list_free(cont->floating); list_free(cont->floating);
} }
@ -304,16 +301,14 @@ swayc_t *destroy_output(swayc_t *output) {
return NULL; return NULL;
} }
if (output->children->length > 0) { if (output->children->length > 0) {
int i, len = root_container.children->length;
// TODO save workspaces when there are no outputs. // TODO save workspaces when there are no outputs.
// TODO also check if there will ever be no outputs except for exiting // TODO also check if there will ever be no outputs except for exiting
// program // program
if (len > 1) { if (root_container.children->length > 1) {
len = output->children->length;
int p = root_container.children->items[0] == output; int p = root_container.children->items[0] == output;
// Move workspace from this output to another output // Move workspace from this output to another output
for (i = 0; i < len; ++i) { while (output->children->length) {
swayc_t *child = output->children->items[i]; swayc_t *child = output->children->items[0];
remove_child(child); remove_child(child);
add_child(root_container.children->items[p], child); add_child(root_container.children->items[p], child);
} }
@ -651,6 +646,7 @@ void update_visibility(swayc_t *container) {
} }
void reset_gaps(swayc_t *view, void *data) { void reset_gaps(swayc_t *view, void *data) {
(void) data;
if (!ASSERT_NONNULL(view)) { if (!ASSERT_NONNULL(view)) {
return; return;
} }