From fc63ed440a3f8c52bb1c05458117d90a52edf872 Mon Sep 17 00:00:00 2001 From: Bonsaiiv Date: Wed, 7 Feb 2024 21:01:55 +0100 Subject: [PATCH 1/2] reduces redundant containers Applying layout changes to the parent of the parent, in case the parent only has a single child, stops the creation of a chain of single child containers. The way of doing is hacky but i have no idea, what i am doing. --- sway/commands/layout.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sway/commands/layout.c b/sway/commands/layout.c index 12ce48398..fab7f3ecb 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -134,6 +134,9 @@ struct cmd_results *cmd_layout(int argc, char **argv) { // Operate on parent container, like i3. if (container) { container = container->pending.parent; + if (container && container->pending.children->length == 1) { + container = container->pending.parent; + } } // We could be working with a container OR a workspace. These are different From 272d14f8eff460bc36017ea784fc22445a948619 Mon Sep 17 00:00:00 2001 From: Bonsaiiv Date: Wed, 7 Feb 2024 21:37:00 +0100 Subject: [PATCH 2/2] matches i3 behavior found the flatten function :) i just followed it; not used it, as that is, what i3 is doing too --- sway/commands/layout.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sway/commands/layout.c b/sway/commands/layout.c index fab7f3ecb..a32c908b8 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -134,8 +134,14 @@ struct cmd_results *cmd_layout(int argc, char **argv) { // Operate on parent container, like i3. if (container) { container = container->pending.parent; + // If parent has only a singe child operate on its parent and + // flatten once, like i3 if (container && container->pending.children->length == 1) { - container = container->pending.parent; + struct sway_container *child = container->pending.children->items[0]; + struct sway_container *parent = container->pending.parent; + container_replace(container, child); + container_begin_destroy(container); + container = parent; } }