diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-30 11:39:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-30 11:39:00 -0400 |
commit | 2426ca0241c70105859f13cb02ef765986ca1cc2 (patch) | |
tree | ae5197dabda270035b383d45b5c113afab2ebfbd /sway/tree/layout.c | |
parent | 2d460502812093b47f43295cf21636198e44edbb (diff) | |
parent | 01af34391267e91461a4ab7a1234dd58f45d2c93 (diff) | |
download | sway-2426ca0241c70105859f13cb02ef765986ca1cc2.tar.xz |
Merge pull request #1658 from swaywm/delete-empty-ws
Destroy empty workspaces when moving away
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r-- | sway/tree/layout.c | 37 |
1 files changed, 37 insertions, 0 deletions
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 |