diff options
-rw-r--r-- | sway/container.c | 34 | ||||
-rw-r--r-- | sway/focus.c | 6 |
2 files changed, 31 insertions, 9 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) { | |||
323 | if (!ASSERT_NONNULL(workspace)) { | 323 | if (!ASSERT_NONNULL(workspace)) { |
324 | return NULL; | 324 | return NULL; |
325 | } | 325 | } |
326 | // NOTE: This is called from elsewhere without checking children length | ||
327 | // TODO move containers to other workspaces? | ||
328 | // for now just dont delete | ||
329 | 326 | ||
330 | // Do not destroy this if it's the last workspace on this output | 327 | // Do not destroy this if it's the last workspace on this output |
331 | swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); | 328 | swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); |
@@ -333,14 +330,35 @@ swayc_t *destroy_workspace(swayc_t *workspace) { | |||
333 | return NULL; | 330 | return NULL; |
334 | } | 331 | } |
335 | 332 | ||
336 | // Do not destroy if there are children | 333 | swayc_t *parent = workspace->parent; |
334 | // destroy the WS if there are no children | ||
337 | if (workspace->children->length == 0 && workspace->floating->length == 0) { | 335 | if (workspace->children->length == 0 && workspace->floating->length == 0) { |
338 | sway_log(L_DEBUG, "destroying workspace '%s'", workspace->name); | 336 | sway_log(L_DEBUG, "destroying workspace '%s'", workspace->name); |
339 | swayc_t *parent = workspace->parent; | 337 | } else { |
340 | free_swayc(workspace); | 338 | // Move children to a different workspace on this output |
341 | return parent; | 339 | swayc_t *new_workspace = NULL; |
340 | int i; | ||
341 | for(i = 0; i < output->children->length; i++) { | ||
342 | if(output->children->items[i] != workspace) { | ||
343 | break; | ||
344 | } | ||
345 | } | ||
346 | new_workspace = output->children->items[i]; | ||
347 | |||
348 | sway_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'", | ||
349 | workspace->name, new_workspace->name); | ||
350 | |||
351 | for(i = 0; i < workspace->children->length; i++) { | ||
352 | move_container_to(workspace->children->items[i], new_workspace); | ||
353 | } | ||
354 | |||
355 | for(i = 0; i < workspace->floating->length; i++) { | ||
356 | move_container_to(workspace->floating->items[i], new_workspace); | ||
357 | } | ||
342 | } | 358 | } |
343 | return NULL; | 359 | |
360 | free_swayc(workspace); | ||
361 | return parent; | ||
344 | } | 362 | } |
345 | 363 | ||
346 | swayc_t *destroy_container(swayc_t *container) { | 364 | swayc_t *destroy_container(swayc_t *container) { |
diff --git a/sway/focus.c b/sway/focus.c index 9f070866..ca56de4b 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -37,7 +37,11 @@ static void update_focus(swayc_t *c) { | |||
37 | ipc_event_workspace(prev, c); | 37 | ipc_event_workspace(prev, c); |
38 | // update visibility of old workspace | 38 | // update visibility of old workspace |
39 | update_visibility(prev); | 39 | update_visibility(prev); |
40 | destroy_workspace(prev); | 40 | |
41 | // if the old workspace has no children, destroy it | ||
42 | if(prev->children->length == 0 && prev->floating->length == 0){ | ||
43 | destroy_workspace(prev); | ||
44 | } | ||
41 | } | 45 | } |
42 | // Update visibility of newly focused workspace | 46 | // Update visibility of newly focused workspace |
43 | update_visibility(c); | 47 | update_visibility(c); |