diff options
author | Jason Nader <jason.nader@protonmail.com> | 2020-03-20 21:39:59 +0900 |
---|---|---|
committer | Jason Nader <jason.nader@protonmail.com> | 2020-03-20 21:46:40 +0900 |
commit | 81e471d183e38eeab4dcea740ba9e70d431035bd (patch) | |
tree | c4f540356c2d0ed1c6d23cc74e9886726e08a951 /autotiling.py | |
parent | 3d83a5fd94c8ff3f6e8ba65e01955264f4a50618 (diff) | |
download | autotiling-81e471d183e38eeab4dcea740ba9e70d431035bd.tar.gz |
Add `--debug` option
Diffstat (limited to 'autotiling.py')
-rwxr-xr-x | autotiling.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/autotiling.py b/autotiling.py index e430d32..79acd03 100755 --- a/autotiling.py +++ b/autotiling.py @@ -15,13 +15,14 @@ License: GPL3 Dependencies: python-i3ipc>=2.0.1 (i3ipc-python) """ +import argparse import sys +from functools import partial from i3ipc import Connection, Event - -def switch_splitting(i3, e): +def switch_splitting(i3, e, debug): try: con = i3.get_tree().find_focused() if con: @@ -39,16 +40,31 @@ def switch_splitting(i3, e): # Let's exclude floating containers, stacked layouts, tabbed layouts and full screen mode if not is_floating and not is_stacked and not is_tabbed and not is_full_screen: new_layout = 'splitv' if con.rect.height > con.rect.width else 'splith' - i3.command(new_layout) + if new_layout != con.parent.layout: + result = i3.command(new_layout) + if result[0].success and debug: + print('Debug: Switched to {}'.format(new_layout), file=sys.stderr) + else: + print('Error: {}'.format(result[0].error), file=sys.stderr) + + elif debug: + print('Debug: No focused container found', file=sys.stderr) except Exception as e: print('Error: {}'.format(e), file=sys.stderr) - pass def main(): - i3.on(Event.WINDOW_FOCUS, switch_splitting) + parser = argparse.ArgumentParser() + parser.add_argument( + '--debug', + action='store_true', + help='Print debug messages to stderr' + ) + args = parser.parse_args() + handler = partial(switch_splitting, debug=args.debug) i3 = Connection() + i3.on(Event.WINDOW_FOCUS, handler) i3.main() |