Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specific sequences may cause sway to "leak" containers, potentially leading to unnecessary deep nesting in the representation hierarchy #6116

Open
oranenj opened this issue Mar 19, 2021 · 6 comments
Labels
bug Not working as intended layout

Comments

@oranenj
Copy link
Contributor

oranenj commented Mar 19, 2021

Using sway 1.6rc1.

Related to #6115
I used my terminal to reproduce because it's easy to open new ones, but I suspect this will happen with any window.

$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": null
}
$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": "H[gnome-terminal-server gnome-terminal-server]"
}
# here we have the lone horizontal container that is not needed.
$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": "V[H[gnome-terminal-server] gnome-terminal-server]"
}
$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": "V[H[gnome-terminal-server] gnome-terminal-server gnome-terminal-server]"
}
$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": "H[V[H[gnome-terminal-server] gnome-terminal-server] gnome-terminal-server]"
}
$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": "H[V[H[gnome-terminal-server]] gnome-terminal-server]"
}
# and these are definitely even less necessary:
$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": "H[V[H[gnome-terminal-server]]]"
}
$ swaymsg -t get_workspaces --raw | jq '.[] | {num: .num, r: .representation} | select(.num==11)'
{
  "num": 11,
  "r": "H[]"
}

And the steps to reproduce:
0. start with a completely fresh workspace

  1. open two windows side-by-side
  2. move the second window from horizontal split to vertical (shift-mod-h)
  3. Open another window
  4. Now move the bottom one to the right (shift-mod-l)
  5. close the left bottom one. You should be left with two windows in a horizontal split, but the representation says H[V[H[gnome-terminal-server]] gnome-terminal-server]
  6. If you close all windows, there will be a container "left over"

Apparently some sequences of opening and closing windows can result in arbitrarily deep nesting, causing #6115

@oranenj oranenj added the bug Not working as intended label Mar 19, 2021
@oranenj
Copy link
Contributor Author

oranenj commented Mar 19, 2021

Something like this seems to fix this

