From 2aeab6cfbd0ba86f80f824e42088d5473a9e6a58 Mon Sep 17 00:00:00 2001 From: Piotr Miller Date: Thu, 25 Nov 2021 11:36:42 +0100 Subject: improve .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0bdec20..50341b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /.idea /venv +/autotiling.egg-info/ +/build/ +/dist/ -- cgit From ea3caa81818e06ac88712443571fc79a5080e39a Mon Sep 17 00:00:00 2001 From: Piotr Miller Date: Thu, 25 Nov 2021 11:55:00 +0100 Subject: allow specifying events; version bump --- autotiling/main.py | 36 ++++++++++++++++++++++++++++-------- setup.cfg | 4 ++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/autotiling/main.py b/autotiling/main.py index dc237a2..b7cc75e 100644 --- a/autotiling/main.py +++ b/autotiling/main.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + """ This script uses the i3ipc python module to switch the layout splith / splitv for the currently focused window, depending on its dimensions. @@ -62,8 +64,7 @@ def switch_splitting(i3, e, debug, workspaces): is_stacked = con.parent.layout == "stacked" is_tabbed = con.parent.layout == "tabbed" - # Let's exclude floating containers, stacked layouts, tabbed layouts and - # full screen mode + # Exclude floating containers, stacked layouts, tabbed layouts and full screen mode if (not is_floating and not is_stacked and not is_tabbed @@ -89,7 +90,7 @@ def main(): parser.add_argument("-d", "--debug", action="store_true", - help="Print debug messages to stderr") + help="print debug messages to stderr") parser.add_argument("-v", "--version", action="version", @@ -97,24 +98,43 @@ def main(): help="display version information", ) parser.add_argument("-w", "--workspaces", - help="Restricts autotiling to certain workspaces. Example: autotiling --workspaces 8 9", + help="restricts autotiling to certain workspaces. Example: autotiling --workspaces 8 9", + nargs="*", + type=str, + default=[], ) + """ + 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. + """ + parser.add_argument("-e", + "--events", + help="list of events to trigger switching split orientation; Default: WINDOW MODE", nargs="*", type=str, - default=[],) + default=["WINDOW", "MODE"]) args = parser.parse_args() if args.debug and args.workspaces: print("autotiling is only active on workspaces:", ','.join(args.workspaces)) - + # For use w/ nwg-panel if args.workspaces: save_string(','.join(args.workspaces), os.path.join(temp_dir(), "autotiling")) + if not args.events: + print("No events specified", file=sys.stderr) + sys.exit(1) + handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces) i3 = Connection() - i3.on(Event.WINDOW, handler) - i3.on(Event.MODE, handler) + for e in args.events: + try: + i3.on(Event[e], handler) + print("{} subscribed".format(Event[e])) + except KeyError: + print("'{}' is not a valid event".format(e), file=sys.stderr) + i3.main() diff --git a/setup.cfg b/setup.cfg index e67767f..52b9747 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,9 @@ [metadata] name = autotiling -version = 1.5 +version = 1.6 author = Piotr Miller author_email = nwg.piotr@gmail.com -description = Automatically switch the horizontal/vertical window split orientation in i3 and sway +description = Automatically switch the horizontal/vertical window split orientation in sway and i3 url = https://github.com/nwg-piotr/autotiling project_urls = Code=https://github.com/nwg-piotr/autotiling -- cgit From 89e5cf26e1d95ef530413302dd60868d2b5b3b99 Mon Sep 17 00:00:00 2001 From: Piotr Miller Date: Thu, 25 Nov 2021 11:58:56 +0100 Subject: help format corrected --- autotiling/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autotiling/main.py b/autotiling/main.py index b7cc75e..1780884 100644 --- a/autotiling/main.py +++ b/autotiling/main.py @@ -98,7 +98,7 @@ def main(): help="display version information", ) parser.add_argument("-w", "--workspaces", - help="restricts autotiling to certain workspaces. Example: autotiling --workspaces 8 9", + help="restricts autotiling to certain workspaces; example: autotiling --workspaces 8 9", nargs="*", type=str, default=[], ) @@ -108,7 +108,7 @@ def main(): """ parser.add_argument("-e", "--events", - help="list of events to trigger switching split orientation; Default: WINDOW MODE", + help="list of events to trigger switching split orientation; default: WINDOW MODE", nargs="*", type=str, default=["WINDOW", "MODE"]) -- cgit