diff --git a/README.md b/README.md index 14375b7..9325ed1 100644 --- a/README.md +++ b/README.md @@ -12,18 +12,28 @@ action](https://img.youtube.com/vi/UWRZuhn92bQ/0.jpg)](https://www.youtube.com/w ## PLEASE DO READ THIS -The script does one thing: it checks the window height / width ratio, and executes -the equivalent of either `swaymsg splitv` or `swaymsg splith`. Nothing less, nothing more. Yes, it may make -stacking and tabbed layouts behave oddly. No, nothing can be done about it. If you like stacking/tabbed layouts, -you may use them on workspaces with autotiling turned off (`--workspaces` argument). Do not submit issues about it. +The script does one thing: it checks the window height / width ratio, and +executes the equivalent of either `swaymsg splitv` or `swaymsg splith`. Nothing +less, nothing more. This may make stack and tabbed layouts behave oddly. +Unfortunately, there is nothing that can be done about it – please, do not +submit issues about it –, but there are two workaround that you can try. -For instance, you may configure autotiling to work on odd workspaces, but not on even: +One option is, to enable autotiling on certain workspaces only. For instance, +you could configure autotiling to be enabled on odd workspaces, but not on +even ones: ```text ### Autostart - exec autotiling -w 1 3 5 7 9 + exec_always autotiling -w 1 3 5 7 9 ``` +Another option you can try, is setting `--limit` and only use stacking or +tabbing on the lowest level. A good place to start would be `--limit 2`. Open +four windows with the third and fourth window in the same container as two. This +might mimic a master-stack layout and you should now be able to switch to +stacking or tabbed. Beware that the decision on how to split is still based on +the height / width ratio. + ## Installation The script has been packaged for the following distributions: @@ -54,6 +64,9 @@ optional arguments: -w [WORKSPACES ...], --workspaces [WORKSPACES ...] restricts autotiling to certain workspaces; example: autotiling --workspaces 8 9 + -l LIMIT, --limit LIMIT + limit how often autotiling will split a container; try "2", if you like + master-stack layouts; default: 0 (no limit) -e [EVENTS ...], --events [EVENTS ...] list of events to trigger switching split orientation; default: WINDOW MODE ``` @@ -64,4 +77,4 @@ Changing event subscription has already been the objective of several pull reque starting from v1.6 you may specify them in the `-e` | `--events` argument. If no value given, the script will subscribe to `Event.WINDOW` and `Event.MODE`, as if it was executed with `autotiling -e WINDOW MODE`. See [altdesktop/i3ipc-python`](https://github.com/altdesktop/i3ipc-python/blob/a670f24e7e04f509de8161cf760afe929c22ae93/i3ipc/events.py#L12) -for event enumeration. \ No newline at end of file +for event enumeration. diff --git a/autotiling/main.py b/autotiling/main.py index 50868ee..38f236c 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,31 @@ 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 + 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: + 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 +126,12 @@ def main(): nargs="*", type=str, default=[], ) + parser.add_argument("-l", + "--limit", + help='limit how often autotiling will split a container; ' + 'try "2", if you like master-stack layouts; 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 +160,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: