Jelajahi Sumber

Cinnamon should be fixed now

UwU 1 bulan lalu
induk
melakukan
b1b6e8baf4

+ 1 - 0
README.md

@@ -175,6 +175,7 @@ The background can be a Steam Workshop ID (`1845706469`) or a path to a backgrou
 | `--no-audio-processing` | Disable audio reactive features |
 | `--fps <val>` | Limit frame rate |
 | `--window <XxYxWxH>` | Run in windowed mode with custom size/position |
+| `--window-background` | X11 only, with `--window`: the window acts as the desktop background (desktop type, below every other window, on all workspaces, off the taskbar, never focused, clicks go through, desktop icons stay above it). For desktops that don't show a root window wallpaper, e.g. some Cinnamon setups |
 | `--screen-root <screen>` | Set as background for a specific screen |
 | `--screen-span <screen-1>,<screen-2>,...` | Stretch a single wallpaper across multiple screens |
 | `--screen-slot <screen>` | Add a slot to a screen, once per wallpaper, so several share it side by side (stacked on a portrait screen); the following `--bg`, `--scaling`, etc. apply to that slot, called `<screen>#<n>` |

+ 9 - 0
src/WallpaperEngine/Application/ApplicationContext.cpp

@@ -1111,6 +1111,15 @@ void ApplicationContext::loadSettingsFromArgv () {
 	    this->settings.render.pauseOnFullscreenOnlyWhenActive = true;
 	});
 