+++ b/sway/tree/container.c
@@ -1705,10 +1705,12 @@ static bool is_parallel(enum sway_container_layout first,
 static bool container_is_squashable(struct sway_container *con,
                struct sway_container *child) {
        enum sway_container_layout gp_layout = container_parent_layout(con);
-       return (con->pending.layout == L_HORIZ || con->pending.layout == L_VERT) &&
+       // if we have only one grandchild, we can always squash it
+       return (child->pending.children && (child->pending.children->length == 1)) ||
+               ((con->pending.layout == L_HORIZ || con->pending.layout == L_VERT) &&
                (child->pending.layout == L_HORIZ || child->pending.layout == L_VERT) &&
                !is_parallel(con->pending.layout, child->pending.layout) &&
-               is_parallel(gp_layout, child->pending.layout);
+               is_parallel(gp_layout, child->pending.layout));
 }

Didn't manage to crash anything, though I need to test more with stacked and tabbed layouts.

oranenj pushed a commit to oranenj/sway that referenced this issue Mar 21, 2021
Fixes swaywm#6116. With the previous logic, it was possible to accumulate
redundant containers, potentiall causing arbitrarily deep nesting.
@Xyene Xyene added the layout label Mar 30, 2021
@camoz
Copy link

camoz commented Jul 28, 2021

Having a similar issue and I think it's the same.

Steps to reproduce using sway 1.6.1 with default config:

0. start with a completely fresh workspace
1. open two windows side-by-side, results in H[termite termite]
2. press $mod+w to change layout to tabbed, results in H[T[termite termite]]
3. press $mod+e to change layout back to tiled, results in H[H[termite termite]]

Also weird:

0. start with a completely fresh workspace
1. press $mod+w to change layout to tabbed, results in T[]
2. open two windows side-by-side, results in T[termite termite]
3. press $mod+e to change layout to tabbed, results in T[H[termite termite]] (here the tiled parent container is even visually present)

I would expect the tree in step 3 to be H[termite termite] and T[termite termite], respectively.

@ammgws
Copy link
Contributor

ammgws commented Oct 16, 2021

I believe I am experiencing this too, possibly due to the autotiling script I'm using.
When the nesting gets too deep even swaymsg -t get_tree fails. (Related: #6611)

Example JSON which causes swaymsg to fail:

{
    "id": 1,
    "type": "root",
    "orientation": "horizontal",
    "percent": null,
    "urgent": false,
    "marks": [],
    "focused": false,
    "layout": "splith",
    "border": "none",
    "current_border_width": 0,
    "rect": {
        "x": 0,
        "y": 0,
        "width": 3840,
        "height": 1080
    },
    "deco_rect": {
        "x": 0,
        "y": 0,
        "width": 0,
        "height": 0
    },
    "window_rect": {
        "x": 0,
        "y": 0,
        "width": 0,
        "height": 0
    },
    "geometry": {
        "x": 0,
        "y": 0,
        "width": 0,
        "height": 0
    },
    "name": "root",
    "window": null,
    "nodes": [
        {
            "id": 2147483647,
            "type": "output",
            "orientation": "horizontal",
            "percent": null,
            "urgent": false,
            "marks": [],
            "focused": false,
            "layout": "output",
            "border": "none",
            "current_border_width": 0,
            "rect": {
                "x": 0,
                "y": 0,
                "width": 3840,
                "height": 1080
            },
            "deco_rect": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "window_rect": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "geometry": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "name": "__i3",
            "window": null,
            "nodes": [
                {
                    "id": 2147483646,
                    "type": "workspace",
                    "orientation": "horizontal",
                    "percent": null,
                    "urgent": false,
                    "marks": [],
                    "focused": false,
                    "layout": "splith",
                    "border": "none",
                    "current_border_width": 0,
                    "rect": {
                        "x": 0,
                        "y": 0,
                        "width": 3840,
                        "height": 1080
                    },
                    "deco_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "window_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "geometry": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "name": "__i3_scratch",
                    "window": null,
                    "nodes": [],
                    "floating_nodes": [],
                    "focus": [],
                    "fullscreen_mode": 1,
                    "sticky": false
                }
            ],
            "floating_nodes": [],
            "focus": [
                2147483646
            ],
            "fullscreen_mode": 0,
            "sticky": false
        },
        {
            "id": 2785,
            "type": "output",
            "orientation": "none",
            "percent": 0.5,
            "urgent": false,
            "marks": [],
            "focused": false,
            "layout": "output",
            "border": "none",
            "current_border_width": 0,
            "rect": {
                "x": 0,
                "y": 0,
                "width": 1920,
                "height": 1080
            },
            "deco_rect": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "window_rect": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "geometry": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "name": "HDMI-A-1",
            "window": null,
            "nodes": [
                {
                    "id": 29,
                    "type": "workspace",
                    "orientation": "horizontal",
                    "percent": null,
                    "urgent": false,
                    "marks": [],
                    "focused": false,
                    "layout": "splith",
                    "border": "none",
                    "current_border_width": 0,
                    "rect": {
                        "x": 0,
                        "y": 18,
                        "width": 1920,
                        "height": 1062
                    },
                    "deco_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "window_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "geometry": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "name": "4",
                    "window": null,
                    "nodes": [
                        {
                            "id": 30,
                            "type": "con",
                            "orientation": "none",
                            "percent": 1.0,
                            "urgent": false,
                            "marks": [],
                            "focused": false,
                            "layout": "none",
                            "border": "normal",
                            "current_border_width": 2,
                            "rect": {
                                "x": 0,
                                "y": 43,
                                "width": 1920,
                                "height": 1037
                            },
                            "deco_rect": {
                                "x": 0,
                                "y": 0,
                                "width": 1920,
                                "height": 25
                            },
                            "window_rect": {
                                "x": 2,
                                "y": 0,
                                "width": 1916,
                                "height": 1035
                            },
                            "geometry": {
                                "x": 0,
                                "y": 0,
                                "width": 1916,
                                "height": 1035
                            },
                            "name": "swaybar ~",
                            "window": null,
                            "nodes": [],
                            "floating_nodes": [],
                            "focus": [],
                            "fullscreen_mode": 0,
                            "sticky": false,
                            "pid": 5514,
                            "app_id": "kitty",
                            "visible": false,
                            "max_render_time": 0,
                            "shell": "xdg_shell",
                            "inhibit_idle": false,
                            "idle_inhibitors": {
                                "user": "none",
                                "application": "none"
                            }
                        }
                    ],
                    "floating_nodes": [],
                    "focus": [
                        30
                    ],
                    "fullscreen_mode": 1,
                    "sticky": false,
                    "num": 4,
                    "output": "HDMI-A-1",
                    "representation": "H[kitty]"
                },
                {
                    "id": 130,
                    "type": "workspace",
                    "orientation": "horizontal",
                    "percent": null,
                    "urgent": false,
                    "marks": [],
                    "focused": false,
                    "layout": "splith",
                    "border": "none",
                    "current_border_width": 0,
                    "rect": {
                        "x": 0,
                        "y": 18,
                        "width": 1920,
                        "height": 1062
                    },
                    "deco_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "window_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "geometry": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "name": "7",
                    "window": null,
                    "nodes": [
                        {
                            "id": 137,
                            "type": "con",
                            "orientation": "horizontal",
                            "percent": 1.0,
                            "urgent": false,
                            "marks": [],
                            "focused": false,
                            "layout": "splith",
                            "border": "none",
                            "current_border_width": 0,
                            "rect": {
                                "x": 0,
                                "y": 18,
                                "width": 1920,
                                "height": 1062
                            },
                            "deco_rect": {
                                "x": 0,
                                "y": 0,
                                "width": 0,
                                "height": 0
                            },
                            "window_rect": {
                                "x": 0,
                                "y": 0,
                                "width": 0,
                                "height": 0
                            },
                            "geometry": {
                                "x": 0,
                                "y": 0,
                                "width": 0,
                                "height": 0
                            },
                            "name": null,
                            "window": null,
                            "nodes": [
                                {
                                    "id": 140,
                                    "type": "con",
                                    "orientation": "horizontal",
                                    "percent": 1.0,
                                    "urgent": false,
                                    "marks": [],
                                    "focused": false,
                                    "layout": "splith",
                                    "border": "none",
                                    "current_border_width": 0,
                                    "rect": {
                                        "x": 0,
                                        "y": 18,
                                        "width": 1920,
                                        "height": 1062
                                    },
                                    "deco_rect": {
                                        "x": 0,
                                        "y": 0,
                                        "width": 0,
                                        "height": 0
                                    },
                                    "window_rect": {
                                        "x": 0,
                                        "y": 0,
                                        "width": 0,
                                        "height": 0
                                    },
                                    "geometry": {
                                        "x": 0,
                                        "y": 0,
                                        "width": 0,
                                        "height": 0
                                    },
                                    "name": null,
                                    "window": null,
                                    "nodes": [
                                        {
                                            "id": 220,
                                            "type": "con",
                                            "orientation": "horizontal",
                                            "percent": 1.0,
                                            "urgent": false,
                                            "marks": [],
                                            "focused": false,
                                            "layout": "splith",
                                            "border": "none",
                                            "current_border_width": 0,
                                            "rect": {
                                                "x": 0,
                                                "y": 18,
                                                "width": 1920,
                                                "height": 1062
                                            },
                                            "deco_rect": {
                                                "x": 0,
                                                "y": 0,
                                                "width": 0,
                                                "height": 0
                                            },
                                            "window_rect": {
                                                "x": 0,
                                                "y": 0,
                                                "width": 0,
                                                "height": 0
                                            },
                                            "geometry": {
                                                "x": 0,
                                                "y": 0,
                                                "width": 0,
                                                "height": 0
                                            },
                                            "name": null,
                                            "window": null,
                                            "nodes": [
                                                {
                                                    "id": 543,
                                                    "type": "con",
                                                    "orientation": "horizontal",
                                                    "percent": 1.0,
                                                    "urgent": false,
                                                    "marks": [],
                                                    "focused": false,
                                                    "layout": "splith",
                                                    "border": "none",
                                                    "current_border_width": 0,
                                                    "rect": {
                                                        "x": 0,
                                                        "y": 18,
                                                        "width": 1920,
                                                        "height": 1062
                                                    },
                                                    "deco_rect": {
                                                        "x": 0,
                                                        "y": 0,
                                                        "width": 0,
                                                        "height": 0
                                                    },
                                                    "window_rect": {
                                                        "x": 0,
                                                        "y": 0,
                                                        "width": 0,
                                                        "height": 0
                                                    },
                                                    "geometry": {
                                                        "x": 0,
                                                        "y": 0,
                                                        "width": 0,
                                                        "height": 0
                                                    },
                                                    "name": null,
                                                    "window": null,
                                                    "nodes": [
                                                        {
                                                            "id": 1450,
                                                            "type": "con",
                                                            "orientation": "horizontal",
                                                            "percent": 1.0,
                                                            "urgent": false,
                                                            "marks": [],
                                                            "focused": false,
                                                            "layout": "splith",
                                                            "border": "none",
                                                            "current_border_width": 0,
                                                            "rect": {
                                                                "x": 0,
                                                                "y": 18,
                                                                "width": 1920,
                                                                "height": 1062
                                                            },
                                                            "deco_rect": {
                                                                "x": 0,
                                                                "y": 0,
                                                                "width": 0,
                                                                "height": 0
                                                            },
                                                            "window_rect": {
                                                                "x": 0,
                                                                "y": 0,
                                                                "width": 0,
                                                                "height": 0
                                                            },
                                                            "geometry": {
                                                                "x": 0,
                                                                "y": 0,
                                                                "width": 0,
                                                                "height": 0
                                                            },
                                                            "name": null,
                                                            "window": null,
                                                            "nodes": [
                                                                {
                                                                    "id": 1456,
                                                                    "type": "con",
                                                                    "orientation": "horizontal",
                                                                    "percent": 1.0,
                                                                    "urgent": false,
                                                                    "marks": [],
                                                                    "focused": false,
                                                                    "layout": "splith",
                                                                    "border": "none",
                                                                    "current_border_width": 0,
                                                                    "rect": {
                                                                        "x": 0,
                                                                        "y": 18,
                                                                        "width": 1920,
                                                                        "height": 1062
                                                                    },
                                                                    "deco_rect": {
                                                                        "x": 0,
                                                                        "y": 0,
                                                                        "width": 0,
                                                                        "height": 0
                                                                    },
                                                                    "window_rect": {
                                                                        "x": 0,
                                                                        "y": 0,
                                                                        "width": 0,
                                                                        "height": 0
                                                                    },
                                                                    "geometry": {
                                                                        "x": 0,
                                                                        "y": 0,
                                                                        "width": 0,
                                                                        "height": 0
                                                                    },
                                                                    "name": null,
                                                                    "window": null,
                                                                    "nodes": [
                                                                        {
                                                                            "id": 1459,
                                                                            "type": "con",
                                                                            "orientation": "horizontal",
                                                                            "percent": 1.0,
                                                                            "urgent": false,
                                                                            "marks": [],
                                                                            "focused": false,
                                                                            "layout": "splith",
                                                                            "border": "none",
                                                                            "current_border_width": 0,
                                                                            "rect": {
                                                                                "x": 0,
                                                                                "y": 18,
                                                                                "width": 1920,
                                                                                "height": 1062
                                                                            },
                                                                            "deco_rect": {
                                                                                "x": 0,
                                                                                "y": 0,
                                                                                "width": 0,
                                                                                "height": 0
                                                                            },
                                                                            "window_rect": {
                                                                                "x": 0,
                                                                                "y": 0,
                                                                                "width": 0,
                                                                                "height": 0
                                                                            },
                                                                            "geometry": {
                                                                                "x": 0,
                                                                                "y": 0,
                                                                                "width": 0,
                                                                                "height": 0
                                                                            },
                                                                            "name": null,
                                                                            "window": null,
                                                                            "nodes": [
                                                                                {
                                                                                    "id": 1477,
                                                                                    "type": "con",
                                                                                    "orientation": "horizontal",
                                                                                    "percent": 1.0,
                                                                                    "urgent": false,
                                                                                    "marks": [],
                                                                                    "focused": false,
                                                                                    "layout": "splith",
                                                                                    "border": "none",
                                                                                    "current_border_width": 0,
                                                                                    "rect": {
                                                                                        "x": 0,
                                                                                        "y": 18,
                                                                                        "width": 1920,
                                                                                        "height": 1062
                                                                                    },
                                                                                    "deco_rect": {
                                                                                        "x": 0,
                                                                                        "y": 0,
                                                                                        "width": 0,
                                                                                        "height": 0
                                                                                    },
                                                                                    "window_rect": {
                                                                                        "x": 0,
                                                                                        "y": 0,
                                                                                        "width": 0,
                                                                                        "height": 0
                                                                                    },
                                                                                    "geometry": {
                                                                                        "x": 0,
                                                                                        "y": 0,
                                                                                        "width": 0,
                                                                                        "height": 0
                                                                                    },
                                                                                    "name": null,
                                                                                    "window": null,
                                                                                    "nodes": [
                                                                                        {
                                                                                            "id": 1483,
                                                                                            "type": "con",
                                                                                            "orientation": "horizontal",
                                                                                            "percent": 1.0,
                                                                                            "urgent": false,
                                                                                            "marks": [],
                                                                                            "focused": false,
                                                                                            "layout": "splith",
                                                                                            "border": "none",
                                                                                            "current_border_width": 0,
                                                                                            "rect": {
                                                                                                "x": 0,
                                                                                                "y": 18,
                                                                                                "width": 1920,
                                                                                                "height": 1062
                                                                                            },
                                                                                            "deco_rect": {
                                                                                                "x": 0,
                                                                                                "y": 0,
                                                                                                "width": 0,
                                                                                                "height": 0
                                                                                            },
                                                                                            "window_rect": {
                                                                                                "x": 0,
                                                                                                "y": 0,
                                                                                                "width": 0,
                                                                                                "height": 0
                                                                                            },
                                                                                            "geometry": {
                                                                                                "x": 0,
                                                                                                "y": 0,
                                                                                                "width": 0,
                                                                                                "height": 0
                                                                                            },
                                                                                            "name": null,
                                                                                            "window": null,
                                                                                            "nodes": [
                                                                                                {
                                                                                                    "id": 1600,
                                                                                                    "type": "con",
                                                                                                    "orientation": "horizontal",
                                                                                                    "percent": 1.0,
                                                                                                    "urgent": false,
                                                                                                    "marks": [],
                                                                                                    "focused": false,
                                                                                                    "layout": "splith",
                                                                                                    "border": "none",
                                                                                                    "current_border_width": 0,
                                                                                                    "rect": {
                                                                                                        "x": 0,
                                                                                                        "y": 18,
                                                                                                        "width": 1920,
                                                                                                        "height": 1062
                                                                                                    },
                                                                                                    "deco_rect": {
                                                                                                        "x": 0,
                                                                                                        "y": 0,
                                                                                                        "width": 0,
                                                                                                        "height": 0
                                                                                                    },
                                                                                                    "window_rect": {
                                                                                                        "x": 0,
                                                                                                        "y": 0,
                                                                                                        "width": 0,
                                                                                                        "height": 0
                                                                                                    },
                                                                                                    "geometry": {
                                                                                                        "x": 0,
                                                                                                        "y": 0,
                                                                                                        "width": 0,
                                                                                                        "height": 0
                                                                                                    },
                                                                                                    "name": null,
                                                                                                    "window": null,
                                                                                                    "nodes": [
                                                                                                        {
                                                                                                            "id": 1844,
                                                                                                            "type": "con",
                                                                                                            "orientation": "horizontal",
                                                                                                            "percent": 1.0,
                                                                                                            "urgent": false,
                                                                                                            "marks": [],
                                                                                                            "focused": false,
                                                                                                            "layout": "splith",
                                                                                                            "border": "none",
                                                                                                            "current_border_width": 0,
                                                                                                            "rect": {
                                                                                                                "x": 0,
                                                                                                                "y": 18,
                                                                                                                "width": 1920,
                                                                                                                "height": 1062
                                                                                                            },
                                                                                                            "deco_rect": {
                                                                                                                "x": 0,
                                                                                                                "y": 0,
                                                                                                                "width": 0,
                                                                                                                "height": 0
                                                                                                            },
                                                                                                            "window_rect": {
                                                                                                                "x": 0,
                                                                                                                "y": 0,
                                                                                                                "width": 0,
                                                                                                                "height": 0
                                                                                                            },
                                                                                                            "geometry": {
                                                                                                                "x": 0,
                                                                                                                "y": 0,
                                                                                                                "width": 0,
                                                                                                                "height": 0
                                                                                                            },
                                                                                                            "name": null,
                                                                                                            "window": null,
                                                                                                            "nodes": [
                                                                                                                {
                                                                                                                    "id": 2789,
                                                                                                                    "type": "con",
                                                                                                                    "orientation": "horizontal",
                                                                                                                    "percent": 1.0,
                                                                                                                    "urgent": false,
                                                                                                                    "marks": [],
                                                                                                                    "focused": false,
                                                                                                                    "layout": "splith",
                                                                                                                    "border": "none",
                                                                                                                    "current_border_width": 0,
                                                                                                                    "rect": {
                                                                                                                        "x": 0,
                                                                                                                        "y": 18,
                                                                                                                        "width": 1920,
                                                                                                                        "height": 1062
                                                                                                                    },
                                                                                                                    "deco_rect": {
                                                                                                                        "x": 0,
                                                                                                                        "y": 0,
                                                                                                                        "width": 0,
                                                                                                                        "height": 0
                                                                                                                    },
                                                                                                                    "window_rect": {
                                                                                                                        "x": 0,
                                                                                                                        "y": 0,
                                                                                                                        "width": 0,
                                                                                                                        "height": 0
                                                                                                                    },
                                                                                                                    "geometry": {
                                                                                                                        "x": 0,
                                                                                                                        "y": 0,
                                                                                                                        "width": 0,
                                                                                                                        "height": 0
                                                                                                                    },
                                                                                                                    "name": null,
                                                                                                                    "window": null,
                                                                                                                    "nodes": [
                                                                                                                        {
                                                                                                                            "id": 2793,
                                                                                                                            "type": "con",
                                                                                                                            "orientation": "vertical",
                                                                                                                            "percent": 0.5,
                                                                                                                            "urgent": false,
                                                                                                                            "marks": [],
                                                                                                                            "focused": false,
                                                                                                                            "layout": "splitv",
                                                                                                                            "border": "none",
                                                                                                                            "current_border_width": 0,
                                                                                                                            "rect": {
                                                                                                                                "x": 0,
                                                                                                                                "y": 18,
                                                                                                                                "width": 960,
                                                                                                                                "height": 1062
                                                                                                                            },
                                                                                                                            "deco_rect": {
                                                                                                                                "x": 0,
                                                                                                                                "y": 0,
                                                                                                                                "width": 0,
                                                                                                                                "height": 0
                                                                                                                            },
                                                                                                                            "window_rect": {
                                                                                                                                "x": 0,
                                                                                                                                "y": 0,
                                                                                                                                "width": 0,
                                                                                                                                "height": 0
                                                                                                                            },
                                                                                                                            "geometry": {
                                                                                                                                "x": 0,
                                                                                                                                "y": 0,
                                                                                                                                "width": 0,
                                                                                                                                "height": 0
                                                                                                                            },
                                                                                                                            "name": null,
                                                                                                                            "window": null,
                                                                                                                            "nodes": [
                                                                                                                                {
                                                                                                                                    "id": 10,
                                                                                                                                    "type": "con",
                                                                                                                                    "orientation": "none",
                                                                                                                                    "percent": 1.0,
                                                                                                                                    "urgent": false,
                                                                                                                                    "marks": [],
                                                                                                                                    "focused": true,
                                                                                                                                    "layout": "none",
                                                                                                                                    "border": "none",
                                                                                                                                    "current_border_width": 2,
                                                                                                                                    "rect": {
                                                                                                                                        "x": 0,
                                                                                                                                        "y": 18,
                                                                                                                                        "width": 960,
                                                                                                                                        "height": 1062
                                                                                                                                    },
                                                                                                                                    "deco_rect": {
                                                                                                                                        "x": 0,
                                                                                                                                        "y": 0,
                                                                                                                                        "width": 0,
                                                                                                                                        "height": 0
                                                                                                                                    },
                                                                                                                                    "window_rect": {
                                                                                                                                        "x": 0,
                                                                                                                                        "y": 0,
                                                                                                                                        "width": 960,
                                                                                                                                        "height": 1062
                                                                                                                                    },
                                                                                                                                    "geometry": {
                                                                                                                                        "x": 0,
                                                                                                                                        "y": 0,
                                                                                                                                        "width": 960,
                                                                                                                                        "height": 1062
                                                                                                                                    },
                                                                                                                                    "name": "swaywm Firefox Nightly",
                                                                                                                                    "window": null,
                                                                                                                                    "nodes": [],
                                                                                                                                    "floating_nodes": [],
                                                                                                                                    "focus": [],
                                                                                                                                    "fullscreen_mode": 0,
                                                                                                                                    "sticky": false,
                                                                                                                                    "pid": 2189,
                                                                                                                                    "app_id": "firefox",
                                                                                                                                    "visible": true,
                                                                                                                                    "max_render_time": 0,
                                                                                                                                    "shell": "xdg_shell",
                                                                                                                                    "inhibit_idle": false,
                                                                                                                                    "idle_inhibitors": {
                                                                                                                                        "user": "none",
                                                                                                                                        "application": "none"
                                                                                                                                    }
                                                                                                                                }
                                                                                                                            ],
                                                                                                                            "floating_nodes": [],
                                                                                                                            "focus": [
                                                                                                                                10
                                                                                                                            ],
                                                                                                                            "fullscreen_mode": 0,
                                                                                                                            "sticky": false
                                                                                                                        },
                                                                                                                        {
                                                                                                                            "id": 2792,
                                                                                                                            "type": "con",
                                                                                                                            "orientation": "vertical",
                                                                                                                            "percent": 0.5,
                                                                                                                            "urgent": false,
                                                                                                                            "marks": [],
                                                                                                                            "focused": false,
                                                                                                                            "layout": "splitv",
                                                                                                                            "border": "none",
                                                                                                                            "current_border_width": 0,
                                                                                                                            "rect": {
                                                                                                                                "x": 960,
                                                                                                                                "y": 18,
                                                                                                                                "width": 960,
                                                                                                                                "height": 1062
                                                                                                                            },
                                                                                                                            "deco_rect": {
                                                                                                                                "x": 0,
                                                                                                                                "y": 0,
                                                                                                                                "width": 0,
                                                                                                                                "height": 0
                                                                                                                            },
                                                                                                                            "window_rect": {
                                                                                                                                "x": 0,
                                                                                                                                "y": 0,
                                                                                                                                "width": 0,
                                                                                                                                "height": 0
                                                                                                                            },
                                                                                                                            "geometry": {
                                                                                                                                "x": 0,
                                                                                                                                "y": 0,
                                                                                                                                "width": 0,
                                                                                                                                "height": 0
                                                                                                                            },
                                                                                                                            "name": null,
                                                                                                                            "window": null,
                                                                                                                            "nodes": [
                                                                                                                                {
                                                                                                                                    "id": 2791,
                                                                                                                                    "type": "con",
                                                                                                                                    "orientation": "none",
                                                                                                                                    "percent": 1.0,
                                                                                                                                    "urgent": false,
                                                                                                                                    "marks": [],
                                                                                                                                    "focused": false,
                                                                                                                                    "layout": "none",
                                                                                                                                    "border": "normal",
                                                                                                                                    "current_border_width": 2,
                                                                                                                                    "rect": {
                                                                                                                                        "x": 960,
                                                                                                                                        "y": 43,
                                                                                                                                        "width": 960,
                                                                                                                                        "height": 1037
                                                                                                                                    },
                                                                                                                                    "deco_rect": {
                                                                                                                                        "x": 0,
                                                                                                                                        "y": 0,
                                                                                                                                        "width": 960,
                                                                                                                                        "height": 25
                                                                                                                                    },
                                                                                                                                    "window_rect": {
                                                                                                                                        "x": 2,
                                                                                                                                        "y": 0,
                                                                                                                                        "width": 956,
                                                                                                                                        "height": 1035
                                                                                                                                    },
                                                                                                                                    "geometry": {
                                                                                                                                        "x": 0,
                                                                                                                                        "y": 0,
                                                                                                                                        "width": 758,
                                                                                                                                        "height": 1035
                                                                                                                                    },
                                                                                                                                    "name": "pikaur ~/projects/sway",
                                                                                                                                    "window": null,
                                                                                                                                    "nodes": [],
                                                                                                                                    "floating_nodes": [],
                                                                                                                                    "focus": [],
                                                                                                                                    "fullscreen_mode": 0,
                                                                                                                                    "sticky": false,
                                                                                                                                    "pid": 1011856,
                                                                                                                                    "app_id": "kitty",
                                                                                                                                    "visible": true,
                                                                                                                                    "max_render_time": 0,
                                                                                                                                    "shell": "xdg_shell",
                                                                                                                                    "inhibit_idle": false,
                                                                                                                                    "idle_inhibitors": {
                                                                                                                                        "user": "none",
                                                                                                                                        "application": "none"
                                                                                                                                    }
                                                                                                                                }
                                                                                                                            ],
                                                                                                                            "floating_nodes": [],
                                                                                                                            "focus": [
                                                                                                                                2791
                                                                                                                            ],
                                                                                                                            "fullscreen_mode": 0,
                                                                                                                            "sticky": false
                                                                                                                        }
                                                                                                                    ],
                                                                                                                    "floating_nodes": [],
                                                                                                                    "focus": [
                                                                                                                        2793,
                                                                                                                        2792
                                                                                                                    ],
                                                                                                                    "fullscreen_mode": 0,
                                                                                                                    "sticky": false
                                                                                                                }
                                                                                                            ],
                                                                                                            "floating_nodes": [],
                                                                                                            "focus": [
                                                                                                                2789
                                                                                                            ],
                                                                                                            "fullscreen_mode": 0,
                                                                                                            "sticky": false
                                                                                                        }
                                                                                                    ],
                                                                                                    "floating_nodes": [],
                                                                                                    "focus": [
                                                                                                        1844
                                                                                                    ],
                                                                                                    "fullscreen_mode": 0,
                                                                                                    "sticky": false
                                                                                                }
                                                                                            ],
                                                                                            "floating_nodes": [],
                                                                                            "focus": [
                                                                                                1600
                                                                                            ],
                                                                                            "fullscreen_mode": 0,
                                                                                            "sticky": false
                                                                                        }
                                                                                    ],
                                                                                    "floating_nodes": [],
                                                                                    "focus": [
                                                                                        1483
                                                                                    ],
                                                                                    "fullscreen_mode": 0,
                                                                                    "sticky": false
                                                                                }
                                                                            ],
                                                                            "floating_nodes": [],
                                                                            "focus": [
                                                                                1477
                                                                            ],
                                                                            "fullscreen_mode": 0,
                                                                            "sticky": false
                                                                        }
                                                                    ],
                                                                    "floating_nodes": [],
                                                                    "focus": [
                                                                        1459
                                                                    ],
                                                                    "fullscreen_mode": 0,
                                                                    "sticky": false
                                                                }
                                                            ],
                                                            "floating_nodes": [],
                                                            "focus": [
                                                                1456
                                                            ],
                                                            "fullscreen_mode": 0,
                                                            "sticky": false
                                                        }
                                                    ],
                                                    "floating_nodes": [],
                                                    "focus": [
                                                        1450
                                                    ],
                                                    "fullscreen_mode": 0,
                                                    "sticky": false
                                                }
                                            ],
                                            "floating_nodes": [],
                                            "focus": [
                                                543
                                            ],
                                            "fullscreen_mode": 0,
                                            "sticky": false
                                        }
                                    ],
                                    "floating_nodes": [],
                                    "focus": [
                                        220
                                    ],
                                    "fullscreen_mode": 0,
                                    "sticky": false
                                }
                            ],
                            "floating_nodes": [],
                            "focus": [
                                140
                            ],
                            "fullscreen_mode": 0,
                            "sticky": false
                        }
                    ],
                    "floating_nodes": [],
                    "focus": [
                        137
                    ],
                    "fullscreen_mode": 1,
                    "sticky": false,
                    "num": 7,
                    "output": "HDMI-A-1",
                    "representation": "H[H[H[H[H[H[H[H[H[H[H[H[H[V[firefox] V[kitty]]]]]]]]]]]]]]"
                }
            ],
            "floating_nodes": [],
            "focus": [
                130,
                29
            ],
            "fullscreen_mode": 0,
            "sticky": false,
            "active": true,
            "dpms": true,
            "primary": false,
            "make": "Acer Technologies",
            "model": "Acer KA270H",
            "serial": "T3QSJ0014200",
            "scale": 1.0,
            "scale_filter": "nearest",
            "transform": "normal",
            "adaptive_sync_status": "disabled",
            "current_workspace": "7",
            "modes": [
                {
                    "width": 720,
                    "height": 400,
                    "refresh": 70082
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 66667
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 720,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 720,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 720,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 800,
                    "height": 600,
                    "refresh": 56250
                },
                {
                    "width": 800,
                    "height": 600,
                    "refresh": 60317
                },
                {
                    "width": 1024,
                    "height": 768,
                    "refresh": 60004
                },
                {
                    "width": 1024,
                    "height": 768,
                    "refresh": 70069
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 50000
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 50000
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 59940
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 60000
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 60000
                },
                {
                    "width": 1280,
                    "height": 800,
                    "refresh": 59910
                },
                {
                    "width": 1440,
                    "height": 900,
                    "refresh": 59901
                },
                {
                    "width": 1280,
                    "height": 1024,
                    "refresh": 60020
                },
                {
                    "width": 1680,
                    "height": 1050,
                    "refresh": 59883
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 50000
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 50000
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 59940
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 60000
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 60000
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 60000
                }
            ],
            "current_mode": {
                "width": 1920,
                "height": 1080,
                "refresh": 60000
            },
            "max_render_time": 0
        },
        {
            "id": 2579,
            "type": "output",
            "orientation": "none",
            "percent": 0.5,
            "urgent": false,
            "marks": [],
            "focused": false,
            "layout": "output",
            "border": "none",
            "current_border_width": 0,
            "rect": {
                "x": 1920,
                "y": 0,
                "width": 1920,
                "height": 1080
            },
            "deco_rect": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "window_rect": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "geometry": {
                "x": 0,
                "y": 0,
                "width": 0,
                "height": 0
            },
            "name": "DP-2",
            "window": null,
            "nodes": [
                {
                    "id": 4,
                    "type": "workspace",
                    "orientation": "horizontal",
                    "percent": null,
                    "urgent": false,
                    "marks": [],
                    "focused": false,
                    "layout": "splith",
                    "border": "none",
                    "current_border_width": 0,
                    "rect": {
                        "x": 1920,
                        "y": 18,
                        "width": 1920,
                        "height": 1062
                    },
                    "deco_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "window_rect": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "geometry": {
                        "x": 0,
                        "y": 0,
                        "width": 0,
                        "height": 0
                    },
                    "name": "1",
                    "window": null,
                    "nodes": [
                        {
                            "id": 2575,
                            "type": "con",
                            "orientation": "none",
                            "percent": 1.0,
                            "urgent": false,
                            "marks": [],
                            "focused": false,
                            "layout": "none",
                            "border": "normal",
                            "current_border_width": 2,
                            "rect": {
                                "x": 1920,
                                "y": 43,
                                "width": 1920,
                                "height": 1037
                            },
                            "deco_rect": {
                                "x": 0,
                                "y": 0,
                                "width": 1920,
                                "height": 25
                            },
                            "window_rect": {
                                "x": 2,
                                "y": 0,
                                "width": 1916,
                                "height": 1035
                            },
                            "geometry": {
                                "x": 0,
                                "y": 0,
                                "width": 731,
                                "height": 1035
                            },
                            "name": "fish ~/projects/sway",
                            "window": null,
                            "nodes": [],
                            "floating_nodes": [],
                            "focus": [],
                            "fullscreen_mode": 0,
                            "sticky": false,
                            "pid": 367387,
                            "app_id": "kitty",
                            "visible": true,
                            "max_render_time": 0,
                            "shell": "xdg_shell",
                            "inhibit_idle": false,
                            "idle_inhibitors": {
                                "user": "none",
                                "application": "none"
                            }
                        }
                    ],
                    "floating_nodes": [],
                    "focus": [
                        2575
                    ],
                    "fullscreen_mode": 1,
                    "sticky": false,
                    "num": 1,
                    "output": "DP-2",
                    "representation": "H[kitty]"
                }
            ],
            "floating_nodes": [],
            "focus": [
                4
            ],
            "fullscreen_mode": 0,
            "sticky": false,
            "active": true,
            "dpms": true,
            "primary": false,
            "make": "Ancor Communications Inc",
            "model": "ASUS VP278",
            "serial": "K3LMTF030840",
            "scale": 1.0,
            "scale_filter": "nearest",
            "transform": "normal",
            "adaptive_sync_status": "disabled",
            "current_workspace": "1",
            "modes": [
                {
                    "width": 720,
                    "height": 400,
                    "refresh": 70082
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 66667
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 72809
                },
                {
                    "width": 640,
                    "height": 480,
                    "refresh": 75000
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 720,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 720,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 720,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 720,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 800,
                    "height": 600,
                    "refresh": 56250
                },
                {
                    "width": 800,
                    "height": 600,
                    "refresh": 60317
                },
                {
                    "width": 800,
                    "height": 600,
                    "refresh": 72188
                },
                {
                    "width": 800,
                    "height": 600,
                    "refresh": 75000
                },
                {
                    "width": 832,
                    "height": 624,
                    "refresh": 74551
                },
                {
                    "width": 1440,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 1440,
                    "height": 480,
                    "refresh": 59940
                },
                {
                    "width": 1440,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 1440,
                    "height": 480,
                    "refresh": 60000
                },
                {
                    "width": 1024,
                    "height": 768,
                    "refresh": 60004
                },
                {
                    "width": 1024,
                    "height": 768,
                    "refresh": 70069
                },
                {
                    "width": 1024,
                    "height": 768,
                    "refresh": 75029
                },
                {
                    "width": 1440,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 1440,
                    "height": 576,
                    "refresh": 50000
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 50000
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 50000
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 59940
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 60000
                },
                {
                    "width": 1280,
                    "height": 720,
                    "refresh": 60000
                },
                {
                    "width": 1152,
                    "height": 864,
                    "refresh": 75000
                },
                {
                    "width": 1280,
                    "height": 800,
                    "refresh": 60000
                },
                {
                    "width": 1280,
                    "height": 960,
                    "refresh": 60000
                },
                {
                    "width": 1440,
                    "height": 900,
                    "refresh": 59901
                },
                {
                    "width": 1280,
                    "height": 1024,
                    "refresh": 60020
                },
                {
                    "width": 1280,
                    "height": 1024,
                    "refresh": 75025
                },
                {
                    "width": 1680,
                    "height": 1050,
                    "refresh": 59883
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 50000
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 59940
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 60000
                },
                {
                    "width": 1920,
                    "height": 1080,
                    "refresh": 60000
                }
            ],
            "current_mode": {
                "width": 1920,
                "height": 1080,
                "refresh": 60000
            },
            "max_render_time": 0
        }
    ],
    "floating_nodes": [],
    "focus": [
        2785,
        2579
    ],
    "fullscreen_mode": 0,
    "sticky": false
}

@ammgws
Copy link
Contributor

ammgws commented Oct 21, 2021

Related i3/i3#3001

@ammgws
Copy link
Contributor

ammgws commented Jan 31, 2024

Maybe this fix i3 recently merged would help here?
i3/i3#5469

@bonsaiiV
Copy link

You mean like this #7961 ?
It does not solve the original issue as creating unnecessary containers is still possible, by closing parallel ones. This PR follows the i3-way (i3/i3#5469) of stopping 'simple' unnecessary containers as described in this comment aswell as in i3/i3#3001 . I was thinking of solving this particular issue by flattening containers after reaping empty containers.:

@@ -553,6 +553,7 @@
void container_reap_empty(struct sway_container *con) {
        struct sway_workspace *ws = con->pending.workspace;
        while (con) {
                if (con->pending.children->length) {
+                       container_flatten(con);
                        return;
                }
                struct sway_container *parent = con->pending.parent;

This may however be hostile to some workflows (e.g. #7950).
Even just applying flatten once may cause issues in some configurations.
I have been thinking about just stopping the flatten one level before the workspace, this would mean, that only one potentially unnecessary container could exist, but i am not sure about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended layout
Development

Successfully merging a pull request may close this issue.

5 participants