diff options
author | Kevin Hamacher <kevin.hamacher@rub.de> | 2015-12-13 18:19:24 +0100 |
---|---|---|
committer | Kevin Hamacher <kevin.hamacher@rub.de> | 2015-12-13 18:19:24 +0100 |
commit | d77d03ce8419f83553d322eb5dd08412a45b7bb3 (patch) | |
tree | 19bf02314f732916aeb78d422877f7706e75d82e /sway/container.c | |
parent | 6596582bc381d371f0e355d61595b2b87b5ee821 (diff) |
Make destroy_workspace behave as expected
Diffstat (limited to 'sway/container.c')
-rw-r--r-- | sway/container.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/sway/container.c b/sway/container.c index c260e01a..a40c483c 100644 --- a/sway/container.c +++ b/sway/container.c @@ -323,9 +323,6 @@ swayc_t *destroy_workspace(swayc_t *workspace) { if (!ASSERT_NONNULL(workspace)) { return NULL; } - // NOTE: This is called from elsewhere without checking children length - // TODO move containers to other workspaces? - // for now just dont delete // Do not destroy this if it's the last workspace on this output swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); @@ -333,14 +330,35 @@ swayc_t *destroy_workspace(swayc_t *workspace) { return NULL; } - // Do not destroy if there are children + swayc_t *parent = workspace->parent; + // destroy the WS if there are no children if (workspace->children->length == 0 && workspace->floating->length == 0) { sway_log(L_DEBUG, "destroying workspace '%s'", workspace->name); - swayc_t *parent = workspace->parent; - free_swayc(workspace); - return parent; + } else { + // Move children to a different workspace on this output + swayc_t *new_workspace = NULL; + int i; + for(i = 0; i < output->children->length; i++) { + if(output->children->items[i] != workspace) { + break; + } + } + new_workspace = output->children->items[i]; + + sway_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'", + workspace->name, new_workspace->name); + + for(i = 0; i < workspace->children->length; i++) { + move_container_to(workspace->children->items[i], new_workspace); + } + + for(i = 0; i < workspace->floating->length; i++) { + move_container_to(workspace->floating->items[i], new_workspace); + } } - return NULL; + + free_swayc(workspace); + return parent; } swayc_t *destroy_container(swayc_t *container) { |