aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Ronan Pigott <rpigott@berkeley.edu>2020-11-01 23:43:07 -0700
committerLibravatar Tudor Brindus <me@tbrindus.ca>2020-12-20 00:58:42 -0500
commit8eb0c54693e44e7c6126ce35045e34ad0f4d4607 (patch)
treef70faa5d8d809591909881e992323d5439d7f21d /sway/tree/workspace.c
parentcommands/move: rework container_move_in_direction (diff)
downloadsway-8eb0c54693e44e7c6126ce35045e34ad0f4d4607.tar.gz
sway-8eb0c54693e44e7c6126ce35045e34ad0f4d4607.tar.zst
sway-8eb0c54693e44e7c6126ce35045e34ad0f4d4607.zip
introduce workspace_squash
workspace_squash is container_flatten in the reverse direction. Instead of eliminating redundant splits that are parents of the target container, it eliminates pairs of redundant H/V splits that are children of the workspace. Splits are redundant if a con and its grandchild have the same layout, and the immediate child has the opposite split. For example, layouts are transformed like: H[V[H[app1 app2]] app3] -> H[app1 app2 app3] i3 uses this operation to simplify the tree after moving heavily nested containers to a higher level in the tree via an orthogonal move.
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index e40792ae..62549434 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -714,14 +714,8 @@ void workspace_add_floating(struct sway_workspace *workspace,
714 node_set_dirty(&con->node); 714 node_set_dirty(&con->node);
715} 715}
716 716
717struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace, 717void workspace_insert_tiling_direct(struct sway_workspace *workspace,
718 struct sway_container *con, int index) { 718 struct sway_container *con, int index) {
719 if (con->workspace) {
720 container_detach(con);
721 }
722 if (config->default_layout != L_NONE) {
723 con = container_split(con, config->default_layout);
724 }
725 list_insert(workspace->tiling, index, con); 719 list_insert(workspace->tiling, index, con);
726 con->workspace = workspace; 720 con->workspace = workspace;
727 container_for_each_child(con, set_workspace, NULL); 721 container_for_each_child(con, set_workspace, NULL);
@@ -729,6 +723,17 @@ struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace,
729 workspace_update_representation(workspace); 723 workspace_update_representation(workspace);
730 node_set_dirty(&workspace->node); 724 node_set_dirty(&workspace->node);
731 node_set_dirty(&con->node); 725 node_set_dirty(&con->node);
726}
727
728struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace,
729 struct sway_container *con, int index) {
730 if (con->workspace) {
731 container_detach(con);
732 }
733 if (config->default_layout != L_NONE) {
734 con = container_split(con, config->default_layout);
735 }
736 workspace_insert_tiling_direct(workspace, con, index);
732 return con; 737 return con;
733} 738}
734 739
@@ -846,3 +851,10 @@ size_t workspace_num_sticky_containers(struct sway_workspace *ws) {
846 workspace_for_each_container(ws, count_sticky_containers, &count); 851 workspace_for_each_container(ws, count_sticky_containers, &count);
847 return count; 852 return count;
848} 853}
854
855void workspace_squash(struct sway_workspace *workspace) {
856 for (int i = 0; i < workspace->tiling->length; i++) {
857 struct sway_container *child = workspace->tiling->items[i];
858 i += container_squash(child);
859 }
860}