From a4c9f59091509106cb15b7d2aa64fc89a5ebac95 Mon Sep 17 00:00:00 2001 From: Adam Gausmann Date: Thu, 15 May 2025 12:49:35 -0500 Subject: [PATCH] fix wpaperd ports; only query compositor for outputs one time --- install.py | 68 +++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/install.py b/install.py index ef2f691..6c592f3 100755 --- a/install.py +++ b/install.py @@ -131,7 +131,9 @@ class OutputConfig: if self.background_path is None: return {} - key = self.match + # FIXME: output descriptions _should_ work? + # https://github.com/danyspin97/wpaperd/pull/97 + key = self.port or self.match if self.match == "*": key = "any" @@ -234,6 +236,35 @@ def main(): host_config = cattrs.structure(host_toml, HostConfig) + output_map = [] + try: + if "SWAYSOCK" in os.environ: + get_outputs = subprocess.check_output( + ["swaymsg", "-t", "get_outputs", "-p"], + ).decode("utf-8") + for line in get_outputs.splitlines(): + # Line format: Output '' + if line.startswith("Output"): + output_map.append((line, line.split()[1])) + + elif "NIRI_SOCKET" in os.environ: + get_outputs = subprocess.check_output( + ["niri", "msg", "outputs"], + ).decode("utf-8") + for line in get_outputs.splitlines(): + # Line format: Output "" () + if line.startswith("Output"): + output_map.append((line, line.split()[-1].removeprefix("(").removesuffix(")"))) + else: + print( + "Could not find SWAYSOCK or NIRI_SOCKET, cannot retrieve output names." + ) + print("Please re-run in sway or niri to finish configuring swaylock.") + + except subprocess.CalledProcessError: + print("Could not contact sway or niri to retrieve output names.") + print("Please re-run in sway or niri to finish configuring swaylock.") + for output in host_config.outputs: # Attempt to resolve port names for swaylock template # (Workaround https://github.com/swaywm/swaylock/issues/114) @@ -243,37 +274,10 @@ def main(): if output.match == "*": continue - try: - if "SWAYSOCK" in os.environ: - get_outputs = subprocess.check_output( - ["swaymsg", "-t", "get_outputs", "-p"], - ).decode("utf-8") - for line in get_outputs.splitlines(): - # Line format: Output '' - if line.startswith("Output") and output.match in line: - output.port = line.split()[1] - break - - elif "NIRI_SOCKET" in os.environ: - get_outputs = subprocess.check_output( - ["niri", "msg", "outputs"], - ).decode("utf-8") - for line in get_outputs.splitlines(): - # Line format: Output "" () - if line.startswith("Output") and output.match in line: - output.port = ( - line.split()[-1].removeprefix("(").removesuffix(")") - ) - break - else: - print( - "Could not find SWAYSOCK or NIRI_SOCKET, cannot retrieve output names." - ) - print("Please re-run in sway or niri to finish configuring swaylock.") - - except subprocess.CalledProcessError: - print("Could not contact sway or niri to retrieve output names.") - print("Please re-run in sway or niri to finish configuring swaylock.") + for haystack, port in output_map: + if output.match in haystack: + output.port = port + break jenv = jinja2.Environment( loader=jinja2.FileSystemLoader("templates"),