diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | autotiling/main.py | 36 | ||||
-rw-r--r-- | setup.cfg | 4 |
3 files changed, 33 insertions, 10 deletions
@@ -1,2 +1,5 @@ /.idea /venv +/autotiling.egg-info/ +/build/ +/dist/ diff --git a/autotiling/main.py b/autotiling/main.py index dc237a2..1780884 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() @@ -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 |