Switch restore workspaces to a nested for-loop

This commit is contained in:
Brian Ashworth 2018-06-08 13:06:29 -04:00
parent 5c9a917df9
commit e2b2fb0a0e
3 changed files with 22 additions and 21 deletions

View file

@ -445,9 +445,6 @@ void container_descendants(struct sway_container *root,
func(item, data); func(item, data);
} }
container_descendants(item, type, func, data); container_descendants(item, type, func, data);
if (i < root->children->length && root->children->items[i] != item) {
--i;
}
} }
} }

View file

@ -184,6 +184,7 @@ void container_move_to(struct sway_container *container,
container_sort_workspaces(new_parent); container_sort_workspaces(new_parent);
seat_set_focus(seat, new_parent); seat_set_focus(seat, new_parent);
workspace_output_raise_priority(container, old_parent, 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(old_parent);
container_notify_subtree_changed(new_parent); container_notify_subtree_changed(new_parent);

View file

@ -8,26 +8,30 @@
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
#include "log.h" #include "log.h"
static void restore_workspace(struct sway_container *ws, void *output) { static void restore_workspaces(struct sway_container *output) {
if (ws->parent == output) { for (int i = 0; i < root_container.children->length; i++) {
return; struct sway_container *other = root_container.children->items[i];
} if (other == output) {
continue;
}
struct sway_container *highest = workspace_output_get_highest_available( for (int j = 0; j < other->children->length; j++) {
ws, NULL); struct sway_container *ws = other->children->items[j];
if (!highest) { struct sway_container *highest =
return; 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--;
}
}
if (highest == output) {
struct sway_container *other = container_remove_child(ws);
container_add_child(output, ws);
ipc_event_workspace(ws, NULL, "move");
container_sort_workspaces(output);
arrange_output(output);
arrange_output(other); arrange_output(other);
} }
container_sort_workspaces(output);
arrange_output(output);
} }
struct sway_container *output_create( struct sway_container *output_create(
@ -80,8 +84,7 @@ struct sway_container *output_create(
output->width = size.width; output->width = size.width;
output->height = size.height; output->height = size.height;
container_descendants(&root_container, C_WORKSPACE, restore_workspace, restore_workspaces(output);
output);
if (!output->children->length) { if (!output->children->length) {
// Create workspace // Create workspace