diff options
author | piotr <nwg.piotr@gmail.com> | 2020-03-22 00:28:30 +0100 |
---|---|---|
committer | piotr <nwg.piotr@gmail.com> | 2020-03-22 00:28:30 +0100 |
commit | 798b9f4bf9bfd0f9a8912ac86de1c1243a216962 (patch) | |
tree | 1ca6a1673e3e5dcfc3e027860cb07c42e795dd2d | |
parent | d8d51eb7b2b2828997ea597a7ea73baa7bdcd4fd (diff) | |
parent | a4da24d65dc931b3bdea316db5193515284acbc1 (diff) | |
download | autotiling-798b9f4bf9bfd0f9a8912ac86de1c1243a216962.tar.gz |
Merge remote-tracking branch 'origin/master'
-rwxr-xr-x | autotiling.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/autotiling.py b/autotiling.py index 9cd6aa5..131e447 100755 --- a/autotiling.py +++ b/autotiling.py @@ -8,20 +8,21 @@ It works on both sway and i3 window managers. Inspired by https://github.com/olemartinorg/i3-alternating-layout -Author: Piotr Miller +Copyright: 2019-2020 Piotr Miller & Contributors e-mail: nwg.piotr@gmail.com Project: https://github.com/nwg-piotr/autotiling License: GPL3 Dependencies: python-i3ipc>=2.0.1 (i3ipc-python) """ +import argparse +import sys +from functools import partial from i3ipc import Connection, Event -i3 = Connection() - -def switch_splitting(i3, e): +def switch_splitting(i3, e, debug): try: con = i3.get_tree().find_focused() if con: @@ -39,15 +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: Switch failed with err {}'.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)) - pass + print('Error: {}'.format(e), file=sys.stderr) 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() |