aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-06-07 19:36:16 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-06-08 13:08:00 -0400
commit5c9a917df9453f0463040b1164ba639b430f7833 (patch)
tree581a2b3056df2625de3d6dbcbb970b20fff260cb /sway/tree/container.c
parentMerge pull request #2121 from martinetd/swaylock-ctrl-u (diff)
downloadsway-5c9a917df9453f0463040b1164ba639b430f7833.tar.gz
sway-5c9a917df9453f0463040b1164ba639b430f7833.tar.zst
sway-5c9a917df9453f0463040b1164ba639b430f7833.zip
Restore workspaces to outputs based on priority
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index ca993c41..f36820b3 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -213,6 +213,9 @@ static struct sway_container *container_workspace_destroy(
213 sway_workspace->floating->parent = NULL; 213 sway_workspace->floating->parent = NULL;
214 _container_destroy(sway_workspace->floating); 214 _container_destroy(sway_workspace->floating);
215 215
216 list_foreach(sway_workspace->output_priority, free);
217 list_free(sway_workspace->output_priority);
218
216 free(sway_workspace); 219 free(sway_workspace);
217 220
218 if (output) { 221 if (output) {
@@ -234,24 +237,33 @@ static struct sway_container *container_output_destroy(
234 // program 237 // program
235 if (root_container.children->length > 1) { 238 if (root_container.children->length > 1) {
236 // Move workspace from this output to another output 239 // Move workspace from this output to another output
237 struct sway_container *other_output = 240 struct sway_container *fallback_output =
238 root_container.children->items[0]; 241 root_container.children->items[0];
239 if (other_output == output) { 242 if (fallback_output == output) {
240 other_output = root_container.children->items[1]; 243 fallback_output = root_container.children->items[1];
241 } 244 }
242 245
243 while (output->children->length) { 246 while (output->children->length) {
244 struct sway_container *workspace = output->children->items[0]; 247 struct sway_container *workspace = output->children->items[0];
248
249 struct sway_container *new_output =
250 workspace_output_get_highest_available(workspace, output);
251 if (!new_output) {
252 new_output = fallback_output;
253 workspace_output_add_priority(workspace, new_output);
254 }
255
245 container_remove_child(workspace); 256 container_remove_child(workspace);
246 if (workspace->children->length > 0) { 257 if (!workspace_is_empty(workspace)) {
247 container_add_child(other_output, workspace); 258 container_add_child(new_output, workspace);
248 ipc_event_workspace(workspace, NULL, "move"); 259 ipc_event_workspace(workspace, NULL, "move");
249 } else { 260 } else {
250 container_workspace_destroy(workspace); 261 container_workspace_destroy(workspace);
251 } 262 }
263
264 container_sort_workspaces(new_output);
265 arrange_output(new_output);
252 } 266 }
253 container_sort_workspaces(other_output);
254 arrange_output(other_output);
255 } 267 }
256 } 268 }
257 269
@@ -433,6 +445,9 @@ void container_descendants(struct sway_container *root,
433 func(item, data); 445 func(item, data);
434 } 446 }
435 container_descendants(item, type, func, data); 447 container_descendants(item, type, func, data);
448 if (i < root->children->length && root->children->items[i] != item) {
449 --i;
450 }
436 } 451 }
437} 452}
438 453