diff options
author | Brian Ashworth <[email protected]> | 2018-06-07 19:36:16 -0400 |
---|---|---|
committer | Brian Ashworth <[email protected]> | 2018-06-08 13:08:00 -0400 |
commit | 5c9a917df9453f0463040b1164ba639b430f7833 (patch) | |
tree | 581a2b3056df2625de3d6dbcbb970b20fff260cb /sway/tree/output.c | |
parent | c65c84444e58404f951c628221b7485da0684f19 (diff) |
Restore workspaces to outputs based on priority
Diffstat (limited to 'sway/tree/output.c')
-rw-r--r-- | sway/tree/output.c | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/sway/tree/output.c b/sway/tree/output.c index 8823eba0..1ab8bed2 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -1,11 +1,35 @@ #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_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; + } + + 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); + } +} + struct sway_container *output_create( struct sway_output *sway_output) { const char *name = sway_output->wlr_output->name; @@ -56,19 +80,24 @@ 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); + container_descendants(&root_container, C_WORKSPACE, restore_workspace, + 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; } |