aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSyphdias <syphdias+git@gmail.com>2022-10-27 19:36:29 +0200
committerSyphdias <syphdias+git@gmail.com>2022-10-27 20:19:00 +0200
commitefb8f2997eb5c04f8e5aff5f095b42f0f93f1777 (patch)
treede36be257c0ef574e642d22193ddf317f0cb21f5
parentee0686eacdcb638f730cb8e7d9fc822075d99e85 (diff)
downloadautotiling-efb8f2997eb5c04f8e5aff5f095b42f0f93f1777.tar.gz
Add depth limit as argument for how often to autotile
Currently the script will autotile (vsplit/hsplit) every window focused on with no limit. At a certain depth this behaviour is not desirably to me and I want to add more windows to the same container. Especially for terminals I prefer to have more space horizontally than vertically to see the entire line if possible. To achieve this, I add a optional parameter to prevent further autotiling after the specified limit. For example with a 16:9 display and a depth limit of 1, it will split horizontally first and then only split vertically but in the same container. ``` ________________ | | | |--------| | | |-------| |--------| | |________|_______| ``` As a side effect, this enables stacking and tabbed layouts after reaching the limit. The default behavior is still the same with an infinite limit for how deep to autotile.
-rw-r--r--autotiling/main.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/autotiling/main.py b/autotiling/main.py
index 50868ee..5560949 100644
--- a/autotiling/main.py
+++ b/autotiling/main.py
@@ -47,7 +47,7 @@ def save_string(string, file):
print(e)
-def switch_splitting(i3, e, debug, workspaces):
+def switch_splitting(i3, e, debug, workspaces, depth_limit):
try:
con = i3.get_tree().find_focused()
if con and not workspaces or (str(con.workspace().num) in workspaces):
@@ -59,6 +59,22 @@ def switch_splitting(i3, e, debug, workspaces):
# We are on sway
is_floating = con.type == "floating_con"
+ if 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
+ if current_con.type == "workspace":
+ # Found the workspace within the depth limitation
+ depth_limit_reached = False
+
+ if depth_limit_reached:
+ if debug:
+ print("Debug: Depth limit reached")
+ return
+
is_full_screen = con.fullscreen_mode == 1
is_stacked = con.parent.layout == "stacked"
is_tabbed = con.parent.layout == "tabbed"
@@ -101,6 +117,11 @@ def main():
nargs="*",
type=str,
default=[], )
+ parser.add_argument("-l",
+ "--limit",
+ help="limit how often autotiling will split a container; default: 0 (no limit)",
+ type=int,
+ default=0, )
"""
Changing event subscription has already been the objective of several pull request. To avoid doing this again
and again, let's allow to specify them in the `--events` argument.
@@ -129,7 +150,7 @@ def main():
print("No events specified", file=sys.stderr)
sys.exit(1)
- handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces)
+ handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces, depth_limit=args.limit)
i3 = Connection()
for e in args.events:
try: