diff --git a/nwg_shell_config/autotiling.py b/nwg_shell_config/autotiling.py index 498d319..9cb9c52 100644 --- a/nwg_shell_config/autotiling.py +++ b/nwg_shell_config/autotiling.py @@ -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 @@ -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): @@ -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" @@ -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. @@ -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: diff --git a/nwg_shell_config/langs/en_US.json b/nwg_shell_config/langs/en_US.json index dbf8b8d..ee92e18 100644 --- a/nwg_shell_config/langs/en_US.json +++ b/nwg_shell_config/langs/en_US.json @@ -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.", diff --git a/nwg_shell_config/langs/pl_PL.json b/nwg_shell_config/langs/pl_PL.json index 362ca0a..d590262 100644 --- a/nwg_shell_config/langs/pl_PL.json +++ b/nwg_shell_config/langs/pl_PL.json @@ -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.", diff --git a/nwg_shell_config/main.py b/nwg_shell_config/main.py index f593613..e3f6f88 100644 --- a/nwg_shell_config/main.py +++ b/nwg_shell_config/main.py @@ -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: @@ -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, diff --git a/nwg_shell_config/shell/settings b/nwg_shell_config/shell/settings index 9a77706..59dc5c4 100644 --- a/nwg_shell_config/shell/settings +++ b/nwg_shell_config/shell/settings @@ -2,6 +2,7 @@ "keyboard-layout": "us", "autotiling-workspaces": "", "autotiling-on": true, + "autotiling-limit": false, "appindicator": true, "night-lat": -1, "night-long": -1, diff --git a/nwg_shell_config/ui_components.py b/nwg_shell_config/ui_components.py index 0b48d8c..9ae1943 100644 --- a/nwg_shell_config/ui_components.py +++ b/nwg_shell_config/ui_components.py @@ -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) diff --git a/setup.py b/setup.py index 016cf26..5c31a8a 100644 --- a/setup.py +++ b/setup.py @@ -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,