aboutsummaryrefslogtreecommitdiff
path: root/sway/tree/output.c
diff options
context:
space:
mode:
authorRyan Dwyer <RyanDwyer@users.noreply.github.com>2018-06-09 08:43:57 +1000
committerGitHub <noreply@github.com>2018-06-09 08:43:57 +1000
commit0b798ed9543d55bd39782c3a4a4bc1789acd40d3 (patch)
tree1ef7bdd44c5b7684e2c5e7118d5b7ffdda1e4ba6 /sway/tree/output.c
parentc65c84444e58404f951c628221b7485da0684f19 (diff)
parente2b2fb0a0e3e7db3046aeef485621ff3f490cd61 (diff)
Merge pull request #2115 from RedSoxFan/restore-workspaces
Restore workspaces to output when re-enabled
Diffstat (limited to 'sway/tree/output.c')
-rw-r--r--sway/tree/output.c52
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;
}