diff options
Diffstat (limited to 'sway/tree/output.c')
-rw-r--r-- | sway/tree/output.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/sway/tree/output.c b/sway/tree/output.c index 8823eba0..ed7e941e 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -1,11 +1,39 @@ #define _POSIX_C_SOURCE 200809L #include <string.h> #include <strings.h> +#include "sway/ipc-server.h" #include "sway/output.h" +#include "sway/tree/arrange.h" #include "sway/tree/output.h" #include "sway/tree/workspace.h" #include "log.h" +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; + } + + 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--; + } + } + + arrange_output(other); + } + + container_sort_workspaces(output); + arrange_output(output); +} + struct sway_container *output_create( struct sway_output *sway_output) { const char *name = sway_output->wlr_output->name; @@ -56,19 +84,23 @@ struct sway_container *output_create( output->width = size.width; output->height = size.height; - // Create workspace - char *ws_name = workspace_next_name(output->name); - wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); - struct sway_container *ws = workspace_create(output, ws_name); - // Set each seat's focus if not already set - struct sway_seat *seat = NULL; - wl_list_for_each(seat, &input_manager->seats, link) { - if (!seat->has_focus) { - seat_set_focus(seat, ws); + restore_workspaces(output); + + if (!output->children->length) { + // Create workspace + char *ws_name = workspace_next_name(output->name); + wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); + struct sway_container *ws = workspace_create(output, ws_name); + // Set each seat's focus if not already set + struct sway_seat *seat = NULL; + wl_list_for_each(seat, &input_manager->seats, link) { + if (!seat->has_focus) { + seat_set_focus(seat, ws); + } } + free(ws_name); } - free(ws_name); container_create_notify(output); return output; } |