+    backgroundGroup.add_argument ("--window-background")
+	.help (
+	    "X11 only, with --window: make the window behave like the desktop background. It becomes a desktop type "
+	    "window below every other window, on all workspaces, off the taskbar, never focused and transparent to "
+	    "clicks. For desktops that don't show a root window wallpaper"
+	)
+	.flag ()
+	.action ([this] (const std::string& value) -> void { this->settings.render.window.asBackground = true; });
+
     performanceGroup.add_argument ("--pause-on-focus")
 	.help (
 	    "Also pause while another application has the focus (Wallpaper Engine's \"Other application focused\" "

+ 2 - 0
src/WallpaperEngine/Application/ApplicationContext.h

@@ -183,6 +183,7 @@ public:
 		WallpaperEngine::Render::WallpaperState::Alignment alignment;
 		glm::vec4 cornerColor;
 		WallpaperEngine::Data::Model::ImageAdjustments imageAdjustments;
+		bool asBackground;
 	    } window;
 
 	    struct {
@@ -284,6 +285,7 @@ public:
                 .alignment = {},
                 .cornerColor = { 0.0f, 0.0f, 0.0f, 1.0f },
                 .imageAdjustments = {},
+                .asBackground = false,
             },
             .wayland = {
                 .layer = WAYLAND_LAYER_BOTTOM,

+ 39 - 1
src/WallpaperEngine/Input/Drivers/GLFWMouseInput.cpp

@@ -3,6 +3,8 @@
 
 #include "WallpaperEngine/Render/Drivers/GLFWOpenGLDriver.h"
 
+#include <X11/Xlib.h>
+
 using namespace WallpaperEngine::Input::Drivers;
 
 GLFWMouseInput::GLFWMouseInput (const Render::Drivers::GLFWOpenGLDriver& driver) : m_driver (driver) { }
@@ -13,6 +15,14 @@ void GLFWMouseInput::update () {
 	return;
     }
 
+    const auto& render = this->m_driver.getApp ().getContext ().settings.render;
+
+    // a background window is click through and under everything, so GLFW never sees the pointer
+    if (render.window.asBackground && render.mode == Application::ApplicationContext::EXPLICIT_WINDOW
+	&& this->updateFromRoot ()) {
+	return;
+    }
+
     const int leftClickState = glfwGetMouseButton (this->m_driver.getWindow (), GLFW_MOUSE_BUTTON_LEFT);
     const int rightClickState = glfwGetMouseButton (this->m_driver.getWindow (), GLFW_MOUSE_BUTTON_RIGHT);
 
@@ -32,4 +42,32 @@ glm::dvec2 GLFWMouseInput::position () const { return this->m_reportedPosition;
 
 WallpaperEngine::Input::MouseClickStatus GLFWMouseInput::leftClick () const { return m_leftClick; }
 
-WallpaperEngine::Input::MouseClickStatus GLFWMouseInput::rightClick () const { return m_rightClick; }
+WallpaperEngine::Input::MouseClickStatus GLFWMouseInput::rightClick () const { return m_rightClick; }
+bool GLFWMouseInput::updateFromRoot () {
+    auto* display = static_cast<Display*> (this->m_driver.getX11Display ());
+
+    if (display == nullptr) {
+	return false;
+    }
+
+    Window rootReturn = 0, child = 0;
+    int rootX = 0, rootY = 0, childX = 0, childY = 0;
+    unsigned int mask = 0;
+
+    if (!XQueryPointer (
+	    display, DefaultRootWindow (display), &rootReturn, &child, &rootX, &rootY, &childX, &childY, &mask
+	)) {
+	return false;
+    }
+
+    const auto& geometry = this->m_driver.getApp ().getContext ().settings.render.window.geometry;
+    const glm::ivec2 framebufferSize = this->m_driver.getFramebufferSize ();
+
+    this->m_leftClick = (mask & Button1Mask) ? MouseClickStatus::Clicked : MouseClickStatus::Released;
+    this->m_rightClick = (mask & Button3Mask) ? MouseClickStatus::Clicked : MouseClickStatus::Released;
+    this->m_mousePosition
+	= { static_cast<double> (rootX - geometry.x), static_cast<double> (framebufferSize.y) - (rootY - geometry.y) };
+    this->m_reportedPosition = this->m_mousePosition;
+
+    return true;
+}

+ 2 - 0
src/WallpaperEngine/Input/Drivers/GLFWMouseInput.h

@@ -20,6 +20,8 @@ public:
     [[nodiscard]] MouseClickStatus rightClick () const override;
 
 private:
+    bool updateFromRoot ();
+
     const Render::Drivers::GLFWOpenGLDriver& m_driver;
 
     glm::dvec2 m_mousePosition = {};

+ 267 - 8
src/WallpaperEngine/Render/Drivers/Output/GLFWWindowOutput.cpp

@@ -4,6 +4,13 @@
 #include <GL/glew.h>
 #include <GLFW/glfw3.h>
 
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/shape.h>
+
+#include <algorithm>
+#include <cstdlib>
 #include <unistd.h>
 
 using namespace WallpaperEngine::Render::Drivers::Output;
@@ -14,12 +21,26 @@ GLFWWindowOutput::GLFWWindowOutput (ApplicationContext& context, VideoDriver& dr
 	sLog.exception ("Initializing window output when not in output mode, how did you get here?!");
     }
 
-    driver.showWindow ();
+    const bool background = this->m_context.settings.render.mode == Application::ApplicationContext::EXPLICIT_WINDOW
+	&& this->m_context.settings.render.window.asBackground;
+
+    if (background && driver.getX11Display () == nullptr) {
+	sLog.error ("--window-background only works on X11, the window stays a normal one");
+    }
+
+    // the GL window stays hidden for a background window, it only renders
+    if (!background || driver.getX11Display () == nullptr) {
+	driver.showWindow ();
+    }
 
     if (this->m_context.settings.render.mode == Application::ApplicationContext::EXPLICIT_WINDOW) {
 	this->m_fullWidth = this->m_context.settings.render.window.geometry.z;
 	this->m_fullHeight = this->m_context.settings.render.window.geometry.w;
 	this->repositionWindow ();
+
+	if (background && driver.getX11Display () != nullptr) {
+	    this->createBackgroundWindow ();
+	}
     } else {
 	this->m_fullWidth = this->m_driver.getFramebufferSize ().x;
 	this->m_fullHeight = this->m_driver.getFramebufferSize ().y;
@@ -30,6 +51,8 @@ GLFWWindowOutput::GLFWWindowOutput (ApplicationContext& context, VideoDriver& dr
 }
 
 GLFWWindowOutput::~GLFWWindowOutput () {
+    this->destroyBackgroundWindow ();
+
     for (const auto& [name, viewport] : this->m_viewports) {
 	delete viewport;
     }
@@ -45,20 +68,256 @@ void GLFWWindowOutput::reset () {
     }
 }
 
-bool GLFWWindowOutput::renderVFlip () const { return true; }
+void GLFWWindowOutput::createBackgroundWindow () {
+    // A GL window can't sit below Cinnamon's desktop icons (it is composited over nemo-desktop whatever the
+    // stacking says), a plain X window can. So this one only gets the finished frames, like the root window does
+    Display* display = XOpenDisplay (nullptr);
+    this->m_display = display;
+
+    if (display == nullptr) {
+	sLog.error ("Cannot open the X display for the background window");
+	return;
+    }
+
+    const auto& geometry = this->m_context.settings.render.window.geometry;
+    const int screen = DefaultScreen (display);
+
+    XSetWindowAttributes attributes {};
+    attributes.background_pixel = BlackPixel (display, screen);
+    attributes.border_pixel = 0;
+
+    const Window window = XCreateWindow (
+	display, RootWindow (display, screen), geometry.x, geometry.y, geometry.z, geometry.w, 0, CopyFromParent,
+	InputOutput, CopyFromParent, CWBackPixel | CWBorderPixel, &attributes
+    );
+
+    const auto atom = [display] (const char* name) { return XInternAtom (display, name, False); };
+
+    const Atom type = atom ("_NET_WM_WINDOW_TYPE_DESKTOP");
+    XChangeProperty (
+	display, window, atom ("_NET_WM_WINDOW_TYPE"), XA_ATOM, 32, PropModeReplace,
+	reinterpret_cast<const unsigned char*> (&type), 1
+    );
+
+    const Atom states[]
+	= { atom ("_NET_WM_STATE_STICKY"), atom ("_NET_WM_STATE_SKIP_TASKBAR"), atom ("_NET_WM_STATE_SKIP_PAGER") };
+    XChangeProperty (
+	display, window, atom ("_NET_WM_STATE"), XA_ATOM, 32, PropModeReplace,
+	reinterpret_cast<const unsigned char*> (states), 3
+    );
+
+    const unsigned long allDesktops = 0xFFFFFFFF;
+    XChangeProperty (
+	display, window, atom ("_NET_WM_DESKTOP"), XA_CARDINAL, 32, PropModeReplace,
+	reinterpret_cast<const unsigned char*> (&allDesktops), 1
+    );
+
+    const unsigned long pid = getpid ();
+    XChangeProperty (
+	display, window, atom ("_NET_WM_PID"), XA_CARDINAL, 32, PropModeReplace,
+	reinterpret_cast<const unsigned char*> (&pid), 1
+    );
+
+    // never takes the focus
+    XWMHints wmHints {};
+    wmHints.flags = InputHint;
+    wmHints.input = False;
+    XSetWMHints (display, window, &wmHints);
+
+    // undecorated
+    const unsigned long motif[] = { 2, 0, 0, 0, 0 };
+    XChangeProperty (
+	display, window, atom ("_MOTIF_WM_HINTS"), atom ("_MOTIF_WM_HINTS"), 32, PropModeReplace,
+	reinterpret_cast<const unsigned char*> (motif), 5
+    );
+
+    // like the other X windows of ours, the clicks go to what is below
+    XShapeCombineRectangles (display, window, ShapeInput, 0, 0, nullptr, 0, ShapeSet, Unsorted);
+
+    char name[] = "linux-wallpaperengine";
+    XClassHint classHint { name, name };
+    XSetClassHint (display, window, &classHint);
+    XStoreName (display, window, "wallpaperengine");
+
+    this->m_background = window;
+    this->m_gc = XCreateGC (display, window, 0, nullptr);
+    this->m_imageSize = this->m_fullWidth * this->m_fullHeight * 4;
+    // XDestroyImage () frees this with free ()
+    this->m_imageData = static_cast<char*> (malloc (this->m_imageSize));
+    this->m_image = XCreateImage (
+	display, CopyFromParent, 24, ZPixmap, 0, this->m_imageData, this->m_fullWidth, this->m_fullHeight, 32, 0
+    );
+
+    XMapWindow (display, window);
+    XFlush (display);
+}
+
+void GLFWWindowOutput::destroyBackgroundWindow () {
+    auto* display = static_cast<Display*> (this->m_display);
+
+    if (display == nullptr) {
+	return;
+    }
+
+    if (this->m_image != nullptr) {
+	// frees m_imageData as well
+	XDestroyImage (static_cast<XImage*> (this->m_image));
+	this->m_image = nullptr;
+	this->m_imageData = nullptr;
+    }
+
+    if (this->m_nudge != 0) {
+	XDestroyWindow (display, this->m_nudge);
+	this->m_nudge = 0;
+    }
+
+    if (this->m_gc != nullptr) {
+	XFreeGC (display, static_cast<GC> (this->m_gc));
+	this->m_gc = nullptr;
+    }
+
+    if (this->m_background != 0) {
+	XDestroyWindow (display, this->m_background);
+	this->m_background = 0;
+    }
+
+    XCloseDisplay (display);
+    this->m_display = nullptr;
+}
+
+bool GLFWWindowOutput::desktopWindowBelowUs () const {
+    auto* display = static_cast<Display*> (this->m_display);
+    const Atom listAtom = XInternAtom (display, "_NET_CLIENT_LIST_STACKING", False);
+    const Atom typeAtom = XInternAtom (display, "_NET_WM_WINDOW_TYPE", False);
+    const Atom desktopAtom = XInternAtom (display, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
+    Atom type;
+    int format;
+    unsigned long count = 0, remaining;
+    unsigned char* data = nullptr;
+    bool below = false;
+
+    if (XGetWindowProperty (
+	    display, DefaultRootWindow (display), listAtom, 0, 4096, False, XA_WINDOW, &type, &format, &count,
+	    &remaining, &data
+	) != Success
+	|| data == nullptr || format != 32) {
+	return false;
+    }
+
+    // bottom to top
+    const auto* windows = reinterpret_cast<const Window*> (data);
+    unsigned long ours = count;
+
+    for (unsigned long i = 0; i < count; i++) {
+	if (windows[i] == this->m_background) {
+	    ours = i;
+	}
+    }
+
+    for (unsigned long i = 0; i < ours && !below; i++) {
+	Atom windowType;
+	int windowFormat;
+	unsigned long typeCount, typeRemaining;
+	unsigned char* typeData = nullptr;
+
+	if (XGetWindowProperty (
+		display, windows[i], typeAtom, 0, 16, False, XA_ATOM, &windowType, &windowFormat, &typeCount,
+		&typeRemaining, &typeData
+	    ) == Success
+	    && typeData != nullptr && windowFormat == 32) {
+	    const auto* atoms = reinterpret_cast<const Atom*> (typeData);
+	    below = std::find (atoms, atoms + typeCount, desktopAtom) != atoms + typeCount;
+	}
+
+	if (typeData != nullptr) {
+	    XFree (typeData);
+	}
+    }
+
+    XFree (data);
+
+    return below;
+}
+
+void GLFWWindowOutput::keepBackgroundWindowLow () const {
+    auto* display = static_cast<Display*> (this->m_display);
+    const uint32_t tick = this->m_updates++;
+
+    if (this->m_nudge != 0 && tick >= this->m_nudgeUntil) {
+	XDestroyWindow (display, this->m_nudge);
+	this->m_nudge = 0;
+    }
+
+    if (tick % 60 != 5 || this->m_nudge != 0 || !this->desktopWindowBelowUs ()) {
+	return;
+    }
+
+    // Desktop windows stack by age and nemo-desktop is one too, so ours goes below it. Muffin keeps those in a group
+    // of their own and only syncs it to the new order when a normal window changes the stacking as well, which on an
+    // empty desktop never happens. A normal window, invisible and gone again a moment later, makes it happen.
+    XLowerWindow (display, this->m_background);
+
+    XSetWindowAttributes attributes {};
+    attributes.background_pixel = BlackPixel (display, DefaultScreen (display));
+    const Window nudge = XCreateWindow (
+	display, DefaultRootWindow (display), 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel,
+	&attributes
+    );
+
+    const auto atom = [display] (const char* name) { return XInternAtom (display, name, False); };
+    const unsigned long transparent = 0;
+    XChangeProperty (
+	display, nudge, atom ("_NET_WM_WINDOW_OPACITY"), XA_CARDINAL, 32, PropModeReplace,
+	reinterpret_cast<const unsigned char*> (&transparent), 1
+    );
+    const Atom states[] = { atom ("_NET_WM_STATE_SKIP_TASKBAR"), atom ("_NET_WM_STATE_SKIP_PAGER") };
+    XChangeProperty (
+	display, nudge, atom ("_NET_WM_STATE"), XA_ATOM, 32, PropModeReplace,
+	reinterpret_cast<const unsigned char*> (states), 2
+    );
+    XWMHints wmHints {};
+    wmHints.flags = InputHint;
+    wmHints.input = False;
+    XSetWMHints (display, nudge, &wmHints);
+    XShapeCombineRectangles (display, nudge, ShapeInput, 0, 0, nullptr, 0, ShapeSet, Unsorted);
+
+    XMapWindow (display, nudge);
+    this->m_nudge = nudge;
+    this->m_nudgeUntil = tick + 6;
+}
+
+bool GLFWWindowOutput::renderVFlip () const { return this->m_image == nullptr; }
 
 bool GLFWWindowOutput::renderMultiple () const { return false; }
 
-bool GLFWWindowOutput::haveImageBuffer () const { return false; }
+bool GLFWWindowOutput::haveImageBuffer () const { return this->m_image != nullptr; }
 
-void* GLFWWindowOutput::getImageBuffer () const { return nullptr; }
+void* GLFWWindowOutput::getImageBuffer () const { return this->m_imageData; }
 
-uint32_t GLFWWindowOutput::getImageBufferSize () const { return 0; }
+uint32_t GLFWWindowOutput::getImageBufferSize () const { return this->m_imageSize; }
 
 void GLFWWindowOutput::updateRender () const {
-    // re-read every frame so window resizes re-stretch the scene instead of cropping it
-    this->m_fullWidth = this->m_driver.getFramebufferSize ().x;
-    this->m_fullHeight = this->m_driver.getFramebufferSize ().y;
+    // re-read every frame so window resizes re-stretch the scene instead of cropping it, the image buffer of a
+    // background window has a fixed size
+    if (this->m_image == nullptr) {
+	this->m_fullWidth = this->m_driver.getFramebufferSize ().x;
+	this->m_fullHeight = this->m_driver.getFramebufferSize ().y;
+    }
 
     this->m_viewports["default"]->viewport = { 0, 0, this->m_fullWidth, this->m_fullHeight };
+
+    if (this->m_image == nullptr) {
+	return;
+    }
+
+    auto* display = static_cast<Display*> (this->m_display);
+
+    XPutImage (
+	display, this->m_background, static_cast<GC> (this->m_gc), static_cast<XImage*> (this->m_image), 0, 0, 0, 0,
+	this->m_fullWidth, this->m_fullHeight
+    );
+
+    this->keepBackgroundWindowLow ();
+
+    XFlush (display);
 }

+ 16 - 0
src/WallpaperEngine/Render/Drivers/Output/GLFWWindowOutput.h

@@ -19,5 +19,21 @@ public:
 
 private:
     void repositionWindow () const;
+    void createBackgroundWindow ();
+    void destroyBackgroundWindow ();
+    void keepBackgroundWindowLow () const;
+    bool desktopWindowBelowUs () const;
+
+    // --window-background: the frames go into a plain X window of our own, see createBackgroundWindow
+    // Xlib types are kept out of this header, its macros clash with the rest of the engine
+    void* m_display = nullptr;
+    unsigned long m_background = 0;
+    void* m_gc = nullptr;
+    void* m_image = nullptr;
+    char* m_imageData = nullptr;
+    uint32_t m_imageSize = 0;
+    mutable uint32_t m_updates = 0;
+    mutable unsigned long m_nudge = 0;
+    mutable uint32_t m_nudgeUntil = 0;
 };
 }

+ 70 - 0
tools/linuxvm/RELEASE_TESTING.md

@@ -0,0 +1,70 @@
+# Release testing in the distro VMs
+
+Trigger: when the maintainer says a release is planned, run the whole matrix below, one VM after the other, and report
+before anything is tagged. Nothing here runs on its own schedule.
+
+## What is tested
+
+The release candidate, built the way CI builds it: the engine tarballs (portable, plus the Ubuntu/Fedora/Arch
+distribution builds, `tools/package_release.sh`, built in the proot rootfs under `~/.local/share/distro-rootfs`) and
+we_manager's .deb, AppImage and Flatpak. Wallpapers used everywhere: one scene with parallax (1111948150), one scene with
+particles (1120596121), one video, one preset, two web items (1078208425, 834237690).
+
+## The matrix (a VM per row, `tools/linuxvm/linuxvm.sh`)
+
+| VM | Session | Engine path | Extra checks |
+|----|---------|-------------|--------------|
+| fedora-kde | Plasma Wayland | distribution + Flatpak | KWin script pause (maximized, fullscreen, show desktop), click passthrough |
+| fedora-gnome | GNOME Wayland | distribution | shell extension, per-output pause |
+| ubuntu-gnome | GNOME Wayland | distribution + .deb we_manager | polkit install/update dialog |
+| arch-hypr | Hyprland | portable + AUR packages | layer shell, per-output pause |
+| mint-cinnamon | Cinnamon X11 | portable | `--window-background` (icons above, below windows, sticky), root mode |
+| debian-gnome | GNOME Wayland | portable | |
+| opensuse-tumbleweed-kde | Plasma Wayland | portable | newest libraries |
+| manjaro-kde | Plasma Wayland | portable + AUR | |
+| popos-cosmic | COSMIC | portable | layer shell on cosmic-comp |
+| bazzite | KDE/Gamescope, immutable | portable + Flatpak | rpm-ostree path of we_manager |
+
+Rows are added as the VMs of `TODO.md` -> "Real-session distro VMs" get built. A new distro joins the matrix once its
+VM has a profile and a golden snapshot.
+
+## One VM run
+
+1. Start from the golden snapshot (a throwaway qcow2 overlay, so every run begins clean and the VM is never changed).
+2. Boot headless (`start`), wait for ssh and the desktop session (autologin, inhibit lock/idle as in the profile).
+3. Copy the candidate and the test wallpapers in, install it the way a user does (we_manager install or the package).
+4. Per wallpaper: start, wait for the first frames, take a screenshot inside the guest (`gnome-screenshot`, `spectacle`,
+   `grim` or `cosmic-screenshot` per profile), check it.
+5. Behaviour checks: hotswap to another wallpaper, pause while a window is fullscreen (CPU of the engine drops below
+   3%) and resume, stop leaves no engine, no web host and no stray window or KWin script, autostart entry works.
+6. Collect engine and we_manager logs, powers the VM off, deletes the overlay.
+
+A screenshot passes when the wallpaper area is not black or flat, is not upside down (compare with the reference frame
+of the same wallpaper from `~/.local/share/we_live/refs` or the previous run, tolerance per wallpaper) and the desktop
+icons/panel are still visible where the profile says they must be. A run fails on: engine exit or crash (core, `SIGSEGV`
+in the log), missing frames, black desktop, a leftover process, a log line matching the error list in the profile.
+
+## Automation to build
+
+- `tools/linuxvm/profiles/<vm>.sh`: how to reach the session (env vars for `DISPLAY`/`WAYLAND_DISPLAY`/dbus), the
+  screenshot command, how to install the candidate, which extra checks apply.
+- `tools/linuxvm/release_check.sh [--vm name ...] [--candidate dir]`: loops over the profiles sequentially (RAM, 30 GB,
+  fits one or two VMs), runs `guest_test.sh` in each over ssh, then writes `reports/<date>/summary.md` plus the
+  screenshots and logs, exit code 1 when anything failed.
+- `tools/linuxvm/guest_test.sh`: the per-VM steps above, prints one `PASS/FAIL <check>` line each.
+- `tools/linuxvm/check_frame.py`: black/flat/upside-down/reference comparison (Pillow, run with `-I`).
+- Retry a failed check once before calling it a failure (first-frame timing in VMs is noisy).
+
+## Running it
+
+I start `release_check.sh` in the background and watch it, roughly 10 minutes per VM, so about two hours for ten.
+A failing VM is reported with its screenshot and log excerpt and the matrix carries on with the next one. I do not fix
+and re-tag on my own: the report goes to the maintainer first. Cleanup after a run: all VMs powered off, overlays gone.
+
+## Order of work
+
+1. Finish the first batch of VMs (Debian GNOME, openSUSE Tumbleweed KDE, Manjaro KDE, Pop!_OS COSMIC, Bazzite).
+2. Give every VM a profile and a golden snapshot, starting with the five that exist.
+3. Write `guest_test.sh`, `check_frame.py` and the driver, prove them on Mint and Fedora KDE.
+4. Run the full matrix on the current build, fix what it finds, keep that report as the baseline for comparisons.
+5. Remaining distros from the TODO join the matrix one by one.

+ 57 - 9
tools/linuxvm/linuxvm.sh

@@ -3,10 +3,17 @@
 # namespaces), a real KMS session of a desktop. A VM is a cloud image overlay set up by cloud-init with user "lab"
 # (uid 1000, password "lab", passwordless sudo), reached over ssh on a localhost port. The guest GPU is virtio-vga-gl
 # with QEMU's egl-headless display on the container's render node (virgl), so nothing ever shows on the desktop's
-# display; screenshots and pointer input go through QMP. No audio device.
-#   fetch                 downloads the cloud images (Fedora 44, Arch, Ubuntu 24.04)
-#   create <vm> <image>   new VM from images/<image>.qcow2 (fedora-44, arch, ubuntu-24.04), 60G overlay
+# display; screenshots and pointer input go through QMP. No audio device unless started with `desktop`.
+#   fetch                 downloads the cloud images (Fedora 44, Arch, Ubuntu 24.04, Debian 13, openSUSE Tumbleweed)
+#                         and the installer ISOs (Linux Mint Cinnamon, Manjaro KDE, Pop!_OS, Bazzite)
+#   create <vm> <image>   new VM from images/<image>.qcow2 (fedora-44, arch, ubuntu-24.04, debian-13,
+#                         opensuse-tumbleweed), 60G overlay
+#   create-iso <vm> <iso> blank 60G disk that boots images/<iso>.iso (a distro installer, e.g. linuxmint-22.3-cinnamon);
+#                         remove <vm>/boot.iso after installing. Such a VM has no cloud-init, ssh needs setting up by hand
 #   start <vm>            boots it (LINUXVM_CPUS, LINUXVM_MEM, LINUXVM_SIZE=WxH for the display)
+#   desktop <vm>          boots it in a window on the container's display (GTK, GL, host PipeWire audio, shared
+#                         clipboard with spice-vdagent in the guest) to use it like a normal desktop; same as
+#                         LINUXVM_DISPLAY=window start. Stop a headless run of the VM first
 #   ssh <vm> [cmd]        runs a command as lab (or a shell)
 #   scp <vm> <src> <dst>  copies into the VM (dst relative to /home/lab)
 #   shot <vm> <png>       screenshot through the VNC socket (vncshot.py); pointer/click/keys/type/raw go to qmp.py
@@ -38,9 +45,23 @@ fetch)
     [ -f arch.qcow2 ] || curl -fLo arch.qcow2 https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2
     [ -f ubuntu-24.04.qcow2 ] || curl -fLo ubuntu-24.04.qcow2 \
         https://cloud-images.ubuntu.com/releases/noble/release/ubuntu-24.04-server-cloudimg-amd64.img
+    [ -f debian-13.qcow2 ] || curl -fLo debian-13.qcow2 \
+        https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2
+    [ -f opensuse-tumbleweed.qcow2 ] || curl -fLo opensuse-tumbleweed.qcow2 \
+        https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2
+    [ -f linuxmint-22.3-cinnamon.iso ] || curl -fLo linuxmint-22.3-cinnamon.iso \
+        https://mirrors.kernel.org/linuxmint/stable/22.3/linuxmint-22.3-cinnamon-64bit.iso
+    [ -f manjaro-kde.iso ] || curl -fLo manjaro-kde.iso \
+        https://download.manjaro.org/kde/26.1.0/manjaro-kde-26.1.0-260812-linux71.iso
+    if [ ! -f pop-os.iso ]; then
+        pop=$(curl -fsSL https://api.pop-os.org/builds/24.04/generic)
+        curl -fLo pop-os.iso "$(echo "$pop" | python3 -c 'import json,sys; print(json.load(sys.stdin)["url"])')"
+        [ "$(sha256sum pop-os.iso | cut -d' ' -f1)" = "$(echo "$pop" | python3 -c 'import json,sys; print(json.load(sys.stdin)["sha_sum"])')" ] || echo "pop-os.iso: sha256 mismatch"
+    fi
+    [ -f bazzite.iso ] || curl -fLo bazzite.iso https://download.bazzite.gg/bazzite-stable-amd64.iso
     cd "$LINUXVM/rpms" && dnf download --arch x86_64 qemu-device-display-virtio-gpu qemu-device-display-virtio-gpu-gl \
         qemu-device-display-virtio-gpu-pci qemu-device-display-virtio-gpu-pci-gl qemu-device-display-virtio-vga \
-        qemu-device-display-virtio-vga-gl qemu-ui-egl-headless qemu-ui-opengl virglrenderer
+        qemu-device-display-virtio-vga-gl qemu-ui-egl-headless qemu-ui-opengl virglrenderer qemu-ui-gtk qemu-audio-pipewire
     cd "$LINUXVM/root" && for rpm in "$LINUXVM"/rpms/*.rpm; do rpm2cpio "$rpm" | cpio -idm 2>/dev/null; done
     [ -f "$KEY" ] || ssh-keygen -q -t ed25519 -N '' -f "$KEY"
     ;;
@@ -55,7 +76,7 @@ create)
     while echo "$used" | grep -qx $p; do p=$((p + 1)); done
     echo $p > "$dir/port"
     admin=wheel
-    case $3 in ubuntu*) admin=sudo ;; esac
+    case $3 in ubuntu* | debian*) admin=sudo ;; esac
     cat > "$dir/seed/meta-data" <<EOF
 instance-id: $vm
 local-hostname: $vm
@@ -80,26 +101,53 @@ EOF
     cp /usr/share/edk2/ovmf/OVMF_VARS.fd "$dir/vars.fd"
     echo "created $vm (ssh port $p)"
     ;;
+create-iso)
+    vm=$2 iso=$LINUXVM/images/$3.iso dir=$(vmdir "$2")
+    [ -f "$iso" ] || { echo "no $iso"; exit 1; }
+    [ -e "$dir" ] && { echo "$dir exists"; exit 1; }
+    mkdir -p "$dir"
+    qemu-img create -q -f qcow2 "$dir/disk.qcow2" 60G
+    ln -s "$iso" "$dir/boot.iso"
+    used=$(cat "$LINUXVM"/vms/*/port 2>/dev/null)
+    p=2250
+    while echo "$used" | grep -qx $p; do p=$((p + 1)); done
+    echo $p > "$dir/port"
+    cp /usr/share/edk2/ovmf/OVMF_VARS.fd "$dir/vars.fd"
+    echo "created $vm (ssh port $p)"
+    ;;
 start)
     vm=$2 dir=$(vmdir "$2")
     [ -f "$dir/qemu.pid" ] && kill -0 "$(cat "$dir/qemu.pid")" 2>/dev/null && { echo running; exit 0; }
     size=${LINUXVM_SIZE:-1920x1080}
+    display=(-display egl-headless,rendernode="${LINUXVM_RENDERNODE:-/dev/dri/renderD128}")
+    extra=(-vnc unix:"$dir/vnc.sock")
+    if [ "${LINUXVM_DISPLAY:-}" = window ]; then
+        display=(-display gtk,gl=on,zoom-to-fit=off,show-menubar=off)
+        extra=(-audiodev pipewire,id=snd0 -device intel-hda -device hda-duplex,audiodev=snd0
+            -device virtio-serial-pci -chardev qemu-vdagent,id=vdagent,clipboard=on,mouse=off
+            -device virtserialport,chardev=vdagent,name=com.redhat.spice.0)
+    fi
     QEMU_MODULE_DIR=$LINUXVM/root/usr/lib64/qemu LD_LIBRARY_PATH=$LINUXVM/root/usr/lib64 \
     qemu-system-x86_64 -name "$vm" -machine q35 -accel kvm -cpu host -smp "${LINUXVM_CPUS:-8}" -m "${LINUXVM_MEM:-8G}" \
         -drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/ovmf/OVMF_CODE.fd \
         -drive if=pflash,format=raw,file="$dir/vars.fd" \
         -drive file="$dir/disk.qcow2",if=virtio,format=qcow2,cache=unsafe,discard=unmap \
