From 5c9a917df9453f0463040b1164ba639b430f7833 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 7 Jun 2018 19:36:16 -0400 Subject: Restore workspaces to outputs based on priority --- sway/tree/container.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'sway/tree/container.c') diff --git a/sway/tree/container.c b/sway/tree/container.c index ca993c41..f36820b3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -213,6 +213,9 @@ static struct sway_container *container_workspace_destroy( sway_workspace->floating->parent = NULL; _container_destroy(sway_workspace->floating); + list_foreach(sway_workspace->output_priority, free); + list_free(sway_workspace->output_priority); + free(sway_workspace); if (output) { @@ -234,24 +237,33 @@ static struct sway_container *container_output_destroy( // program if (root_container.children->length > 1) { // Move workspace from this output to another output - struct sway_container *other_output = + struct sway_container *fallback_output = root_container.children->items[0]; - if (other_output == output) { - other_output = root_container.children->items[1]; + if (fallback_output == output) { + fallback_output = root_container.children->items[1]; } while (output->children->length) { struct sway_container *workspace = output->children->items[0]; + + struct sway_container *new_output = + workspace_output_get_highest_available(workspace, output); + if (!new_output) { + new_output = fallback_output; + workspace_output_add_priority(workspace, new_output); + } + container_remove_child(workspace); - if (workspace->children->length > 0) { - container_add_child(other_output, workspace); + if (!workspace_is_empty(workspace)) { + container_add_child(new_output, workspace); ipc_event_workspace(workspace, NULL, "move"); } else { container_workspace_destroy(workspace); } + + container_sort_workspaces(new_output); + arrange_output(new_output); } - container_sort_workspaces(other_output); - arrange_output(other_output); } } @@ -433,6 +445,9 @@ void container_descendants(struct sway_container *root, func(item, data); } container_descendants(item, type, func, data); + if (i < root->children->length && root->children->items[i] != item) { + --i; + } } } -- cgit v1.2.3-54-g00ecf From e2b2fb0a0e3e7db3046aeef485621ff3f490cd61 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Fri, 8 Jun 2018 13:06:29 -0400 Subject: Switch restore workspaces to a nested for-loop --- sway/tree/container.c | 3 --- sway/tree/layout.c | 1 + sway/tree/output.c | 39 +++++++++++++++++++++------------------ 3 files changed, 22 insertions(+), 21 deletions(-) (limited to 'sway/tree/container.c') diff --git a/sway/tree/container.c b/sway/tree/container.c index f36820b3..cd2c083c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -445,9 +445,6 @@ void container_descendants(struct sway_container *root, func(item, data); } container_descendants(item, type, func, data); - if (i < root->children->length && root->children->items[i] != item) { - --i; - } } } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index fc17d8c3..6d4cd088 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -184,6 +184,7 @@ void container_move_to(struct sway_container *container, container_sort_workspaces(new_parent); seat_set_focus(seat, new_parent); workspace_output_raise_priority(container, old_parent, new_parent); + ipc_event_workspace(container, NULL, "move"); } container_notify_subtree_changed(old_parent); container_notify_subtree_changed(new_parent); diff --git a/sway/tree/output.c b/sway/tree/output.c index 1ab8bed2..ed7e941e 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -8,26 +8,30 @@ #include "sway/tree/workspace.h" #include "log.h" -static void restore_workspace(struct sway_container *ws, void *output) { - if (ws->parent == output) { - return; - } - - struct sway_container *highest = workspace_output_get_highest_available( - ws, NULL); - if (!highest) { - return; - } +static void restore_workspaces(struct sway_container *output) { + for (int i = 0; i < root_container.children->length; i++) { + struct sway_container *other = root_container.children->items[i]; + if (other == output) { + continue; + } - if (highest == output) { - struct sway_container *other = container_remove_child(ws); - container_add_child(output, ws); - ipc_event_workspace(ws, NULL, "move"); + for (int j = 0; j < other->children->length; j++) { + struct sway_container *ws = other->children->items[j]; + struct sway_container *highest = + workspace_output_get_highest_available(ws, NULL); + if (highest == output) { + container_remove_child(ws); + container_add_child(output, ws); + ipc_event_workspace(ws, NULL, "move"); + j--; + } + } - container_sort_workspaces(output); - arrange_output(output); arrange_output(other); } + + container_sort_workspaces(output); + arrange_output(output); } struct sway_container *output_create( @@ -80,8 +84,7 @@ struct sway_container *output_create( output->width = size.width; output->height = size.height; - container_descendants(&root_container, C_WORKSPACE, restore_workspace, - output); + restore_workspaces(output); if (!output->children->length) { // Create workspace -- cgit v1.2.3-54-g00ecf