diff options
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 2eac812e..ed39a154 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -58,7 +58,7 @@ static struct sway_container *container_create(enum sway_container_type type) { | |||
58 | return c; | 58 | return c; |
59 | } | 59 | } |
60 | 60 | ||
61 | static void container_destroy(struct sway_container *cont) { | 61 | void container_destroy(struct sway_container *cont) { |
62 | if (cont == NULL) { | 62 | if (cont == NULL) { |
63 | return; | 63 | return; |
64 | } | 64 | } |
@@ -203,8 +203,7 @@ struct sway_container *container_view_create(struct sway_container *sibling, | |||
203 | } | 203 | } |
204 | 204 | ||
205 | struct sway_container *container_output_destroy(struct sway_container *output) { | 205 | struct sway_container *container_output_destroy(struct sway_container *output) { |
206 | if (!sway_assert(output, | 206 | if (!sway_assert(output, "cannot destroy null output")) { |
207 | "null output passed to container_output_destroy")) { | ||
208 | return NULL; | 207 | return NULL; |
209 | } | 208 | } |
210 | 209 | ||
@@ -236,6 +235,45 @@ struct sway_container *container_output_destroy(struct sway_container *output) { | |||
236 | return &root_container; | 235 | return &root_container; |
237 | } | 236 | } |
238 | 237 | ||
238 | struct sway_container *container_workspace_destroy( | ||
239 | struct sway_container *workspace) { | ||
240 | if (!sway_assert(workspace, "cannot destroy null workspace")) { | ||
241 | return NULL; | ||
242 | } | ||
243 | |||
244 | // Do not destroy this if it's the last workspace on this output | ||
245 | struct sway_container *output = container_parent(workspace, C_OUTPUT); | ||
246 | if (output && output->children->length == 1) { | ||
247 | return NULL; | ||
248 | } | ||
249 | |||
250 | struct sway_container *parent = workspace->parent; | ||
251 | if (workspace->children->length == 0) { | ||
252 | // destroy the WS if there are no children (TODO check for floating) | ||
253 | wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); | ||
254 | ipc_event_workspace(workspace, NULL, "empty"); | ||
255 | } else { | ||
256 | // Move children to a different workspace on this output | ||
257 | struct sway_container *new_workspace = NULL; | ||
258 | // TODO move floating | ||
259 | for (int i = 0; i < output->children->length; i++) { | ||
260 | if (output->children->items[i] != workspace) { | ||
261 | new_workspace = output->children->items[i]; | ||
262 | break; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | wlr_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'", | ||
267 | workspace->name, new_workspace->name); | ||
268 | for (int i = 0; i < workspace->children->length; i++) { | ||
269 | container_move_to(workspace->children->items[i], new_workspace); | ||
270 | } | ||
271 | } | ||
272 | |||
273 | container_destroy(workspace); | ||
274 | return parent; | ||
275 | } | ||
276 | |||
239 | struct sway_container *container_view_destroy(struct sway_container *view) { | 277 | struct sway_container *container_view_destroy(struct sway_container *view) { |
240 | if (!view) { | 278 | if (!view) { |
241 | return NULL; | 279 | return NULL; |
@@ -438,3 +476,14 @@ void container_for_each_descendant_bfs(struct sway_container *con, | |||
438 | list_cat(queue, current->children); | 476 | list_cat(queue, current->children); |
439 | } | 477 | } |
440 | } | 478 | } |
479 | |||
480 | bool container_has_anscestor(struct sway_container *descendant, | ||
481 | struct sway_container *anscestor) { | ||
482 | while (descendant->type != C_ROOT) { | ||
483 | descendant = descendant->parent; | ||
484 | if (descendant == anscestor) { | ||
485 | return true; | ||
486 | } | ||
487 | } | ||
488 | return false; | ||
489 | } | ||