Skip to content

Commit

Permalink
Merge pull request #29 from nwg-piotr/test-depth-limit
Browse files Browse the repository at this point in the history
nwg-autotiling: add depth limit
  • Loading branch information
nwg-piotr authored Oct 31, 2022
2 parents ae5762e + c080827 commit b88c8e3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
39 changes: 35 additions & 4 deletions nwg_shell_config/autotiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
Additions:
- killing existing *autotiling* process instances on startup;
- gentle SIGINT & SIGTERM handler;
- clearing used workspaces info ('/tmp/autotiling' file) if started w/o the -- workspaces argument.
- gentle SIGINT & SIGTERM handler.
"""
import argparse
import os
Expand Down Expand Up @@ -56,7 +55,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 @@ -68,6 +67,32 @@ def switch_splitting(i3, e, debug, workspaces):
# We are on sway
is_floating = con.type == "floating_con"

# `depth_limit` contributed by @Syphdias to original autotiling script
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"
Expand Down Expand Up @@ -117,6 +142,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.
Expand Down Expand Up @@ -158,7 +189,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
2 changes: 2 additions & 0 deletions nwg_shell_config/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"auto-show-hide-tooltip": "Auto-hide dock, show on hotspot pointed.",
"autotiling": "Autotiling",
"autotiling-tooltip": "Automates changing the horizontal/vertical window split orientation.",
"autotiling-depth-limit": "Depth limit",
"autotiling-depth-limit-tooltip": "Limits autotiling depth to 2 levels, to mimic\n(to some degree) the master/stack layout.",
"backgrounds": "Backgrounds",
"before-sleep": "Before sleep",
"before-sleep-tooltip": "Command to execute before systemd puts the computer to sleep.",
Expand Down
2 changes: 2 additions & 0 deletions nwg_shell_config/langs/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"auto-show-hide-tooltip": "Automatycznie ukrywaj, wyświetl po wskazaniu hotspota myszą.",
"autotiling": "Autotiling",
"autotiling-tooltip": "Automatyzuje zmianę poziom/pion orientacji podziału okna.",
"autotiling-depth-limit": "Limit głębokości",
"autotiling-depth-limit-tooltip": "Ogranicza autotiling do 2 poziomów, udając\n(do pewnego stopnia) układ master/stack.",
"backgrounds": "Tapety",
"before-sleep": "Przed uśpieniem",
"before-sleep-tooltip": "Komenda do wykonania zanim `systemd` uśpi komputer.",
Expand Down
6 changes: 6 additions & 0 deletions nwg_shell_config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,13 @@ def save_includes():

if settings["autotiling-on"]:
cmd_autotiling = "exec_always nwg-autotiling"

if settings["autotiling-workspaces"]:
cmd_autotiling += " -w {}".format(settings["autotiling-workspaces"])

if settings["autotiling-limit"]:
cmd_autotiling += " -l 2"

autostart.append(cmd_autotiling)

if cmd_launcher_autostart:
Expand Down Expand Up @@ -744,6 +749,7 @@ def load_settings():
"keyboard-layout": "us",
"autotiling-workspaces": "",
"autotiling-on": True,
"autotiling-limit": False,
"appindicator": True,
"night-lat": -1,
"night-long": -1,
Expand Down
1 change: 1 addition & 0 deletions nwg_shell_config/shell/settings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"keyboard-layout": "us",
"autotiling-workspaces": "",
"autotiling-on": true,
"autotiling-limit": false,
"appindicator": true,
"night-lat": -1,
"night-long": -1,
Expand Down
6 changes: 6 additions & 0 deletions nwg_shell_config/ui_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ def screen_tab(settings, voc, pending_updates):
entry.connect("changed", set_from_workspaces, settings)
grid.attach(entry, 1, 3, 1, 1)

cb_autotiling_limit = Gtk.CheckButton.new_with_label(voc["autotiling-depth-limit"])
cb_autotiling_limit.set_active(settings["autotiling-limit"])
cb_autotiling_limit.connect("toggled", set_from_checkbutton, settings, "autotiling-limit")
cb_autotiling_limit.set_tooltip_text(voc["autotiling-depth-limit-tooltip"])
grid.attach(cb_autotiling_limit, 2, 3, 2, 1)

lbl = Gtk.Label()
lbl.set_markup("<b>{}</b>".format(voc["night-light"]))
lbl.set_property("margin-top", 6)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(f_name):

setup(
name='nwg-shell-config',
version='0.4.4',
version='0.4.5',
description='nwg-shell configuration utility',
packages=find_packages(),
include_package_data=True,
Expand Down

0 comments on commit b88c8e3

Please sign in to comment.