aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/tree/container.h4
-rw-r--r--include/sway/tree/layout.h4
-rw-r--r--sway/tree/container.c54
-rw-r--r--sway/tree/layout.c29
-rw-r--r--sway/tree/view.c10
5 files changed, 63 insertions, 38 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 5d15f12b..1286316a 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -128,11 +128,11 @@ struct sway_container *container_view_create(
128 struct sway_container *sibling, struct sway_view *sway_view); 128 struct sway_container *sibling, struct sway_view *sway_view);
129 129
130// TODO don't return the parent on destroy 130// TODO don't return the parent on destroy
131struct sway_container *container_destroy(struct sway_container *container); 131void container_destroy(struct sway_container *container);
132 132
133struct sway_container *container_workspace_destroy(struct sway_container *container); 133struct sway_container *container_workspace_destroy(struct sway_container *container);
134struct sway_container *container_output_destroy(struct sway_container *container); 134struct sway_container *container_output_destroy(struct sway_container *container);
135struct sway_container *container_view_destroy(struct sway_container *container); 135void container_view_destroy(struct sway_container *container);
136 136
137struct sway_container *container_close(struct sway_container *container); 137struct sway_container *container_close(struct sway_container *container);
138 138
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h
index 8badb244..9d33d561 100644
--- a/include/sway/tree/layout.h
+++ b/include/sway/tree/layout.h
@@ -41,7 +41,9 @@ struct sway_container *container_add_sibling(struct sway_container *parent,
41struct sway_container *container_remove_child(struct sway_container *child); 41struct sway_container *container_remove_child(struct sway_container *child);
42 42
43// TODO PRIVATE in tree.h 43// TODO PRIVATE in tree.h
44struct sway_container *container_reap_empty(struct sway_container *container); 44
45struct sway_container *container_replace_child(struct sway_container *child,
46 struct sway_container *new_child);
45 47
46// TODO move to tree.h 48// TODO move to tree.h
47void container_move_to(struct sway_container* container, 49void container_move_to(struct sway_container* container,
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 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <assert.h>
2#include <stdint.h> 3#include <stdint.h>
3#include <stdlib.h> 4#include <stdlib.h>
4#include <string.h> 5#include <string.h>
@@ -109,12 +110,55 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
109 return parent; 110 return parent;
110} 111}
111 112
112struct sway_container *container_destroy(struct sway_container *cont) { 113static void reap_empty_func(struct sway_container *con, void *data) {
113 struct sway_container *parent = _container_destroy(cont); 114 switch (con->type) {
114 parent = container_reap_empty(parent); 115 case C_TYPES:
116 case C_ROOT:
117 case C_OUTPUT:
118 // dont reap these
119 break;
120 case C_WORKSPACE:
121 if (!workspace_is_visible(con) && con->children->length == 0) {
122 container_workspace_destroy(con);
123 }
124 break;
125 case C_CONTAINER:
126 if (con->children->length == 0) {
127 _container_destroy(con);
128 } else if (con->children->length == 1) {
129 struct sway_container *only_child = con->children->items[0];
130 if (only_child->type == C_CONTAINER) {
131 container_remove_child(only_child);
132 container_replace_child(con, only_child);
133 _container_destroy(con);
134 }
135 }
136 case C_VIEW:
137 break;
138 }
139}
140
141struct sway_container *container_reap_empty(struct sway_container *container) {
142 struct sway_container *parent = container->parent;
143
144 container_for_each_descendant_dfs(container, reap_empty_func, NULL);
145
115 return parent; 146 return parent;
116} 147}
117 148
149void container_destroy(struct sway_container *cont) {
150 if (cont == NULL) {
151 return;
152 }
153
154 if (cont->children != NULL && cont->children->length) {
155 assert(false && "dont destroy containers with children");
156 }
157
158 _container_destroy(cont);
159 container_reap_empty(&root_container);
160}
161
118static void container_close_func(struct sway_container *container, void *data) { 162static void container_close_func(struct sway_container *container, void *data) {
119 if (container->type == C_VIEW) { 163 if (container->type == C_VIEW) {
120 view_close(container->sway_view); 164 view_close(container->sway_view);
@@ -126,6 +170,8 @@ struct sway_container *container_close(struct sway_container *con) {
126 return NULL; 170 return NULL;
127 } 171 }
128 172
173 struct sway_container *parent = con->parent;
174
129 switch (con->type) { 175 switch (con->type) {
130 case C_TYPES: 176 case C_TYPES:
131 wlr_log(L_ERROR, "tried to close an invalid container"); 177 wlr_log(L_ERROR, "tried to close an invalid container");
@@ -148,7 +194,7 @@ struct sway_container *container_close(struct sway_container *con) {
148 194
149 } 195 }
150 196
151 return con->parent; 197 return parent;
152} 198}
153 199
154struct sway_container *container_output_create( 200struct 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,
103 child->parent = parent; 103 child->parent = parent;
104} 104}
105 105
106struct sway_container *container_reap_empty(struct sway_container *container) {
107 if (container == NULL) {
108 return NULL;
109 }
110 wlr_log(L_DEBUG, "Reaping %p %s '%s'", container,
111 container_type_to_str(container->type), container->name);
112 while (container->type != C_ROOT && container->type != C_OUTPUT
113 && container->children && container->children->length == 0) {
114 if (container->type == C_WORKSPACE) {
115 if (!workspace_is_visible(container)) {
116 struct sway_container *parent = container->parent;
117 container_workspace_destroy(container);
118 return parent;
119 }
120 return container;
121 } else if (container->type == C_CONTAINER) {
122 struct sway_container *parent = container->parent;
123 container_destroy(container);
124 container = parent;
125 } else {
126 container = container->parent;
127 }
128 }
129 return container;
130}
131
132struct sway_container *container_remove_child(struct sway_container *child) { 106struct sway_container *container_remove_child(struct sway_container *child) {
133 struct sway_container *parent = child->parent; 107 struct sway_container *parent = child->parent;
134 for (int i = 0; i < parent->children->length; ++i) { 108 for (int i = 0; i < parent->children->length; ++i) {
@@ -309,6 +283,8 @@ void arrange_windows(struct sway_container *container,
309 container->children->length); 283 container->children->length);
310 break; 284 break;
311 case L_VERT: 285 case L_VERT:
286 assert(container);
287 assert(container->children);
312 apply_vert_layout(container, x, y, width, height, 0, 288 apply_vert_layout(container, x, y, width, height, 0,
313 container->children->length); 289 container->children->length);
314 break; 290 break;
@@ -381,6 +357,7 @@ void apply_vert_layout(struct sway_container *container,
381 const double x, const double y, 357 const double x, const double y,
382 const double width, const double height, const int start, 358 const double width, const double height, const int start,
383 const int end) { 359 const int end) {
360 assert(container);
384 int i; 361 int i;
385 double scale = 0; 362 double scale = 0;
386 // Calculate total height 363 // 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) {
78 } 78 }
79} 79}
80 80
81struct sway_container *container_view_destroy(struct sway_container *view) { 81void container_view_destroy(struct sway_container *view) {
82 if (!view) { 82 if (!view) {
83 return NULL; 83 return;
84 } 84 }
85 wlr_log(L_DEBUG, "Destroying view '%s'", view->name); 85 wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
86 struct sway_container *parent = container_destroy(view); 86 container_destroy(view);
87 arrange_windows(&root_container, -1, -1);
88 return parent;
89} 87}
90 88
91void view_damage_whole(struct sway_view *view) { 89void view_damage_whole(struct sway_view *view) {
@@ -164,6 +162,8 @@ void view_unmap(struct sway_view *view) {
164 162
165 view->swayc = NULL; 163 view->swayc = NULL;
166 view->surface = NULL; 164 view->surface = NULL;
165
166 arrange_windows(&root_container, -1, -1);
167} 167}
168 168
169void view_update_position(struct sway_view *view, double ox, double oy) { 169void view_update_position(struct sway_view *view, double ox, double oy) {