Rename output.device -> port; wpaperd: use output port

This commit is contained in:
Adam Gausmann 2025-03-20 10:24:47 -05:00
parent 51da9745fa
commit 1d0f2610f8

View file

@ -90,7 +90,7 @@ class OutputConfig:
scale: float | None = None
background_path: str | None = None
background_mode: BackgroundMode = BackgroundMode.Fill
device: str | None = None
port: str | None = None
@property
def sway_lines(self) -> str:
@ -108,12 +108,12 @@ class OutputConfig:
@property
def swaylock_image_line(self) -> str | None:
if (self.match != "*" and self.device is None) or self.background_path is None:
if (self.match != "*" and self.port is None) or self.background_path is None:
return None
if self.match == "*":
return f"image={self.background_path}"
return f"image={self.device}:{self.background_path}"
return f"image={self.port}:{self.background_path}"
@property
def niri_lines(self) -> str:
@ -132,8 +132,9 @@ class OutputConfig:
if self.background_path is None:
return {}
key = self.match
if key == "*":
# TODO: match by serial number instead of by port
key = self.port
if self.match == "*":
key = "any"
return {
@ -228,7 +229,7 @@ def main():
host_config = cattrs.structure(host_toml, HostConfig)
for output in host_config.outputs:
# Attempt to resolve device names for swaylock template
# 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
@ -242,9 +243,9 @@ def main():
["swaymsg", "-t", "get_outputs", "-p"],
).decode("utf-8")
for line in get_outputs.splitlines():
# Line format: Output <device> '<match identifier>'
# Line format: Output <port> '<match identifier>'
if line.startswith("Output") and output.match in line:
output.device = line.split()[1]
output.port = line.split()[1]
break
elif "NIRI_SOCKET" in os.environ:
@ -252,9 +253,9 @@ def main():
["niri", "msg", "outputs"],
).decode("utf-8")
for line in get_outputs.splitlines():
# Line format: Output "<match identifier>" (<device>)
# Line format: Output "<match identifier>" (<port>)
if line.startswith("Output") and output.match in line:
output.device = (
output.port = (
line.split()[-1].removeprefix("(").removesuffix(")")
)
break