-        -drive file="$dir/seed.iso",media=cdrom,if=none,id=seed,readonly=on -device ide-cd,drive=seed \
+        $([ -f "$dir/seed.iso" ] && echo -drive file="$dir/seed.iso",media=cdrom,if=none,id=seed,readonly=on -device ide-cd,drive=seed) \
+        $([ -e "$dir/boot.iso" ] && echo -drive file="$dir/boot.iso",media=cdrom,if=none,id=boot,readonly=on -device ide-cd,drive=boot,bootindex=1) \
         -nic user,model=virtio-net-pci,hostfwd=tcp:127.0.0.1:"$(port "$vm")"-:22 \
         -device virtio-vga-gl,xres="${size%x*}",yres="${size#*x}" \
-        -display egl-headless,rendernode="${LINUXVM_RENDERNODE:-/dev/dri/renderD128}" \
-        -vnc unix:"$dir/vnc.sock" -device qemu-xhci -device usb-tablet \
+        "${display[@]}" "${extra[@]}" \
+        -device qemu-xhci -device usb-tablet \
         -qmp unix:"$dir/qmp.sock",server=on,wait=off -serial file:"$dir/serial.log" \
         -daemonize -pidfile "$dir/qemu.pid"
+    [ -f "$dir/seed.iso" ] || { echo "$vm started (no cloud-init, no ssh wait)"; exit 0; }
     for _ in $(seq 120); do ssh_vm "$vm" true 2>/dev/null && { echo "$vm is up"; exit 0; }; sleep 2; done
     echo "$vm: no ssh after 4 minutes, see $dir/serial.log"
     exit 1
     ;;
+desktop)
+    LINUXVM_DISPLAY=window exec "$0" start "$2"
+    ;;
 ssh)
     vm=$2
     shift 2
@@ -125,7 +173,7 @@ pointer | click | keys | type | raw)
     $QMP "$(vmdir "$vm")/qmp.sock" "$op" "$@"
     ;;
 *)
-    sed -n '2,16p' "$0"
+    sed -n '2,24p' "$0"
     exit 1
     ;;
 esac