feat(e2e): sync the neutral core from kfde 57e510da

Platform gains close(client), and the core gains the monocle and closing
scenarios. From kfde change nykrktvm.
This commit is contained in:
LGUG2Z committed 2026-10-30 18:22:44 -07:00
1 parent 94333870d8
commit 40a9aa3739
6 files changed
+181 -11

No files matched your search

+4
View File
@@ -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),
)
+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