From 2faad763b0138712201e4d78825d2a0dc1798204 Mon Sep 17 00:00:00 2001 From: Syphdias Date: Tue, 1 Nov 2022 20:28:02 +0100 Subject: Add option to limit to outputs To enable different limits on different outputs, you can start two processes and limit them to the outputs you want. --- README.md | 9 ++++++--- autotiling/main.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9325ed1..2601c77 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ 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. -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: +One option is, to enable autotiling on certain workspaces or outputs only. +For instance, you could configure autotiling to be enabled on odd workspaces, +but not on even ones: ```text ### Autostart @@ -61,6 +61,9 @@ optional arguments: -h, --help show this help message and exit -d, --debug print debug messages to stderr -v, --version display version information + -o [OUTPUTS ...], --outputs [OUTPUTS ...] + restricts autotiling to certain output; example: autotiling --output DP-1 + HDMI-0 -w [WORKSPACES ...], --workspaces [WORKSPACES ...] restricts autotiling to certain workspaces; example: autotiling --workspaces 8 9 diff --git a/autotiling/main.py b/autotiling/main.py index 38f236c..e5b3ad7 100644 --- a/autotiling/main.py +++ b/autotiling/main.py @@ -47,8 +47,18 @@ def save_string(string, file): print(e) -def switch_splitting(i3, e, debug, workspaces, depth_limit): +def switch_splitting(i3, e, debug, outputs, workspaces, depth_limit): try: + output = e.ipc_data.get("container", {}).get("output", "") + # Stop, if outputs is set and current output is not in the selection + if outputs and output not in outputs: + if debug: + print( + "Debug: Autotiling turned off on output {}".format(output), + file=sys.stderr, + ) + return + con = i3.get_tree().find_focused() if con and not workspaces or (str(con.workspace().num) in workspaces): if con.floating: @@ -120,6 +130,13 @@ def main(): action="version", version="%(prog)s {}, Python {}".format(__version__, sys.version), help="display version information", ) + parser.add_argument("-o", + "--outputs", + help="restricts autotiling to certain output; " + "example: autotiling --output DP-1 HDMI-0", + nargs="*", + type=str, + default=[], ) parser.add_argument("-w", "--workspaces", help="restricts autotiling to certain workspaces; example: autotiling --workspaces 8 9", @@ -145,6 +162,9 @@ def main(): args = parser.parse_args() + if args.debug and args.outputs: + print("autotiling is only active on outputs:", ",".join(args.outputs)) + if args.debug and args.workspaces: print("autotiling is only active on workspaces:", ','.join(args.workspaces)) @@ -160,7 +180,13 @@ def main(): print("No events specified", file=sys.stderr) sys.exit(1) - handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces, depth_limit=args.limit) + handler = partial( + switch_splitting, + debug=args.debug, + outputs=args.outputs, + workspaces=args.workspaces, + depth_limit=args.limit, + ) i3 = Connection() for e in args.events: try: -- cgit From 017bea932c37b6cae2c961afd29396f212b27287 Mon Sep 17 00:00:00 2001 From: Syphdias Date: Tue, 8 Nov 2022 00:26:51 +0100 Subject: Find output by analysing parent instead of ipc_data Apparently there are differences in the returned ipc_data for sway and we cannot use the ipc_data of the event that triggered the handler. To accommodate this, we look at the currently focused container and check its parents recursively until we find the output. --- autotiling/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/autotiling/main.py b/autotiling/main.py index e5b3ad7..8f7e673 100644 --- a/autotiling/main.py +++ b/autotiling/main.py @@ -47,9 +47,21 @@ def save_string(string, file): print(e) +def output_name(con): + if con.type == "root": + return None + + if p := con.parent: + if p.type == "output": + return p.name + else: + return output_name(p) + + def switch_splitting(i3, e, debug, outputs, workspaces, depth_limit): try: - output = e.ipc_data.get("container", {}).get("output", "") + con = i3.get_tree().find_focused() + output = output_name(con) # Stop, if outputs is set and current output is not in the selection if outputs and output not in outputs: if debug: @@ -59,7 +71,6 @@ def switch_splitting(i3, e, debug, outputs, workspaces, depth_limit): ) return - con = i3.get_tree().find_focused() if con and not workspaces or (str(con.workspace().num) in workspaces): if con.floating: # We're on i3: on sway it would be None -- cgit