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 scale: float | None = None
background_path: str | None = None background_path: str | None = None
background_mode: BackgroundMode = BackgroundMode.Fill background_mode: BackgroundMode = BackgroundMode.Fill
device: str | None = None port: str | None = None
@property @property
def sway_lines(self) -> str: def sway_lines(self) -> str:
@ -108,12 +108,12 @@ class OutputConfig:
@property @property
def swaylock_image_line(self) -> str | None: 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 return None
if self.match == "*": if self.match == "*":
return f"image={self.background_path}" return f"image={self.background_path}"
return f"image={self.device}:{self.background_path}" return f"image={self.port}:{self.background_path}"
@property @property
def niri_lines(self) -> str: def niri_lines(self) -> str:
@ -132,8 +132,9 @@ class OutputConfig:
if self.background_path is None: if self.background_path is None:
return {} return {}
key = self.match # TODO: match by serial number instead of by port
if key == "*": key = self.port
if self.match == "*":
key = "any" key = "any"
return { return {
@ -228,7 +229,7 @@ def main():
host_config = cattrs.structure(host_toml, HostConfig) host_config = cattrs.structure(host_toml, HostConfig)
for output in host_config.outputs: 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) # (Workaround https://github.com/swaywm/swaylock/issues/114)
# #
# This will only work if this is run on the target host # This will only work if this is run on the target host
@ -242,9 +243,9 @@ def main():
["swaymsg", "-t", "get_outputs", "-p"], ["swaymsg", "-t", "get_outputs", "-p"],
).decode("utf-8") ).decode("utf-8")
for line in get_outputs.splitlines(): 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: if line.startswith("Output") and output.match in line:
output.device = line.split()[1] output.port = line.split()[1]
break break
elif "NIRI_SOCKET" in os.environ: elif "NIRI_SOCKET" in os.environ:
@ -252,9 +253,9 @@ def main():
["niri", "msg", "outputs"], ["niri", "msg", "outputs"],
).decode("utf-8") ).decode("utf-8")
for line in get_outputs.splitlines(): 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: if line.startswith("Output") and output.match in line:
output.device = ( output.port = (
line.split()[-1].removeprefix("(").removesuffix(")") line.split()[-1].removeprefix("(").removesuffix(")")
) )
break break