mirror of
https://github.com/swaywm/sway.git
synced 2026-04-17 06:46:32 -04:00
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.
This commit is contained in:
parent
e95c299f0a
commit
8eb0c54693
4 changed files with 109 additions and 7 deletions
|
|
@ -714,6 +714,17 @@ void workspace_add_floating(struct sway_workspace *workspace,
|
|||
node_set_dirty(&con->node);
|
||||
}
|
||||
|
||||
void workspace_insert_tiling_direct(struct sway_workspace *workspace,
|
||||
struct sway_container *con, int index) {
|
||||
list_insert(workspace->tiling, index, con);
|
||||
con->workspace = workspace;
|
||||
container_for_each_child(con, set_workspace, NULL);
|
||||
container_handle_fullscreen_reparent(con);
|
||||
workspace_update_representation(workspace);
|
||||
node_set_dirty(&workspace->node);
|
||||
node_set_dirty(&con->node);
|
||||
}
|
||||
|
||||
struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace,
|
||||
struct sway_container *con, int index) {
|
||||
if (con->workspace) {
|
||||
|
|
@ -722,13 +733,7 @@ struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace,
|
|||
if (config->default_layout != L_NONE) {
|
||||
con = container_split(con, config->default_layout);
|
||||
}
|
||||
list_insert(workspace->tiling, index, con);
|
||||
con->workspace = workspace;
|
||||
container_for_each_child(con, set_workspace, NULL);
|
||||
container_handle_fullscreen_reparent(con);
|
||||
workspace_update_representation(workspace);
|
||||
node_set_dirty(&workspace->node);
|
||||
node_set_dirty(&con->node);
|
||||
workspace_insert_tiling_direct(workspace, con, index);
|
||||
return con;
|
||||
}
|
||||
|
||||
|
|
@ -846,3 +851,10 @@ size_t workspace_num_sticky_containers(struct sway_workspace *ws) {
|
|||
workspace_for_each_container(ws, count_sticky_containers, &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
void workspace_squash(struct sway_workspace *workspace) {
|
||||
for (int i = 0; i < workspace->tiling->length; i++) {
|
||||
struct sway_container *child = workspace->tiling->items[i];
|
||||
i += container_squash(child);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue