fix wpaperd ports; only query compositor for outputs one time

This commit is contained in:
Adam Gausmann 2025-05-15 12:49:35 -05:00
parent 7de71dd986
commit a4c9f59091

View file

@ -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,15 +236,7 @@ def main():
host_config = cattrs.structure(host_toml, HostConfig)
for output in host_config.outputs:
# Attempt to resolve port names for swaylock template
# (Workaround https://github.com/swaywm/swaylock/issues/114)
#
# This will only work if this is run on the target host
# and if sway or niri is running, but that is usually the case...
if output.match == "*":
continue
output_map = []
try:
if "SWAYSOCK" in os.environ:
get_outputs = subprocess.check_output(
@ -250,9 +244,8 @@ def main():
).decode("utf-8")
for line in get_outputs.splitlines():
# Line format: Output <port> '<match identifier>'
if line.startswith("Output") and output.match in line:
output.port = line.split()[1]
break
if line.startswith("Output"):
output_map.append((line, line.split()[1]))
elif "NIRI_SOCKET" in os.environ:
get_outputs = subprocess.check_output(
@ -260,11 +253,8 @@ def main():
).decode("utf-8")
for line in get_outputs.splitlines():
# Line format: Output "<match identifier>" (<port>)
if line.startswith("Output") and output.match in line:
output.port = (
line.split()[-1].removeprefix("(").removesuffix(")")
)
break
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."
@ -275,6 +265,20 @@ def main():
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)
#
# This will only work if this is run on the target host
# and if sway or niri is running, but that is usually the case...
if output.match == "*":
continue
for haystack, port in output_map:
if output.match in haystack:
output.port = port
break
jenv = jinja2.Environment(
loader=jinja2.FileSystemLoader("templates"),
autoescape=jinja2.select_autoescape(),