diff options
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index ab8363bc..ea1c93bb 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -208,7 +208,7 @@ static void container_root_finish(struct sway_container *con) { | |||
208 | wlr_log(L_ERROR, "TODO: destroy the root container"); | 208 | wlr_log(L_ERROR, "TODO: destroy the root container"); |
209 | } | 209 | } |
210 | 210 | ||
211 | static bool container_reap_empty(struct sway_container *con) { | 211 | bool container_reap_empty(struct sway_container *con) { |
212 | switch (con->type) { | 212 | switch (con->type) { |
213 | case C_ROOT: | 213 | case C_ROOT: |
214 | case C_OUTPUT: | 214 | case C_OUTPUT: |
@@ -225,14 +225,6 @@ static bool container_reap_empty(struct sway_container *con) { | |||
225 | if (con->children->length == 0) { | 225 | if (con->children->length == 0) { |
226 | _container_destroy(con); | 226 | _container_destroy(con); |
227 | return true; | 227 | return true; |
228 | } else if (con->children->length == 1) { | ||
229 | struct sway_container *child = con->children->items[0]; | ||
230 | if (child->type == C_CONTAINER) { | ||
231 | container_remove_child(child); | ||
232 | container_replace_child(con, child); | ||
233 | _container_destroy(con); | ||
234 | return true; | ||
235 | } | ||
236 | } | 228 | } |
237 | case C_VIEW: | 229 | case C_VIEW: |
238 | break; | 230 | break; |
@@ -245,6 +237,29 @@ static bool container_reap_empty(struct sway_container *con) { | |||
245 | return false; | 237 | return false; |
246 | } | 238 | } |
247 | 239 | ||
240 | struct sway_container *container_reap_empty_recursive( | ||
241 | struct sway_container *con) { | ||
242 | while (con) { | ||
243 | struct sway_container *next = con->parent; | ||
244 | if (!container_reap_empty(con)) { | ||
245 | break; | ||
246 | } | ||
247 | con = next; | ||
248 | } | ||
249 | return con; | ||
250 | } | ||
251 | |||
252 | struct sway_container *container_flatten(struct sway_container *container) { | ||
253 | while (container->type == C_CONTAINER && container->children->length == 1) { | ||
254 | struct sway_container *child = container->children->items[0]; | ||
255 | struct sway_container *parent = container->parent; | ||
256 | container_replace_child(container, child); | ||
257 | container_destroy(container); | ||
258 | container = parent; | ||
259 | } | ||
260 | return container; | ||
261 | } | ||
262 | |||
248 | struct sway_container *container_destroy(struct sway_container *con) { | 263 | struct sway_container *container_destroy(struct sway_container *con) { |
249 | if (con == NULL) { | 264 | if (con == NULL) { |
250 | return NULL; | 265 | return NULL; |
@@ -283,18 +298,7 @@ struct sway_container *container_destroy(struct sway_container *con) { | |||
283 | break; | 298 | break; |
284 | } | 299 | } |
285 | 300 | ||
286 | struct sway_container *tmp = parent; | 301 | return container_reap_empty_recursive(parent); |
287 | while (parent) { | ||
288 | tmp = parent->parent; | ||
289 | |||
290 | if (!container_reap_empty(parent)) { | ||
291 | break; | ||
292 | } | ||
293 | |||
294 | parent = tmp; | ||
295 | } | ||
296 | |||
297 | return tmp; | ||
298 | } | 302 | } |
299 | 303 | ||
300 | static void container_close_func(struct sway_container *container, void *data) { | 304 | static void container_close_func(struct sway_container *container, void *data) { |