static void free_swayc(swayc_t *cont) { if (!ASSERT_NONNULL(cont)) { return; } // TODO does not properly handle containers with children, // TODO but functions that call this usually check for that if (cont->children) { if (cont->children->length) { int i; for (i = 0; i < cont->children->length; ++i) { free_swayc(cont->children->items[i]); } } list_free(cont->children); } if (cont->floating) { if (cont->floating->length) { int i; for (i = 0; i < cont->floating->length; ++i) { free_swayc(cont->floating->items[i]); } } list_free(cont->floating); } if (cont->parent) { remove_child(cont); } if (cont->name) { free(cont->name); } free(cont); }
swayc_t *destroy_output(swayc_t *output) { if (output->children->length == 0) { //TODO move workspaces to other outputs } sway_log(L_DEBUG, "OUTPUT: Destroying output '%u'", (unsigned int)output->handle); free_swayc(output); return &root_container; }
swayc_t *destroy_container(swayc_t *container) { while (container->children->length == 0 && container->type == C_CONTAINER) { sway_log(L_DEBUG, "Container: Destroying container '%p'", container); swayc_t *parent = container->parent; free_swayc(container); container = parent; } return container; }
swayc_t *destroy_output(swayc_t *output) { if (!ASSERT_NONNULL(output)) { return NULL; } if (output->children->length == 0) { // TODO move workspaces to other outputs } sway_log(L_DEBUG, "OUTPUT: Destroying output '%lu'", output->handle); free_swayc(output); return &root_container; }
swayc_t *destroy_workspace(swayc_t *workspace) { //NOTE: This is called from elsewhere without checking children length //TODO move containers to other workspaces? //for now just dont delete if (workspace->children->length == 0) { sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); swayc_t *parent = workspace->parent; free_swayc(workspace); return parent; } return NULL; }
swayc_t *destroy_view(swayc_t *view) { if (!ASSERT_NONNULL(view)) { return NULL; } sway_log(L_DEBUG, "Destroying view '%p'", view); swayc_t *parent = view->parent; free_swayc(view); // Destroy empty containers if (parent->type == C_CONTAINER) { return destroy_container(parent); } return parent; }
swayc_t *destroy_view(swayc_t *view) { if (view == NULL) { sway_log(L_DEBUG, "Warning: NULL passed into destroy_view"); return NULL; } sway_log(L_DEBUG, "Destroying view '%p'", view); swayc_t *parent = view->parent; free_swayc(view); //Destroy empty containers if (parent->type == C_CONTAINER) { return destroy_container(parent); } return parent; }
swayc_t *destroy_workspace(swayc_t *workspace) { if (!ASSERT_NONNULL(workspace)) { return NULL; } // NOTE: This is called from elsewhere without checking children length // TODO move containers to other workspaces? // for now just dont delete // Do not destroy this if it's the last workspace on this output swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); if (output && output->children->length == 1) { return NULL; } if (workspace->children->length == 0) { sway_log(L_DEBUG, "%s: '%s'", __func__, workspace->name); swayc_t *parent = workspace->parent; free_swayc(workspace); return parent; } return NULL; }