diff options
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r-- | sway/tree/layout.c | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index dc0ee5b4..588ceb2d 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -9,8 +9,10 @@ #include "sway/tree/container.h" #include "sway/tree/layout.h" #include "sway/output.h" +#include "sway/tree/workspace.h" #include "sway/tree/view.h" #include "sway/input/seat.h" +#include "sway/ipc-server.h" #include "list.h" #include "log.h" @@ -98,37 +100,67 @@ void container_add_child(struct sway_container *parent, parent, parent->type, parent->width, parent->height); list_add(parent->children, child); child->parent = parent; - // set focus for this container - /* TODO WLR - if (parent->type == C_WORKSPACE && child->type == C_VIEW && - (parent->workspace_layout == L_TABBED || parent->workspace_layout == - L_STACKED)) { - child = new_container(child, parent->workspace_layout); +} + +struct sway_container *container_reap_empty(struct sway_container *container) { + if (!sway_assert(container, "reaping null container")) { + return NULL; } - */ + wlr_log(L_DEBUG, "reaping %p %s", container, container->name); + while (container->children->length == 0) { + if (container->type == C_WORKSPACE) { + if (!workspace_is_visible(container)) { + struct sway_container *parent = container->parent; + container_workspace_destroy(container); + return parent; + } + return container; + } else if (container->type == C_CONTAINER) { + struct sway_container *parent = container->parent; + container_destroy(container); + container = parent; + } else { + container = container->parent; + } + } + return container; } struct sway_container *container_remove_child(struct sway_container *child) { - int i; struct sway_container *parent = child->parent; - for (i = 0; i < parent->children->length; ++i) { + for (int i = 0; i < parent->children->length; ++i) { if (parent->children->items[i] == child) { list_del(parent->children, i); break; } } child->parent = NULL; - return parent; + return container_reap_empty(parent); +} + +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 (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 if (config->default_layout != L_NONE) { - //return config->default_layout; + return config->default_layout; } else if (config->default_orientation != L_NONE) { return config->default_orientation; - } else */if (output->width >= output->height) { + } else if (output->width >= output->height) { return L_HORIZ; } else { return L_VERT; |