aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Miller <nwg.piotr@gmail.com>2024-02-09 00:43:51 +0100
committerGitHub <noreply@github.com>2024-02-09 00:43:51 +0100
commit2d15d4569992f24ea735028d7a6d783ff45941d0 (patch)
treee9d7eaa4d5b902a7bb9f6f54237763eefb1d9e65
parent2d397385db79f00e4217e0cdb830b4c133c38170 (diff)
parent31207c0ca44ed846763dc6df55316ee7a7d047a8 (diff)
downloadautotiling-2d15d4569992f24ea735028d7a6d783ff45941d0.tar.gz
Merge branch 'master' into master
-rw-r--r--.github/FUNDING.yml1
-rw-r--r--autotiling/main.py89
2 files changed, 30 insertions, 60 deletions
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..84a260b
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: nwg-piotr
diff --git a/autotiling/main.py b/autotiling/main.py
index 87d0ee0..4fd9e97 100644
--- a/autotiling/main.py
+++ b/autotiling/main.py
@@ -28,21 +28,13 @@ except ImportError:
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 os.getenv("TMPDIR") or os.getenv("TEMP") or os.getenv("TMP") or "/tmp"
- return "/tmp"
-
-def save_string(string, file):
+def save_string(string, file_path):
try:
- file = open(file, "wt")
- file.write(string)
- file.close()
+ with open(file_path, "wt") as file:
+ file.write(string)
except Exception as e:
print(e)
@@ -65,10 +57,7 @@ def switch_splitting(i3, e, debug, outputs, workspaces, depth_limit, splitwidth,
# Stop, if outputs is set and current output is not in the selection
if outputs and output not in outputs:
if debug:
- print(
- "Debug: Autotiling turned off on output {}".format(output),
- file=sys.stderr,
- )
+ print(f"Debug: Autotiling turned off on output {output}", file=sys.stderr)
return
if con and not workspaces or (str(con.workspace().num) in workspaces):
@@ -119,9 +108,9 @@ def switch_splitting(i3, e, debug, outputs, workspaces, depth_limit, splitwidth,
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)
+ print(f"Debug: Switched to {new_layout}", file=sys.stderr)
elif debug:
- print("Error: Switch failed with err {}".format(result[0].error), file=sys.stderr, )
+ print(f"Error: Switch failed with err {result[0].error}", file=sys.stderr)
if e.change in ["new","move"] and con.percent:
if con.parent.layout == "splitv" and splitheight != 1.0: # top / bottom
@@ -135,39 +124,23 @@ def switch_splitting(i3, e, debug, outputs, workspaces, depth_limit, splitwidth,
print("Debug: No focused container found or autotiling on the workspace turned off", file=sys.stderr)
except Exception as e:
- print("Error: {}".format(e), file=sys.stderr)
+ print(f"Error: {e}", file=sys.stderr)
def main():
parser = argparse.ArgumentParser()
- parser.add_argument("-d",
- "--debug",
- action="store_true",
+
+ parser.add_argument("-d", "--debug", action="store_true",
help="print debug messages to stderr")
- parser.add_argument("-v",
- "--version",
- action="version",
- version="%(prog)s {}, Python {}".format(__version__, sys.version),
- help="display version information", )
- parser.add_argument("-o",
- "--outputs",
- help="restricts autotiling to certain output; "
- "example: autotiling --output DP-1 HDMI-0",
- nargs="*",
- type=str,
- default=[], )
- parser.add_argument("-w",
- "--workspaces",
- help="restricts autotiling to certain workspaces; example: autotiling --workspaces 8 9",
- nargs="*",
- type=str,
- default=[], )
- parser.add_argument("-l",
- "--limit",
- help='limit how often autotiling will split a container; '
- 'try "2", if you like master-stack layouts; default: 0 (no limit)',
- type=int,
- default=0, )
+ parser.add_argument("-v", "--version", action="version",
+ version=f"%(prog)s {__version__}, Python {sys.version}",
+ help="display version information")
+ parser.add_argument("-o", "--outputs", nargs="*", type=str, default=[],
+ help="restricts autotiling to certain output; example: autotiling --output DP-1 HDMI-0")
+ parser.add_argument("-w", "--workspaces", nargs="*", type=str, default=[],
+ help="restricts autotiling to certain workspaces; example: autotiling --workspaces 8 9")
+ parser.add_argument("-l", "--limit", type=int, default=0,
+ help='limit how often autotiling will split a container; try "2" if you like master-stack layouts; default: 0 (no limit)')
parser.add_argument("-sw",
"--splitwidth",
help='set the width of the vertical split (as factor); default: 1.0;',
@@ -184,24 +157,21 @@ def main():
'try "1.61", for golden ratio - window has to be 61%% wider for left/right split; default: 1.0;',
type=float,
default=1.0, )
+
"""
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=["WINDOW", "MODE"])
+ parser.add_argument("-e", "--events", nargs="*", type=str, default=["WINDOW", "MODE"],
+ help="list of events to trigger switching split orientation; default: WINDOW MODE")
args = parser.parse_args()
- if args.debug and args.outputs:
- print("autotiling is only active on outputs:", ",".join(args.outputs))
-
- if args.debug and args.workspaces:
- print("autotiling is only active on workspaces:", ','.join(args.workspaces))
+ if args.debug:
+ if args.outputs:
+ print(f"autotiling is only active on outputs: {','.join(args.outputs)}")
+ if args.workspaces:
+ print(f"autotiling is only active on workspaces: {','.join(args.workspaces)}")
# For use w/ nwg-panel
ws_file = os.path.join(temp_dir(), "autotiling")
@@ -229,13 +199,12 @@ def main():
for e in args.events:
try:
i3.on(Event[e], handler)
- print("{} subscribed".format(Event[e]))
+ print(f"{Event[e]} subscribed")
except KeyError:
- print("'{}' is not a valid event".format(e), file=sys.stderr)
+ print(f"'{e}' is not a valid event", file=sys.stderr)
i3.main()
if __name__ == "__main__":
- # execute only if run as a script
main()