From 8eb0c54693e44e7c6126ce35045e34ad0f4d4607 Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Sun, 1 Nov 2020 23:43:07 -0700 Subject: 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. --- include/sway/tree/container.h | 13 +++++++++++++ include/sway/tree/workspace.h | 15 +++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'include/sway') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index c9290108..7e9df59f 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -374,4 +374,17 @@ bool container_is_sticky(struct sway_container *con); bool container_is_sticky_or_child(struct sway_container *con); +/** + * This will destroy pairs of redundant H/V splits + * e.g. H[V[H[app app]] app] -> H[app app app] + * The middle "V[H[" are eliminated by a call to container_squash + * on the V[ con. It's grandchildren are added to it's parent. + * + * This function is roughly equivalent to i3's tree_flatten here: + * https://github.com/i3/i3/blob/1f0c628cde40cf87371481041b7197344e0417c6/src/tree.c#L651 + * + * Returns the number of new containers added to the parent + */ +int container_squash(struct sway_container *con); + #endif diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 3c9f93ed..fdd92f64 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -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 -- cgit v1.2.3