unify container destroy functions

This commit is contained in:
Tony Crisci 2018-04-03 12:34:01 -04:00
parent b4c5f79725
commit 09d448ea2d
5 changed files with 40 additions and 41 deletions

View file

@ -133,8 +133,6 @@ struct sway_container *container_destroy(struct sway_container *container);
// TODO make me private // TODO make me private
struct sway_container *container_finish(struct sway_container *cont); struct sway_container *container_finish(struct sway_container *cont);
struct sway_container *container_output_destroy(struct sway_container *container);
struct sway_container *container_close(struct sway_container *container); struct sway_container *container_close(struct sway_container *container);
// TODO move to layout.c // TODO move to layout.c

View file

@ -127,7 +127,7 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
if (oc && oc->enabled == 0) { if (oc && oc->enabled == 0) {
wlr_output_layout_remove(root_container.sway_root->output_layout, wlr_output_layout_remove(root_container.sway_root->output_layout,
wlr_output); wlr_output);
container_output_destroy(output); container_destroy(output);
return; return;
} }

View file

@ -338,12 +338,12 @@ void output_damage_whole_view(struct sway_output *output,
static void damage_handle_destroy(struct wl_listener *listener, void *data) { static void damage_handle_destroy(struct wl_listener *listener, void *data) {
struct sway_output *output = struct sway_output *output =
wl_container_of(listener, output, damage_destroy); wl_container_of(listener, output, damage_destroy);
container_output_destroy(output->swayc); container_destroy(output->swayc);
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, destroy); struct sway_output *output = wl_container_of(listener, output, destroy);
container_output_destroy(output->swayc); container_destroy(output->swayc);
} }
static void handle_mode(struct wl_listener *listener, void *data) { static void handle_mode(struct wl_listener *listener, void *data) {

View file

@ -109,6 +109,43 @@ struct sway_container *container_finish(struct sway_container *cont) {
free(cont); free(cont);
return parent; return parent;
} }
static struct sway_container *container_output_destroy(struct sway_container *output) {
if (!sway_assert(output, "cannot destroy null output")) {
return NULL;
}
if (output->children->length > 0) {
// TODO save workspaces when there are no outputs.
// TODO also check if there will ever be no outputs except for exiting
// program
if (root_container.children->length > 1) {
int p = root_container.children->items[0] == output;
// Move workspace from this output to another output
while (output->children->length) {
struct sway_container *child = output->children->items[0];
container_remove_child(child);
container_add_child(root_container.children->items[p], child);
}
container_sort_workspaces(root_container.children->items[p]);
arrange_windows(root_container.children->items[p],
-1, -1);
}
}
wl_list_remove(&output->sway_output->destroy.link);
wl_list_remove(&output->sway_output->mode.link);
wl_list_remove(&output->sway_output->transform.link);
wl_list_remove(&output->sway_output->scale.link);
wl_list_remove(&output->sway_output->damage_destroy.link);
wl_list_remove(&output->sway_output->damage_frame.link);
wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
container_finish(output);
return &root_container;
}
static struct sway_container *container_workspace_destroy( static struct sway_container *container_workspace_destroy(
struct sway_container *workspace) { struct sway_container *workspace) {
if (!sway_assert(workspace, "cannot destroy null workspace")) { if (!sway_assert(workspace, "cannot destroy null workspace")) {

View file

@ -4,42 +4,6 @@
#include "sway/output.h" #include "sway/output.h"
#include "log.h" #include "log.h"
struct sway_container *container_output_destroy(struct sway_container *output) {
if (!sway_assert(output, "cannot destroy null output")) {
return NULL;
}
if (output->children->length > 0) {
// TODO save workspaces when there are no outputs.
// TODO also check if there will ever be no outputs except for exiting
// program
if (root_container.children->length > 1) {
int p = root_container.children->items[0] == output;
// Move workspace from this output to another output
while (output->children->length) {
struct sway_container *child = output->children->items[0];
container_remove_child(child);
container_add_child(root_container.children->items[p], child);
}
container_sort_workspaces(root_container.children->items[p]);
arrange_windows(root_container.children->items[p],
-1, -1);
}
}
wl_list_remove(&output->sway_output->destroy.link);
wl_list_remove(&output->sway_output->mode.link);
wl_list_remove(&output->sway_output->transform.link);
wl_list_remove(&output->sway_output->scale.link);
wl_list_remove(&output->sway_output->damage_destroy.link);
wl_list_remove(&output->sway_output->damage_frame.link);
wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
container_destroy(output);
return &root_container;
}
struct sway_container *output_by_name(const char *name) { struct sway_container *output_by_name(const char *name) {
for (int i = 0; i < root_container.children->length; ++i) { for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *output = root_container.children->items[i]; struct sway_container *output = root_container.children->items[i];