From 5c9a917df9453f0463040b1164ba639b430f7833 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 7 Jun 2018 19:36:16 -0400 Subject: Restore workspaces to outputs based on priority --- sway/tree/output.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'sway/tree/output.c') 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 #include +#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; } -- cgit v1.2.3 From e2b2fb0a0e3e7db3046aeef485621ff3f490cd61 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Fri, 8 Jun 2018 13:06:29 -0400 Subject: Switch restore workspaces to a nested for-loop --- sway/tree/output.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'sway/tree/output.c') diff --git a/sway/tree/output.c b/sway/tree/output.c index 1ab8bed2..ed7e941e 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -8,26 +8,30 @@ #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; - } +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; + } - if (highest == output) { - struct sway_container *other = container_remove_child(ws); - container_add_child(output, ws); - ipc_event_workspace(ws, NULL, "move"); + 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--; + } + } - container_sort_workspaces(output); - arrange_output(output); arrange_output(other); } + + container_sort_workspaces(output); + arrange_output(output); } struct sway_container *output_create( @@ -80,8 +84,7 @@ struct sway_container *output_create( output->width = size.width; output->height = size.height; - container_descendants(&root_container, C_WORKSPACE, restore_workspace, - output); + restore_workspaces(output); if (!output->children->length) { // Create workspace -- cgit v1.2.3