aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/tree/container.h2
-rw-r--r--sway/commands/kill.c5
-rw-r--r--sway/tree/container.c37
-rw-r--r--sway/tree/layout.c2
-rw-r--r--sway/tree/view.c2
5 files changed, 41 insertions, 7 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 464f80c4..5d15f12b 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -134,6 +134,8 @@ struct sway_container *container_workspace_destroy(struct sway_container *contai
struct sway_container *container_output_destroy(struct sway_container *container);
struct sway_container *container_view_destroy(struct sway_container *container);
+struct sway_container *container_close(struct sway_container *container);
+
// TODO move to layout.c
struct sway_container *container_set_layout(struct sway_container *container,
enum sway_container_layout layout);
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index 46d6e98e..811c3e6b 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -19,11 +19,8 @@ struct cmd_results *cmd_kill(int argc, char **argv) {
"Can only kill views and containers with this command");
break;
case C_CONTAINER:
- con = container_destroy(con);
- arrange_windows(con, -1, -1);
- break;
case C_VIEW:
- view_close(con->sway_view);
+ container_close(con);
break;
}
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 4db93ce8..8688edd6 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -112,10 +112,45 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
struct sway_container *container_destroy(struct sway_container *cont) {
struct sway_container *parent = _container_destroy(cont);
parent = container_reap_empty(parent);
- arrange_windows(&root_container, -1, -1);
return parent;
}
+static void container_close_func(struct sway_container *container, void *data) {
+ if (container->type == C_VIEW) {
+ view_close(container->sway_view);
+ }
+}
+
+struct sway_container *container_close(struct sway_container *con) {
+ if (!sway_assert(con != NULL, "container_close called with a NULL container")) {
+ return NULL;
+ }
+
+ switch (con->type) {
+ case C_TYPES:
+ wlr_log(L_ERROR, "tried to close an invalid container");
+ break;
+ case C_ROOT:
+ wlr_log(L_ERROR, "tried to close the root container");
+ break;
+ case C_OUTPUT:
+ container_output_destroy(con);
+ break;
+ case C_WORKSPACE:
+ container_workspace_destroy(con);
+ break;
+ case C_CONTAINER:
+ container_for_each_descendant_dfs(con, container_close_func, NULL);
+ break;
+ case C_VIEW:
+ view_close(con->sway_view);
+ break;
+
+ }
+
+ return con->parent;
+}
+
struct sway_container *container_output_create(
struct sway_output *sway_output) {
struct wlr_box size;
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 95a84d12..b0ce4aaf 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -110,7 +110,7 @@ struct sway_container *container_reap_empty(struct sway_container *container) {
wlr_log(L_DEBUG, "Reaping %p %s '%s'", container,
container_type_to_str(container->type), container->name);
while (container->type != C_ROOT && container->type != C_OUTPUT
- && container->children->length == 0) {
+ && container->children && container->children->length == 0) {
if (container->type == C_WORKSPACE) {
if (!workspace_is_visible(container)) {
struct sway_container *parent = container->parent;
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 09c804e4..4e695b5f 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -84,7 +84,7 @@ struct sway_container *container_view_destroy(struct sway_container *view) {
}
wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
struct sway_container *parent = container_destroy(view);
- arrange_windows(parent, -1, -1);
+ arrange_windows(&root_container, -1, -1);
return parent;
}