From 01af34391267e91461a4ab7a1234dd58f45d2c93 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 10:31:21 -0400 Subject: Destroy empty workspaces when moving away --- sway/tree/layout.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'sway/tree/layout.c') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index dc0ee5b4..97007888 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -11,6 +11,7 @@ #include "sway/output.h" #include "sway/tree/view.h" #include "sway/input/seat.h" +#include "sway/ipc-server.h" #include "list.h" #include "log.h" @@ -121,6 +122,42 @@ struct sway_container *container_remove_child(struct sway_container *child) { return parent; } +struct sway_container *container_reap_empty(struct sway_container *container) { + if (!sway_assert(container, "reaping null container")) { + return NULL; + } + while (container->children->length == 0 && container->type == C_CONTAINER) { + wlr_log(L_DEBUG, "Container: Destroying container '%p'", container); + struct sway_container *parent = container->parent; + container_destroy(container); + container = parent; + } + return container; +} + +void container_move_to(struct sway_container* container, + struct sway_container* destination) { + if (container == destination + || container_has_anscestor(container, destination)) { + return; + } + struct sway_container *old_parent = container_remove_child(container); + container->width = container->height = 0; + struct sway_container *new_parent = + container_add_sibling(destination, container); + if (destination->type == C_WORKSPACE) { + // If the workspace only has one child after adding one, it + // means that the workspace was just initialized. + // TODO: Consider floating views in this test + if (destination->children->length == 1) { + ipc_event_workspace(NULL, destination, "init"); + } + } + old_parent = container_reap_empty(old_parent); + arrange_windows(old_parent, -1, -1); + arrange_windows(new_parent, -1, -1); +} + enum sway_container_layout container_get_default_layout( struct sway_container *output) { /* TODO WLR -- cgit v1.2.3-54-g00ecf