Files
komorebi/nix/tests/vm/suites/client-geometry/test.py
T
LGUG2Z b463191d00 feat(kwin): move and focus windows through a held call
With the commands of the Backend trait carried out, the daemon tiles a real
KWin. A command looks up the UUID KWin knows the window by, is queued as JSON
for the bridge, and returns; the held Poll call is answered with the queue, one
millisecond after the first command, so that a retile reaches KWin as one batch.
The bridge sets the frame, activates, raises, minimizes, restores or closes the
window, and reports what it could not do. set_rect records the frame it asked
for in the table, so the window manager sees it at once, and the geometry event
that follows says what the client made of it.

A KWin script cannot move the pointer, so the pointer follows the focus through
KWin's own "Move Mouse to Focus" action, invoked over kglobalaccel once KWin
reports the window active.

The commands are typed in bridge.js, and the declarations of KWin's API let the
bridge set a window's frame, its minimized state and the active window, raise
and close it, and nothing else. The session the tests of both sides share grows
a second batch: the backend's tests check that set_rect, focus, raise, minimize,
unminimize and close send it, and the bridge's tests answer the bridge with it
and check what KWin is asked to do, down to the command for a window that has
closed, which comes back as failed. The bridge's tests also cover findWindow's
fallback to KWin's list, a frame set as a plain object, and a command KWin
throws on.

Three VM suites check it against a real KWin. vm-core-e2e (from the spike's
m2-e2e, the sections that need no komorebic) compares what the daemon asked for,
read from its debug log, with what KWin has, read with kdotool: three windows
inside the screen, not overlapping, sharing it, the same focused window on both
sides, and the same again after a minimize, a restore and a close.
vm-client-geometry (slow) has eight real clients answer the frames komorebi asks
for: Qt programs and xterm take them exactly, foot sizes itself to whole cells,
GTK 4 programs and Firefox keep to their minimum sizes. vm-latency (slow) times
retiles from a recording of the session bus: on HVF, from the daemon's answer to
the last frame KWin reports, p50 17.3 ms, p95 27.7 ms. vm-kwin-events no longer
checks that nothing moves. The VM library gives session commands the test user's
home and data directories rather than root's, which a GTK client was refused.

The bridge's second request for a position after a resize, which matters for
windows off the screen, comes with the scrolling layout.
2026-10-27 14:48:56 -07:00

102 lines
3.6 KiB
Python

# How real clients answer the frame komorebi asks for. KWin carries out a request at once; the
# client then decides the size it draws at, and that is the frame KWin reports. What only real
# clients can tell, and what the fake desktop of the Rust tests cannot know: Qt and KDE programs
# and X11 programs on XWayland take the frame exactly, also below the minimum size they report;
# foot sizes itself down to whole cells of its font; GTK 4 programs and Firefox never go below
# their minimum size. Every client keeps the position komorebi asked for. The output is large
# enough that some tiles are bigger and some smaller than the clients' minimums.
from komorebi_vm import Checks, Kde, Rect, daemon
W, H = 3840, 2160
CELL = 24
EXACT = ["org.kde.konsole", "org.kde.kate", "org.kde.dolphin", "XTerm"]
WHOLE_CELLS = ["foot"]
NOT_BELOW_MINIMUM = ["org.gnome.TextEditor", "org.gnome.Calculator", "firefox"]
CLIENTS = {
"foot": "foot -T foot-term sleep 3000",
"org.kde.konsole": "konsole --separate",
"org.kde.dolphin": "dolphin --new-window /tmp",
"org.kde.kate": "kate --new",
"org.gnome.TextEditor": "gnome-text-editor --new-window",
"org.gnome.Calculator": "gnome-calculator",
"XTerm": "xterm -T xterm-x11",
"firefox": "firefox --no-remote --profile /tmp/firefox-profile about:blank",
}
start_all()
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("user@1000.service")
checks = Checks()
kde = Kde.headless(machine, "main", size=(W, H), xwayland=True, scale=SCALE)
kde.as_user("mkdir -p /tmp/firefox-profile")
kde.start_komorebi("--log-level", "debug")
checks.check(
"the daemon loaded its script into KWin",
kde.wait_for(lambda: "loaded the KWin bridge script" in kde.komorebi_log(), timeout=30),
)
for app, command in CLIENTS.items():
kde.spawn(command, log=f"/tmp/{app}.log")
up = kde.wait_for(lambda app=app: kde.wid_by_class(app) != "", timeout=120)
if not checks.check(f"{app} has a window", up):
print(machine.execute(f"cat /tmp/{app}.log")[1])
def shown() -> int:
return sum(1 for e in daemon.events(kde.komorebi_log()) if e.kind == "Show")
checks.check("the daemon tiles all eight", kde.wait_for(lambda: shown() >= 8, timeout=60))
def show(r: Rect | None) -> str:
return "-" if r is None else f"{r.x},{r.y} {r.w}x{r.h}"
def snapshot() -> dict[str, Rect]:
return {app: kde.rect(kde.wid_by_class(app)) for app in CLIENTS}
# the clients answer in their own time; the frames are final once they stop changing
before: dict[str, Rect] = {}
def still() -> bool:
global before
now = snapshot()
unchanged = now == before
before = now
return unchanged
kde.wait_for(still, timeout=60, interval=3)
requests = list(daemon.requests(kde.komorebi_log()).values())
print(f" {'client':<22} {'asked':<22} {'has':<22}")
for app, have in snapshot().items():
asked = [r for r in requests if (r.x, r.y) == (have.x, have.y)]
want = asked[0] if asked else None
print(f" {app:<22} {show(want):<22} {show(have):<22}")
if not checks.check(f"{app} is where komorebi put it", want is not None):
continue
assert want is not None
if app in EXACT:
checks.check(f"{app} takes the size it is asked for", (have.w, have.h) == (want.w, want.h))
elif app in WHOLE_CELLS:
checks.check(
f"{app} sizes itself down to whole cells",
0 <= want.w - have.w < CELL and 0 <= want.h - have.h < CELL,
)
elif app in NOT_BELOW_MINIMUM:
checks.check(
f"{app} is never smaller than it is asked to be",
have.w >= want.w and have.h >= want.h,
)
kde.stop_komorebi()
kde.stop()
checks.finish()