aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSyphdias <syphdias+git@gmail.com>2022-10-30 17:42:33 +0100
committerSyphdias <syphdias+git@gmail.com>2022-10-30 17:42:33 +0100
commitef9815dac7225659a1b2fdb3f0f69534c52e10c2 (patch)
treef96d7e89e5186dd3cde11ffae78d7ba49aef25b8
parentefb8f2997eb5c04f8e5aff5f095b42f0f93f1777 (diff)
downloadautotiling-ef9815dac7225659a1b2fdb3f0f69534c52e10c2.tar.gz
Ignore containers for depth if they have 1 child node
With lots of splits the hierarchy can get deeper than normal, if containers get closed. i3 does not flatten this hierarchy (atm). This means that the depth option does needs to ignore containers that only contain one child/node. This is done only incrementing the current depth when checking against the limit if the nodes of the parent container is bigger than 1.
-rw-r--r--autotiling/main.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/autotiling/main.py b/autotiling/main.py
index 5560949..941863b 100644
--- a/autotiling/main.py
+++ b/autotiling/main.py
@@ -63,12 +63,21 @@ def switch_splitting(i3, e, debug, workspaces, depth_limit):
# Assume we reached the depth limit, unless we can find a workspace
depth_limit_reached = True
current_con = con
- for _ in range(depth_limit):
- # Check if parent of the current con is a workspace
- current_con = current_con.parent
+ current_depth = 0
+ while current_depth < depth_limit:
+ # Check if we found the workspace of the current container
if current_con.type == "workspace":
# Found the workspace within the depth limitation
depth_limit_reached = False
+ break
+
+ # Look at the parent for next iteration
+ current_con = current_con.parent
+
+ # Only count up the depth, if the container has more than
+ # one container as child
+ if len(current_con.nodes) > 1:
+ current_depth += 1
if depth_limit_reached:
if debug: