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:
Ronan Pigott 2020-11-01 23:43:07 -07:00 committed by Tudor Brindus
parent e95c299f0a
commit 8eb0c54693
4 changed files with 109 additions and 7 deletions

View file

@ -116,6 +116,13 @@ struct sway_container *workspace_add_tiling(struct sway_workspace *workspace,
void workspace_add_floating(struct sway_workspace *workspace,
struct sway_container *con);
/**
* Adds a tiling container to the workspace without considering
* the workspace_layout, so the con will not be split.
*/
void workspace_insert_tiling_direct(struct sway_workspace *workspace,
struct sway_container *con, int index);
struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace,
struct sway_container *con, int index);
@ -134,4 +141,12 @@ size_t workspace_num_tiling_views(struct sway_workspace *ws);
size_t workspace_num_sticky_containers(struct sway_workspace *ws);
/**
* 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.
*/
void workspace_squash(struct sway_workspace *workspace);
#endif