Files
komorebi/nix/tests/vm/suites/features/test.py
T
LGUG2Z 05de20749b feat(wm): maximize
A window could be given the work area only as a tile of the layout, which has
padding around it. `komorebic toggle-maximize` has KWin maximize the focused
window instead: it gets the work area of its monitor with the panels left alone,
and it leaves the layout, so that it is in no container. Toggled again, the
window is restored, put in a container of its own at the index it was taken
from, and the workspace is tiled again.

The window is kept in the workspace as its maximized window, with the index it
goes back to, and the state shows both. While it is maximized the workspace asks
KWin to maximize it again on every tiling, and does not move the containers
behind it. The messages that are about the tiles (move, stack, resize, promote,
preselect, lock, float, monocle, and the ones that send a container to another
monitor or workspace) are dropped before they are handled, since there is no
tile to act on. Focusing in a direction finds no container on any side of it, so
the focus goes to the monitor on that side, where a maximized window or a
monocle is given the focus whole. Showing the workspace again restores the
maximized window and focuses it ahead of the containers' windows. A window in
monocle that is maximized leaves the monocle, and one that closes takes the
maximize with it. Backend gets a maximize command, which does nothing unless a
backend implements it; the fake desktop and the KWin backend do, and the bridge
carries it out with KWin's own `setMaximize`. A maximize also makes the bridge
forget the position it was last asked to put the window at, which it would
otherwise set again on the work area's size when the window's frame changed
within a second of a tiling.

komorebi/tests/maximize.rs and maximize_commands.rs drive it against the fake
desktop, with one monitor and with two. The bridge's tests and the backend's
tests read the maximize command from the same fixture, so that what one sends is
what the other carries out. vm-features is a new session suite that reads
screenshots: the first thing it checks is that the maximized window fills the
work area, is the one on top, and goes back to its tile; the vm-commands sweep
runs the new command.
2026-10-28 07:20:37 -07:00

114 lines
4.2 KiB
Python

# What komorebi does that is on the screen of a real compositing session, read from screenshots: the
# session guest draws, and the daemon is the module's unit, as on a user's machine. A headless KWin
# cannot draw, so what the compositor puts on top can only be told here.
#
# A. toggle-maximize the window fills the work area, is the one on top, and goes back to its
# tile
#
# `komorebi/tests/maximize.rs` and `maximize_commands.rs` check what the window manager does against
# the fake; this checks that KWin's own maximize does it.
import time
from komorebi_vm import Checks, Kde
start_all()
machine.wait_for_unit("multi-user.target")
checks = Checks()
kde = Kde.session(machine, scale=SCALE)
BLUE = (0, 0, 255)
def near(pixel: object, want: tuple[int, int, int], tolerance: int = 14) -> bool:
"""True if every channel of the pixel is within `tolerance` of `want`."""
assert isinstance(pixel, tuple)
return all(abs(got - wanted) <= tolerance for got, wanted in zip(pixel, want, strict=True))
def answering() -> bool:
return kde.run("komorebic monitor-information")[0] == 0
def open_window(title: str, background: str) -> None:
"""Opens a terminal with a plain background, so that a screenshot says which window is on top."""
kde.spawn(
f"foot -T {title} -o colors-dark.background={background} -o colors-dark.alpha=1.0"
" sleep 3000"
)
kde.wait_for(lambda: kde.wid(title) != "", timeout=60)
print("== A. toggle-maximize")
checks.check("the session started komorebi", kde.wait_for(answering, timeout=120))
for count, (title, background) in enumerate(
[("red", "ff0000"), ("green", "00ff00"), ("blue", "0000ff")], start=1
):
open_window(title, background)
checks.check(
f"komorebi manages {title}", kde.wait_for(lambda count=count: kde.managed() == count)
)
# komorebi tiles the windows, and the last one to open has the focus. The bridge asks again for the
# position of a window that is not where komorebi put it for a second after it did (PLATFORM.md,
# "How clients answer a frame"), which would put a window that is maximized in that second back
# where its tile was: the test waits that second out, as a person would.
kde.wait_for(lambda: kde.focused_title() == "blue", timeout=20)
time.sleep(3 * SCALE)
area = kde.state()["monitors"]["elements"][0]["work_area_size"]
blue = kde.wid("blue")
tile = kde.rect(blue)
print(f" the work area is {area['right']}x{area['bottom']}, blue's tile is {tile}")
checks.check(
"blue is a tile, not the whole work area",
tile.w < area["right"] - 20 or tile.h < area["bottom"] - 20,
)
kde.komorebic("toggle-maximize")
def fills_the_work_area() -> bool:
"""KWin's maximize leaves the panel alone, which is at most 100 pixels of the screen."""
r = kde.rect(blue)
return (
r.x <= area["left"] + 2
and r.y <= area["top"] + 2
and r.w >= area["right"] - 30
and r.h >= area["bottom"] - 100
)
filled = kde.wait_for(fills_the_work_area, timeout=20)
maximized = kde.rect(blue)
checks.check(
f"the focused window fills the work area (blue is {maximized}, the area is {area})", filled
)
image = kde.shot("maximized")
print(f" the screenshot is {image.size[0]}x{image.size[1]}")
middle = image.getpixel(
(
min(maximized.x + maximized.w // 2, image.width - 1),
min(maximized.y + maximized.h // 2, image.height - 1),
)
)
checks.check(f"and is the one on top ({middle})", near(middle, BLUE))
workspace = kde.state()["monitors"]["elements"][0]["workspaces"]["elements"][0]
checks.check(
"komorebi's state has it as the maximized window, out of its containers",
workspace["maximized_window"] is not None and len(workspace["containers"]["elements"]) == 2,
)
checks.check("komorebi still has all three", kde.managed_all() == 3)
kde.komorebic("toggle-maximize")
checks.check(
"toggled back, it is in its tile again",
kde.wait_for(lambda: kde.rect(blue) == tile, timeout=20),
)
workspace = kde.state()["monitors"]["elements"][0]["workspaces"]["elements"][0]
checks.check(
"... and in a container of its own",
workspace["maximized_window"] is None and len(workspace["containers"]["elements"]) == 3,
)
checks.finish()