From 937430b70e0780c37921b1ca7ff56b15ef18f371 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 28 Oct 2026 19:33:26 -0700 Subject: [PATCH] feat(e2e): the wallpaper members and put_file on the Windows guest put_file writes bytes to a path in the guest (a folder that has a space in its name is made), wallpaper and set_wallpaper read and set the wallpaper of a display through IDesktopWallpaper, with the COM calls in C# compiled by Add-Type (wallpaper.ps1). --- .../qemu_windows/tests/test_runner.py | 29 ++++++++++++ e2e/platforms/qemu_windows/wallpaper.ps1 | 46 +++++++++++++++++++ .../qemu_windows/windows_platform.py | 33 +++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 e2e/platforms/qemu_windows/wallpaper.ps1 diff --git a/e2e/platforms/qemu_windows/tests/test_runner.py b/e2e/platforms/qemu_windows/tests/test_runner.py index fc697ae7..e9981698 100644 --- a/e2e/platforms/qemu_windows/tests/test_runner.py +++ b/e2e/platforms/qemu_windows/tests/test_runner.py @@ -165,6 +165,7 @@ class _Agent: def __init__(self, titles: list[str]) -> None: self.titles = titles self.spawned: list[tuple[str, ...]] = [] + self.put: list[tuple[str, bytes]] = [] self.executed: list[tuple[str, ...]] = [] def os_windows(self) -> list[dict]: @@ -175,6 +176,9 @@ class _Agent: def spawn(self, *args: str) -> None: self.spawned.append(args) + def put_file(self, local: Path, remote: str) -> None: + self.put.append((remote, local.read_bytes() if local.exists() else b"")) + def exec(self, *args: str) -> dict: self.executed.append(args) return {"status": 0, "stdout": "", "stderr": ""} @@ -295,3 +299,28 @@ def test_the_press_points_of_a_resize_are_outside_but_for_the_top() -> None: assert platform.resize_grab(frame, "topleft") == (653, 395) assert platform.resize_grab(frame, "topright") == (1257, 395) assert platform.resize_grab(frame, "bottomright") == (1257, 729) + + +def test_a_file_is_put_in_a_folder_that_has_a_space(tmp_path: Path) -> None: + agent = _Agent([]) + platform = WindowsPlatform(SimpleNamespace(), agent, tmp_path) + path = "C:\\e2e\\tmp\\wallpapers\\my pictures\\cool.png" + + platform.put_file(path, b"png") + + assert agent.put == [(path, b"png")] + assert "C:\\e2e\\tmp\\wallpapers\\my pictures" in agent.executed[0][-1] + + +def test_the_wallpaper_is_asked_of_the_shell_for_a_display() -> None: + agent = _Agent([]) + agent.exec = lambda *args: ( + agent.executed.append(args) or {"status": 0, "stdout": "C:\\w.png\r\n", "stderr": ""} + ) + platform = WindowsPlatform(SimpleNamespace(), agent, Path(".")) + + assert platform.wallpaper(1) == "C:\\w.png" + platform.set_wallpaper("C:\\x y.png", 1) + + assert agent.executed[-2][-2:] == ("get", "1") + assert agent.executed[-1][-3:] == ("set", "1", "C:\\x y.png") diff --git a/e2e/platforms/qemu_windows/wallpaper.ps1 b/e2e/platforms/qemu_windows/wallpaper.ps1 new file mode 100644 index 00000000..6c17367b --- /dev/null +++ b/e2e/platforms/qemu_windows/wallpaper.ps1 @@ -0,0 +1,46 @@ +# usage: powershell -File wallpaper.ps1 get DISPLAY +# powershell -File wallpaper.ps1 set DISPLAY PATH +# Prints or sets the wallpaper of the monitor DISPLAY (0 is the first), through +# the IDesktopWallpaper interface of the shell. +param([string]$Command = "get", [int]$Display = 0, [string]$Path = "") + +Add-Type @" +using System; +using System.Runtime.InteropServices; + +[ComImport, Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +interface IDesktopWallpaper { + void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID, + [MarshalAs(UnmanagedType.LPWStr)] string wallpaper); + [return: MarshalAs(UnmanagedType.LPWStr)] + string GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID); + [return: MarshalAs(UnmanagedType.LPWStr)] + string GetMonitorDevicePathAt(uint monitorIndex); + uint GetMonitorDevicePathCount(); +} + +[ComImport, Guid("C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD")] +class DesktopWallpaperClass {} + +public static class Wallpaper { + static IDesktopWallpaper Open() { + return (IDesktopWallpaper)new DesktopWallpaperClass(); + } + public static string Get(int display) { + var w = Open(); + return w.GetWallpaper(w.GetMonitorDevicePathAt((uint)display)); + } + public static void Set(int display, string path) { + var w = Open(); + w.SetWallpaper(w.GetMonitorDevicePathAt((uint)display), path); + } +} +"@ + +if ($Command -eq "get") { + [Wallpaper]::Get($Display) +} elseif ($Command -eq "set") { + [Wallpaper]::Set($Display, $Path) + "set" +} diff --git a/e2e/platforms/qemu_windows/windows_platform.py b/e2e/platforms/qemu_windows/windows_platform.py index ac7724a6..7c1e93ec 100644 --- a/e2e/platforms/qemu_windows/windows_platform.py +++ b/e2e/platforms/qemu_windows/windows_platform.py @@ -45,6 +45,7 @@ WM_FULLSCREEN = 0x8000 + 2 WM_SYSCOMMAND = 0x0112 SC_MAXIMIZE = 0xF030 SC_RESTORE = 0xF120 +WALLPAPER_SCRIPT = "C:\\e2e\\wallpaper.ps1" DISPLAY_SCRIPT = "C:\\e2e\\display.ps1" CONFIG_PATH = "C:\\e2e\\komorebi.json" @@ -106,6 +107,7 @@ class WindowsPlatform: self._out = out self._scale = scale self._display_script = False + self._wallpaper_script = False self._daemon_pid: int | None = None self.start_notes: list[str] = [] self._pointer = WindowsPointer(qmp, agent) @@ -234,6 +236,37 @@ class WindowsPlatform: self._agent.exec("cmd", "/c", f"mkdir {TEMP_DIR} 2>nul") return f"{TEMP_DIR}\\{name}" + def put_file(self, path: str, data: bytes) -> None: + parent = path.rsplit("\\", 1)[0] + self._agent.exec( + "powershell", "-NoProfile", "-Command", + f"New-Item -ItemType Directory -Force -Path '{parent}' | Out-Null", + ) + local = self._out / "put_file.tmp" + local.write_bytes(data) + self._agent.put_file(local, path) + + def _wallpaper(self, *args: str) -> str: + if not self._wallpaper_script: + self._agent.exec("cmd", "/c", "mkdir C:\\e2e 2>nul") + self._agent.put_file( + Path(__file__).parent / "wallpaper.ps1", WALLPAPER_SCRIPT + ) + self._wallpaper_script = True + result = self._agent.exec( + "powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", + "-File", WALLPAPER_SCRIPT, *args, + ) + if result["status"] != 0: + raise RuntimeError(f"wallpaper {args}: {result['stderr'] or result}") + return result["stdout"].strip() + + def wallpaper(self, display: int = 0) -> str: + return self._wallpaper("get", str(display)) + + def set_wallpaper(self, path: str, display: int = 0) -> None: + self._wallpaper("set", str(display), path) + def crash(self) -> None: # a process that is killed puts nothing back: windows it cloaked stay so self._agent.exec("taskkill", "/F", "/IM", "komorebi.exe")