|
1 | 1 | #define _POSIX_C_SOURCE 200809L |
2 | 2 | #include <string.h> |
3 | 3 | #include <strings.h> |
| 4 | +#include "sway/ipc-server.h" |
4 | 5 | #include "sway/output.h" |
| 6 | +#include "sway/tree/arrange.h" |
5 | 7 | #include "sway/tree/output.h" |
6 | 8 | #include "sway/tree/workspace.h" |
7 | 9 | #include "log.h" |
8 | 10 |
|
| 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 | + } |
| 17 | + |
| 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 | + } |
| 29 | + |
| 30 | + arrange_output(other); |
| 31 | + } |
| 32 | + |
| 33 | + container_sort_workspaces(output); |
| 34 | + arrange_output(output); |
| 35 | +} |
| 36 | + |
9 | 37 | struct sway_container *output_create( |
10 | 38 | struct sway_output *sway_output) { |
11 | 39 | const char *name = sway_output->wlr_output->name; |
@@ -56,19 +84,23 @@ struct sway_container *output_create( |
56 | 84 | output->width = size.width; |
57 | 85 | output->height = size.height; |
58 | 86 |
|
59 | | - // Create workspace |
60 | | - char *ws_name = workspace_next_name(output->name); |
61 | | - wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); |
62 | | - struct sway_container *ws = workspace_create(output, ws_name); |
63 | | - // Set each seat's focus if not already set |
64 | | - struct sway_seat *seat = NULL; |
65 | | - wl_list_for_each(seat, &input_manager->seats, link) { |
66 | | - if (!seat->has_focus) { |
67 | | - seat_set_focus(seat, ws); |
| 87 | + restore_workspaces(output); |
| 88 | + |
| 89 | + if (!output->children->length) { |
| 90 | + // Create workspace |
| 91 | + char *ws_name = workspace_next_name(output->name); |
| 92 | + wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); |
| 93 | + struct sway_container *ws = workspace_create(output, ws_name); |
| 94 | + // Set each seat's focus if not already set |
| 95 | + struct sway_seat *seat = NULL; |
| 96 | + wl_list_for_each(seat, &input_manager->seats, link) { |
| 97 | + if (!seat->has_focus) { |
| 98 | + seat_set_focus(seat, ws); |
| 99 | + } |
68 | 100 | } |
| 101 | + free(ws_name); |
69 | 102 | } |
70 | 103 |
|
71 | | - free(ws_name); |
72 | 104 | container_create_notify(output); |
73 | 105 | return output; |
74 | 106 | } |
|
0 commit comments