Skip to content

Commit

Permalink
Add depth limit as argument for how often to autotile
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Syphdias committed Oct 27, 2022
1 parent ee0686e commit efb8f29
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions autotiling/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit efb8f29

Please sign in to comment.