From ead3d91e378f01bf641bee61672088089d42f2c4 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 28 Oct 2026 19:33:26 -0700 Subject: [PATCH] fix(e2e): vendor the fake wallpaper that the focus and moving tests import --- e2e/lib/tests/fake_wallpaper.py | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 e2e/lib/tests/fake_wallpaper.py diff --git a/e2e/lib/tests/fake_wallpaper.py b/e2e/lib/tests/fake_wallpaper.py new file mode 100644 index 00000000..ca640c54 --- /dev/null +++ b/e2e/lib/tests/fake_wallpaper.py @@ -0,0 +1,64 @@ +"""A fake that sets wallpapers from the configuration it is started with, shows them on its +screenshots, and draws a ring around the focused window in a hue of the wallpaper.""" + +from typing import Any + +from PIL import Image, ImageDraw + +from komorebi_vm.core.platform import Client +from tests.fake_platform import FakePlatform + +HUES = {"warm": (230, 40, 40), "cool": (40, 60, 230), "other": (60, 230, 60)} + + +# the ring is the 4 pixels of the wallpaper's hue that the window leaves at its left +class FakeWallpaper(FakePlatform): + def __init__(self, *args, **kwargs) -> None: # noqa: ANN002, ANN003 + super().__init__(*args, **kwargs) + self.shown = "" + self.monitor_wallpaper = "" + self.workspace_wallpapers: dict[int, str] = {} + self.workspace = 0 + self.puts_back = True + + def put_file(self, path: str, data: bytes) -> None: + assert data.startswith(b"\x89PNG"), "a picture" + + def wallpaper(self, display: int = 0) -> str: + return self.shown + + def set_wallpaper(self, path: str, display: int = 0) -> None: + self.shown = path + + def restart_with(self, config: dict[str, Any]) -> None: + self.running = True + monitor = config["monitors"][0] + self.monitor_wallpaper = monitor["wallpaper"]["path"] + self.workspace_wallpapers = { + i: w["wallpaper"]["path"] + for i, w in enumerate(monitor["workspaces"]) + if "wallpaper" in w + } + self._show() + + def _show(self) -> None: + self.shown = self.workspace_wallpapers.get(self.workspace, self.monitor_wallpaper) + + def komorebic(self, *args: str) -> str: + if args[0] == "focus-workspace": + self.workspace = int(args[1]) + if self.puts_back or self.shown != self.wallpaper(): + self._show() + return "" + return super().komorebic(*args) + + def screenshot(self, name: str) -> Image.Image: + which = "other" if "other" in self.shown else "cool" if "cool" in self.shown else "warm" + image = Image.new("RGB", (1920, 1080), HUES[which]) + draw = ImageDraw.Draw(image) + for client in (Client(t) for c in self.containers for t in c): + window = self.os_window(client) + if window is not None and window.focused: + f = window.frame + draw.rectangle((f.x + 4, f.y, f.x + f.w, f.y + f.h), fill=(48, 48, 48)) + return image