feat(nix): the monocle and closing scenarios, and Platform.close

monocle toggles monocle on the focused window and checks that it fills the
work area up to the layout's padding, that the state has it as the monocle
container, that every other window is put away, that it keeps the focus,
and that toggling back puts every window in view on the tile it had.
closing closes a window and checks that the OS has no frame for it, that
the daemon manages one window fewer, and that the windows left in view
take more room between them, inside the work area and clear of each other.

Platform.close closes a window as its button would; KdePlatform does it
with kdotool. The fake daemon models monocle and closing, and its
os_window now knows the workspace a window is on, which the workspaces
scenario had passed without. core-e2e runs both: 120 checks pass on KVM.
This commit is contained in:
LGUG2Z committed 2026-10-30 12:03:00 -07:00
1 parent 37b75f8205
commit ed792445d0
9 files changed
+203 -17

No files matched your search

+4 -3
View File
@@ -157,15 +157,16 @@ the run.
a screenshot. Where the platform has a pointer (`has("pointer")`), a scenario moves
it with `pointer.drag`; where it has none, the scenario says so and is skipped.
`core/scenarios` has the scenarios written against it: `tiling`, `focus`, `moving`,
`stacks`, `workspaces` and `resize`. A method is added with the first scenario that
`stacks`, `monocle`, `workspaces`, `closing` and `resize`. A method is added with the first scenario that
needs it. `KdePlatform` (`kde_platform.py`) is a `Kde` session as a `Platform`.
[Writing a scenario](#writing-a-scenario) says how to add one.
The scenarios run on two platforms. KDE runs all six: five at the end of `core-e2e`,
The scenarios run on two platforms. KDE runs all eight: seven at the end of `core-e2e`,
and `resize`, which needs a pointer, at the end of `drag-resize`. A Windows 11 guest
under QEMU, which kfw drives from its own tree, has run `tiling`, `focus`, `moving`,
`stacks` and `workspaces` against kfw's daemon (reported by the session that ran them,
2026-10-29, with this `core/` copied unchanged); `resize` has not run there yet.
2026-10-29, with this `core/` copied unchanged); `monocle` and `closing` have not, and `resize` ran with a shortfall that is a finding about kfw
(the edge moves less than the pointer).
`scripts/sync-e2e-core` keeps kfw's copy of `core/` in step until `core/` moves there.
- `Checks` counts checks and fails once, at the end, so that one failure does
not hide the ones after it. `finish()` prints `passed: N failed: M`, and its
@@ -118,6 +118,10 @@ class Platform(Protocol):
"""
...
def close(self, client: Client) -> None:
"""Closes the window, as its close button would."""
...
def work_area(self) -> Rect:
"""The area of the first display that windows may take."""
...
@@ -0,0 +1,41 @@
"""A window that closes leaves the daemon's state, and the ones that are left share its room."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.platform import Client, Platform
def run(platform: Platform, checks: Checks, clients: list[Client], closing: Client) -> None:
"""Closes `closing`, one of `clients`, which are tiled windows of the first workspace, and
checks that the daemon let go of it and the others fill what it left.
The windows of `clients` that are put away (on another workspace) are left out of the frames.
"""
others = [c for c in clients if c != closing and not platform.hidden(c)]
def area(c: Client) -> int:
window = platform.os_window(c)
return window.frame.w * window.frame.h if window is not None else 0
before = sum(area(c) for c in others)
managed = platform.state().managed()
platform.close(closing)
checks.check(
f"{closing.title} is gone",
platform.wait_for(lambda: platform.os_window(closing) is None, timeout=20),
)
checks.check(
"the daemon manages one window fewer",
platform.wait_for(lambda: platform.state().managed() == managed - 1, timeout=20),
)
checks.check(
"the windows that are left take more room between them",
platform.wait_for(lambda: sum(area(c) for c in others) > before, timeout=20),
)
area_of_screen = platform.work_area()
frames = [w.frame for c in others if (w := platform.os_window(c)) is not None]
checks.check("... inside the work area", all(f.inside(area_of_screen) for f in frames))
checks.check(
"... and not on each other",
not any(a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :]),
)
@@ -0,0 +1,61 @@
"""In monocle one window has the work area and the others are put away; toggling gives it back."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.platform import Client, Platform
from komorebi_vm.core.scenarios.support import focus_agrees, os_focused, positions
# how much smaller than the work area a window in monocle may be: the padding of the layout
PADDING = 120
def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
"""Toggles monocle on the focused one of `clients`, which are tiled windows of the first
workspace, each in a container of its own, and toggles it off again."""
last = clients[-1]
platform.activate(last)
platform.wait_for(lambda: focus_agrees(platform, clients, last.title))
before = positions(platform, clients)
area = platform.work_area()
def fills_the_work_area() -> bool:
window = platform.os_window(last)
return (
window is not None
and window.frame.w >= area.w - PADDING
and window.frame.h >= area.h - PADDING
)
platform.komorebic("toggle-monocle")
checks.check(
"in monocle the focused window fills the work area",
platform.wait_for(fills_the_work_area, timeout=20),
)
checks.check(
"... the daemon's state has it as the monocle container",
platform.wait_for(
lambda: [w.title for w in platform.state().workspace().monocle or []] == [last.title]
),
)
checks.check(
"... and every other window is put away",
platform.wait_for(
lambda: (
all(platform.hidden(c) for c in clients if c != last) and not platform.hidden(last)
)
),
)
checks.check("... and it still has the focus", os_focused(platform, clients) == last.title)
platform.komorebic("toggle-monocle")
checks.check(
"toggling back puts every window in view again",
platform.wait_for(lambda: not any(platform.hidden(c) for c in clients), timeout=20),
)
checks.check(
"... each on the tile it had",
platform.wait_for(lambda: positions(platform, clients) == before, timeout=20),
)
checks.check(
"... and the state has no monocle container",
platform.wait_for(lambda: platform.state().workspace().monocle is None),
)
@@ -80,6 +80,9 @@ class KdePlatform:
return True
return desk != 0 and desk != self.kde.shown()
def close(self, client: Client) -> None:
self.kde.close(self.kde.wid(client.title))
def work_area(self) -> Rect:
return Rect(0, 0, *self.size)
+44 -10
View File
@@ -57,6 +57,7 @@ class FakePlatform:
and the first window of a stack is the one in view."""
self.focuses = [0, 0]
self.current = 0
self.monocle: str | None = None
self.moves = moves
self.focus_follows_move = focus_follows_move
@@ -111,14 +112,34 @@ class FakePlatform:
for i, stack in enumerate(containers):
if title in stack:
return s, i
raise AssertionError(f"no window {title}")
raise KeyError(title)
def close(self, client: Client) -> None:
s, i = self._find(client.title)
stack = self.spaces[s][i]
stack.remove(client.title)
if not stack:
self.spaces[s].pop(i)
self.focuses[s] = max(0, min(self.focuses[s], len(self.spaces[s]) - 1))
if self.monocle == client.title:
self.monocle = None
self._relayout()
def _relayout(self) -> None:
"""The tiles of each workspace share the work area in equal columns."""
self.tiles = list(TILES)
n = len(self.containers)
if n:
width = 1920 // n
self.tiles = [Rect(i * width, 0, width, 1080) for i in range(n)] + list(TILES[n:])
def _container(self, title: str) -> int:
return self._find(title)[1]
def hidden(self, client: Client) -> bool:
s, i = self._find(client.title)
return s != self.current or self.spaces[s][i][0] != client.title
away = self.monocle is not None and client.title != self.monocle
return s != self.current or self.spaces[s][i][0] != client.title or away
def work_area(self) -> Rect:
return Rect(0, 0, 1920, 1080)
@@ -132,12 +153,16 @@ class FakePlatform:
return Image.new("RGB", (4, 4))
def os_window(self, client: Client) -> OsWindow | None:
i = self._container(client.title)
return OsWindow(
client.title,
TILES[i],
focused=i == self.focus and self.containers[i][0] == client.title,
try:
s, i = self._find(client.title)
except KeyError:
return None
if self.monocle == client.title:
return OsWindow(client.title, Rect(0, 0, 1920, 1080), focused=True)
focused = (
s == self.current and i == self.focuses[s] and self.spaces[s][i][0] == client.title
)
return OsWindow(client.title, self.tiles[i], focused=focused)
def komorebic(self, *args: str) -> str:
n = len(self.containers)
@@ -169,6 +194,9 @@ class FakePlatform:
self.containers.pop(self.focus)
self.focus = max(0, min(self.focus, len(self.containers) - 1))
self.spaces[int(number)].append([window])
case ("toggle-monocle",):
top = self.containers[self.focus][0]
self.monocle = None if self.monocle else top
case ("focus-workspace", number):
self.current = int(number)
case ("unstack",):
@@ -199,7 +227,12 @@ class FakePlatform:
def rect(r: Rect) -> dict[str, int]:
return {"left": r.x, "top": r.y, "right": r.w, "bottom": r.h}
def workspace(containers: list[list[str]], focus: int) -> dict[str, Any]:
def workspace(containers: list[list[str]], focus: int, current: bool) -> dict[str, Any]:
monocle = None
if current and self.monocle is not None:
whole = Rect(0, 0, 1920, 1080)
windows = {"elements": [window(self.monocle, whole)], "focused": 0}
monocle = {"id": "m", "locked": False, "windows": windows}
return {
"name": None,
"containers": {
@@ -216,7 +249,7 @@ class FakePlatform:
],
"focused": focus,
},
"monocle_container": None,
"monocle_container": monocle,
"maximized_window": None,
"floating_windows": {"elements": [], "focused": 0},
"layout": {"Default": "Columns"},
@@ -229,7 +262,8 @@ class FakePlatform:
"size": rect(Rect(0, 0, 1920, 1080)),
"workspaces": {
"elements": [
workspace(c, f) for c, f in zip(self.spaces, self.focuses, strict=True)
workspace(c, f, i == self.current)
for i, (c, f) in enumerate(zip(self.spaces, self.focuses, strict=True))
],
"focused": self.current,
},
+28 -1
View File
@@ -1,7 +1,16 @@
"""The focus and moving scenarios against a daemon that is right, and against ones that are not."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.scenarios import focus, moving, resize, stacks, tiling, workspaces
from komorebi_vm.core.scenarios import (
closing,
focus,
monocle,
moving,
resize,
stacks,
tiling,
workspaces,
)
from tests.fake_platform import FakePlatform
@@ -77,3 +86,21 @@ def test_a_platform_with_no_pointer_skips_resize() -> None:
passed = checks.passed
resize.run(platform, checks, clients)
assert (checks.passed, checks.failed) == (passed, 0)
def test_a_daemon_that_is_right_passes_monocle() -> None:
platform = FakePlatform()
checks = Checks()
clients = opened(platform, checks)
monocle.run(platform, checks, clients)
assert checks.failed == 0, checks.failures
assert checks.passed > 5
def test_a_daemon_that_is_right_passes_closing() -> None:
platform = FakePlatform()
checks = Checks()
clients = opened(platform, checks)
closing.run(platform, checks, clients, clients[-1])
assert checks.failed == 0, checks.failures
assert checks.passed > 4
+3
View File
@@ -35,6 +35,9 @@ class FakePlatform:
def hidden(self, client: Client) -> bool:
return False
def close(self, client: Client) -> None:
pass
def has(self, feature: str) -> bool:
return False
+15 -3
View File
@@ -13,7 +13,16 @@
import json
from komorebi_vm import Checks, Kde, Rect, daemon
from komorebi_vm.core.scenarios import focus, moving, stacks, tiling, workspaces
from komorebi_vm.core.platform import Client
from komorebi_vm.core.scenarios import (
closing,
focus,
monocle,
moving,
stacks,
tiling,
workspaces,
)
from komorebi_vm.kde_platform import KdePlatform
W, H = 1920, 1080
@@ -397,7 +406,7 @@ checks.check(
report(["afterwards"])
print(
"== 12. tiling, focus, moving, stacks and workspaces, through the neutral platform"
"== 12. tiling, focus, moving, stacks, monocle, workspaces and closing, through the neutral platform"
)
# the scenarios of komorebi_vm.core.scenarios are what runs on Windows too: it asks the
# operating system where the windows are, and not the daemon's log
@@ -430,7 +439,10 @@ checks.check(
"and unstacked",
kde.wait_for(lambda: sorted(map(len, kde.containers())) == [1, 1, 1]),
)
monocle.run(platform, checks, neutral)
workspaces.run(platform, checks, neutral)
# the third window is on workspace 1 now: the first is closed, and the second takes its room
closing.run(platform, checks, neutral, Client("neutral1"))
print("== 13. komorebic stop")
kde.komorebic("stop")
@@ -442,7 +454,7 @@ checks.check(
checks.check(
"the script is no longer in KWin", kde.wait_for(lambda: not kde.script_loaded())
)
checks.check("the windows stay", kde.wid("neutral1") != "")
checks.check("the windows stay", kde.wid("neutral2") != "")
kde.stop()
checks.finish()