From 23c402a44c2682a5a8779433315ca2371da16c73 Mon Sep 17 00:00:00 2001 From: piotr Date: Tue, 16 Feb 2021 03:25:17 +0100 Subject: Save args.workspaces to /tmp for use with nwg-panel --- autotiling/main.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/autotiling/main.py b/autotiling/main.py index 5a8547e..896034b 100644 --- a/autotiling/main.py +++ b/autotiling/main.py @@ -13,6 +13,7 @@ License: GPL3 Dependencies: python-i3ipc>=2.0.1 (i3ipc-python) """ import argparse +import os import sys from functools import partial @@ -24,6 +25,26 @@ except ImportError: __version__ = "unknown" +def temp_dir(): + if os.getenv("TMPDIR"): + return os.getenv("TMPDIR") + elif os.getenv("TEMP"): + return os.getenv("TEMP") + elif os.getenv("TMP"): + return os.getenv("TMP") + + return "/tmp" + + +def save_string(string, file): + try: + file = open(file, "wt") + file.write(string) + file.close() + except Exception as e: + print(e) + + def switch_splitting(i3, e, debug, workspaces): try: con = i3.get_tree().find_focused() @@ -85,6 +106,10 @@ def main(): 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")) handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces) i3 = Connection() -- cgit