aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2018-04-02 22:37:21 -0400
committerTony Crisci <tony@dubstepdish.com>2018-04-02 22:37:21 -0400
commit2992b72d61933568476e2bf4baf573e714f9ed40 (patch)
tree0682e081d94d73ef2b4b9a7f8d1646c11bb33b8e /sway/tree
parent2c165e1288cbb60f5e677595e35f58a9c56c7010 (diff)
change reap container approach
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c54
-rw-r--r--sway/tree/layout.c29
-rw-r--r--sway/tree/view.c10
3 files changed, 58 insertions, 35 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 8688edd6..686a52c7 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200809L
+#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -109,12 +110,55 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
return parent;
}
-struct sway_container *container_destroy(struct sway_container *cont) {
- struct sway_container *parent = _container_destroy(cont);
- parent = container_reap_empty(parent);
+static void reap_empty_func(struct sway_container *con, void *data) {
+ switch (con->type) {
+ case C_TYPES:
+ case C_ROOT:
+ case C_OUTPUT:
+ // dont reap these
+ break;
+ case C_WORKSPACE:
+ if (!workspace_is_visible(con) && con->children->length == 0) {
+ container_workspace_destroy(con);
+ }
+ break;
+ case C_CONTAINER:
+ if (con->children->length == 0) {
+ _container_destroy(con);
+ } else if (con->children->length == 1) {
+ struct sway_container *only_child = con->children->items[0];
+ if (only_child->type == C_CONTAINER) {
+ container_remove_child(only_child);
+ container_replace_child(con, only_child);
+ _container_destroy(con);
+ }
+ }
+ case C_VIEW:
+ break;
+ }
+}
+
+struct sway_container *container_reap_empty(struct sway_container *container) {
+ struct sway_container *parent = container->parent;
+
+ container_for_each_descendant_dfs(container, reap_empty_func, NULL);
+
return parent;
}
+void container_destroy(struct sway_container *cont) {
+ if (cont == NULL) {
+ return;
+ }
+
+ if (cont->children != NULL && cont->children->length) {
+ assert(false && "dont destroy containers with children");
+ }
+
+ _container_destroy(cont);
+ container_reap_empty(&root_container);
+}
+
static void container_close_func(struct sway_container *container, void *data) {
if (container->type == C_VIEW) {
view_close(container->sway_view);
@@ -126,6 +170,8 @@ struct sway_container *container_close(struct sway_container *con) {
return NULL;
}
+ struct sway_container *parent = con->parent;
+
switch (con->type) {
case C_TYPES:
wlr_log(L_ERROR, "tried to close an invalid container");
@@ -148,7 +194,7 @@ struct sway_container *container_close(struct sway_container *con) {
}
- return con->parent;
+ return parent;
}
struct sway_container *container_output_create(
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index b0ce4aaf..79470f98 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -103,32 +103,6 @@ void container_add_child(struct sway_container *parent,
child->parent = parent;
}
-struct sway_container *container_reap_empty(struct sway_container *container) {
- if (container == NULL) {
- return NULL;
- }
- 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 && 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) {
struct sway_container *parent = child->parent;
for (int i = 0; i < parent->children->length; ++i) {
@@ -309,6 +283,8 @@ void arrange_windows(struct sway_container *container,
container->children->length);
break;
case L_VERT:
+ assert(container);
+ assert(container->children);
apply_vert_layout(container, x, y, width, height, 0,
container->children->length);
break;
@@ -381,6 +357,7 @@ void apply_vert_layout(struct sway_container *container,
const double x, const double y,
const double width, const double height, const int start,
const int end) {
+ assert(container);
int i;
double scale = 0;
// Calculate total height
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 4e695b5f..eeadc5d8 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -78,14 +78,12 @@ void view_close(struct sway_view *view) {
}
}
-struct sway_container *container_view_destroy(struct sway_container *view) {
+void container_view_destroy(struct sway_container *view) {
if (!view) {
- return NULL;
+ return;
}
wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
- struct sway_container *parent = container_destroy(view);
- arrange_windows(&root_container, -1, -1);
- return parent;
+ container_destroy(view);
}
void view_damage_whole(struct sway_view *view) {
@@ -164,6 +162,8 @@ void view_unmap(struct sway_view *view) {
view->swayc = NULL;
view->surface = NULL;
+
+ arrange_windows(&root_container, -1, -1);
}
void view_update_position(struct sway_view *view, double ox, double oy) {