Skip to content

Commit e2b2fb0

Browse files
committed
Switch restore workspaces to a nested for-loop
1 parent 5c9a917 commit e2b2fb0

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

sway/tree/container.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,6 @@ void container_descendants(struct sway_container *root,
445445
func(item, data);
446446
}
447447
container_descendants(item, type, func, data);
448-
if (i < root->children->length && root->children->items[i] != item) {
449-
--i;
450-
}
451448
}
452449
}
453450

sway/tree/layout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ void container_move_to(struct sway_container *container,
184184
container_sort_workspaces(new_parent);
185185
seat_set_focus(seat, new_parent);
186186
workspace_output_raise_priority(container, old_parent, new_parent);
187+
ipc_event_workspace(container, NULL, "move");
187188
}
188189
container_notify_subtree_changed(old_parent);
189190
container_notify_subtree_changed(new_parent);

sway/tree/output.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,30 @@
88
#include "sway/tree/workspace.h"
99
#include "log.h"
1010

11-
static void restore_workspace(struct sway_container *ws, void *output) {
12-
if (ws->parent == output) {
13-
return;
14-
}
15-
16-
struct sway_container *highest = workspace_output_get_highest_available(
17-
ws, NULL);
18-
if (!highest) {
19-
return;
20-
}
11+
static void restore_workspaces(struct sway_container *output) {
12+
for (int i = 0; i < root_container.children->length; i++) {
13+
struct sway_container *other = root_container.children->items[i];
14+
if (other == output) {
15+
continue;
16+
}
2117

22-
if (highest == output) {
23-
struct sway_container *other = container_remove_child(ws);
24-
container_add_child(output, ws);
25-
ipc_event_workspace(ws, NULL, "move");
18+
for (int j = 0; j < other->children->length; j++) {
19+
struct sway_container *ws = other->children->items[j];
20+
struct sway_container *highest =
21+
workspace_output_get_highest_available(ws, NULL);
22+
if (highest == output) {
23+
container_remove_child(ws);
24+
container_add_child(output, ws);
25+
ipc_event_workspace(ws, NULL, "move");
26+
j--;
27+
}
28+
}
2629

27-
container_sort_workspaces(output);
28-
arrange_output(output);
2930
arrange_output(other);
3031
}
32+
33+
container_sort_workspaces(output);
34+
arrange_output(output);
3135
}
3236

3337
struct sway_container *output_create(
@@ -80,8 +84,7 @@ struct sway_container *output_create(
8084
output->width = size.width;
8185
output->height = size.height;
8286

83-
container_descendants(&root_container, C_WORKSPACE, restore_workspace,
84-
output);
87+
restore_workspaces(output);
8588

8689
if (!output->children->length) {
8790
// Create workspace

0 commit comments

Comments
 (0)