mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-27 19:02:47 +01:00
feat(nix): the resize scenario and a pointer on the Platform
Platform.has says whether a platform can do what a scenario needs, and Platform.pointer is a Pointer (move, down, up, drag) where it has one; KdePlatform takes the pointer of a session node. scenarios.resize drags the edge two tiles share by 60 pixels and checks that the tiles that end at the edge are that much wider, the ones that start after it start that much later and end where they did, nothing moves up or down, and tiles that do not touch the edge are where they were. A platform with no pointer skips it, and says so. The fake daemon has a pointer that moves an edge. The scenario runs on KDE at the end of drag-resize: 19 checks pass on KVM. Its first run failed one check that was the scenario's: both tiles of a BSP column share the dragged edge, and the check took the second for one that had not moved.
This commit is contained in:
1 parent
e385bace05
commit
37b75f8205
8 files changed
+273
-24
No files matched your search
+11
-11
@@ -154,19 +154,19 @@ the run.
|
||||
daemon, run `komorebic`, read the `Snapshot`, open a window, ask whether the
|
||||
daemon put it away (`hidden`), ask the operating system for its frame
|
||||
(`os_window`, the oracle: the daemon's state is the thing under test), and take
|
||||
a screenshot. `core/scenarios` has the scenarios written against it: `tiling`,
|
||||
`focus`, `moving`, `stacks` and `workspaces`, which `core-e2e` runs on KDE and which a suite
|
||||
of kfw can run unchanged. A method is added with the first scenario that needs
|
||||
it. `KdePlatform` (`kde_platform.py`) is a `Kde` session as a `Platform`, and
|
||||
the `core-e2e` suite runs the scenarios through it after its own sections.
|
||||
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
|
||||
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 five, in `core-e2e`. A Windows 11
|
||||
guest under QEMU, which kfw drives from its own tree, has run `tiling` against kfw's
|
||||
daemon (10 of 10 checks on 2026-10-29, reported by the session that ran it, with this
|
||||
`core/` copied unchanged); `focus`, `moving`, `stacks` and `workspaces` have not run
|
||||
there yet. `scripts/sync-e2e-core` keeps kfw's copy of `core/` in step until `core/`
|
||||
moves there.
|
||||
The scenarios run on two platforms. KDE runs all six: five 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.
|
||||
`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
|
||||
error names the checks that failed, which `nix build` shows in the last lines
|
||||
|
||||
@@ -38,9 +38,45 @@ class OsWindow:
|
||||
focused: bool
|
||||
|
||||
|
||||
class Pointer(Protocol):
|
||||
"""A pointer a scenario moves and presses, in the pixels of the first display.
|
||||
|
||||
A drag is one press, a glide to the end with the button held, and one release, because a
|
||||
window manager that is asked to follow the pointer drops moves that come a round trip apart.
|
||||
"""
|
||||
|
||||
def move(self, x: int, y: int) -> None:
|
||||
"""Puts the pointer on the pixel (x, y)."""
|
||||
...
|
||||
|
||||
def down(self) -> None:
|
||||
"""Presses the left button."""
|
||||
...
|
||||
|
||||
def up(self) -> None:
|
||||
"""Lets go of the left button."""
|
||||
...
|
||||
|
||||
def drag(
|
||||
self, start: tuple[int, int], end: tuple[int, int], steps: int = 25, ms: int = 30
|
||||
) -> None:
|
||||
"""Presses the left button at `start`, glides to `end` with it held, and lets go there."""
|
||||
...
|
||||
|
||||
|
||||
class Platform(Protocol):
|
||||
"""A machine with a desktop and a daemon to test."""
|
||||
|
||||
def has(self, feature: str) -> bool:
|
||||
"""Whether the platform can do what a scenario needs of it (`"pointer"`), so that a
|
||||
scenario that needs it is skipped, with the reason, where it cannot."""
|
||||
...
|
||||
|
||||
@property
|
||||
def pointer(self) -> Pointer:
|
||||
"""The pointer. Only where `has("pointer")`."""
|
||||
...
|
||||
|
||||
@property
|
||||
def tolerance(self) -> int:
|
||||
"""How far a window's frame may be short of the one asked for, in pixels.
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
"""Dragging the edge two tiles share resizes both, and nothing else moves."""
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, Platform
|
||||
|
||||
# how far outside a window's frame its resize border is pressed: the gap between two tiles
|
||||
OFFSET = 4
|
||||
# how far the edge may end up from where the pointer put it, in pixels
|
||||
SLACK = 6
|
||||
|
||||
|
||||
def _side_by_side(layout: list[Rect]) -> tuple[int, int] | None:
|
||||
"""The first pair of tiles of which the second is to the right of the first, with the same top,
|
||||
so that the edge between them is one the pointer can take."""
|
||||
for i, a in enumerate(layout):
|
||||
for j, b in enumerate(layout):
|
||||
if i != j and b.x >= a.x + a.w and a.y < b.y + b.h and b.y < a.y + a.h:
|
||||
return i, j
|
||||
return None
|
||||
|
||||
|
||||
def run(platform: Platform, checks: Checks, clients: list[Client], dx: int = 60) -> None:
|
||||
"""Drags the edge between a tile and the one to its right by `dx` pixels, and checks that the
|
||||
two tiles moved the edge by what the pointer moved, that every other edge stayed, and that the
|
||||
windows still tile on the work area, as the operating system has them.
|
||||
|
||||
`clients` are the tiled windows of the first workspace, each in a container of its own.
|
||||
"""
|
||||
if not platform.has("pointer"):
|
||||
print(" skipped: this platform has no pointer")
|
||||
return
|
||||
state = platform.state()
|
||||
workspace = state.workspace()
|
||||
layout = workspace.latest_layout
|
||||
pair = _side_by_side(layout)
|
||||
checks.check("two tiles share a vertical edge", pair is not None)
|
||||
if pair is None:
|
||||
return
|
||||
left, right = pair
|
||||
titles = [c[0].title for c in workspace.containers]
|
||||
window = platform.os_window(Client(titles[left]))
|
||||
assert window is not None
|
||||
before = list(layout)
|
||||
grab = (window.frame.x + window.frame.w + OFFSET, window.frame.y + window.frame.h // 2)
|
||||
|
||||
platform.pointer.drag(grab, (grab[0] + dx, grab[1]))
|
||||
|
||||
def edge_moved() -> bool:
|
||||
now = platform.state().workspace().latest_layout
|
||||
return len(now) == len(before) and abs(now[left].w - (before[left].w + dx)) <= SLACK
|
||||
|
||||
checks.check(
|
||||
f"the tile on the left of the edge is {dx} pixels wider",
|
||||
platform.wait_for(edge_moved, timeout=20),
|
||||
)
|
||||
now = platform.state().workspace().latest_layout
|
||||
print(f" tiles before {before}, after {now}")
|
||||
edge = before[left].x + before[left].w
|
||||
# the tiles on either side of the edge: every one that ends at it, and every one that starts
|
||||
# at or after it with the edge as its own left side (a column of tiles shares it)
|
||||
ends = [i for i, t in enumerate(before) if t.x + t.w == edge]
|
||||
starts = [i for i, t in enumerate(before) if t.x == before[right].x]
|
||||
checks.check(
|
||||
f"the tiles that end at the edge are {dx} pixels wider and start where they did",
|
||||
all(abs(now[i].w - (before[i].w + dx)) <= SLACK and now[i].x == before[i].x for i in ends),
|
||||
)
|
||||
checks.check(
|
||||
f"the tiles that start after the edge start {dx} pixels later and end where they did",
|
||||
all(
|
||||
abs(now[i].x - (before[i].x + dx)) <= SLACK
|
||||
and abs((now[i].x + now[i].w) - (before[i].x + before[i].w)) <= SLACK
|
||||
for i in starts
|
||||
),
|
||||
)
|
||||
checks.check(
|
||||
"no tile moved up or down or changed its height",
|
||||
all((now[i].y, now[i].h) == (before[i].y, before[i].h) for i in range(len(before))),
|
||||
)
|
||||
checks.check(
|
||||
"every tile that does not touch the edge is where it was",
|
||||
all(now[i] == before[i] for i in range(len(before)) if i not in ends and i not in starts),
|
||||
)
|
||||
area = platform.work_area()
|
||||
frames = [w.frame for c in clients if (w := platform.os_window(c)) is not None]
|
||||
checks.check("the windows are inside the work area", all(f.inside(area) for f in frames))
|
||||
checks.check(
|
||||
"and do not overlap",
|
||||
not any(a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :]),
|
||||
)
|
||||
@@ -6,6 +6,7 @@ from PIL import Image
|
||||
from komorebi_vm.core import snapshot
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, OsWindow, Predicate
|
||||
from komorebi_vm.core.platform import Pointer as PointerDevice
|
||||
from komorebi_vm.core.snapshot import Snapshot
|
||||
from komorebi_vm.kde import Kde
|
||||
|
||||
@@ -18,9 +19,21 @@ PARK = "komorebi-park"
|
||||
class KdePlatform:
|
||||
"""The platform of a headless KWin session of the test machine."""
|
||||
|
||||
def __init__(self, kde: Kde, size: tuple[int, int]) -> None:
|
||||
def __init__(
|
||||
self, kde: Kde, size: tuple[int, int], pointer: PointerDevice | None = None
|
||||
) -> None:
|
||||
self.kde = kde
|
||||
self.size = size
|
||||
self._pointer = pointer
|
||||
|
||||
def has(self, feature: str) -> bool:
|
||||
return feature == "pointer" and self._pointer is not None
|
||||
|
||||
@property
|
||||
def pointer(self) -> PointerDevice:
|
||||
if self._pointer is None:
|
||||
raise AssertionError("this session has no pointer device")
|
||||
return self._pointer
|
||||
|
||||
@property
|
||||
def tolerance(self) -> int:
|
||||
|
||||
@@ -16,10 +16,42 @@ from komorebi_vm.core.snapshot import Snapshot, parse
|
||||
TILES = [Rect(0, 0, 640, 1080), Rect(640, 0, 640, 1080), Rect(1280, 0, 640, 1080)]
|
||||
|
||||
|
||||
class FakePointer:
|
||||
"""A pointer that, dragged from just outside the right edge of a tile, moves that edge."""
|
||||
|
||||
def __init__(self, platform: "FakePlatform") -> None:
|
||||
self.platform = platform
|
||||
self.at = (0, 0)
|
||||
|
||||
def move(self, x: int, y: int) -> None:
|
||||
self.at = (x, y)
|
||||
|
||||
def down(self) -> None:
|
||||
pass
|
||||
|
||||
def up(self) -> None:
|
||||
pass
|
||||
|
||||
def drag(
|
||||
self, start: tuple[int, int], end: tuple[int, int], steps: int = 25, ms: int = 30
|
||||
) -> None:
|
||||
self.platform.resize(start, end[0] - start[0])
|
||||
|
||||
|
||||
class FakePlatform:
|
||||
tolerance = 24
|
||||
|
||||
def __init__(self, *, moves: bool = True, focus_follows_move: bool = True) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
moves: bool = True,
|
||||
focus_follows_move: bool = True,
|
||||
pointer: bool = True,
|
||||
follows_pointer: bool = True,
|
||||
) -> None:
|
||||
self.tiles = list(TILES)
|
||||
self.has_pointer = pointer
|
||||
self.follows_pointer = follows_pointer
|
||||
self.spaces: list[list[list[str]]] = [[], []]
|
||||
"""The two workspaces: for each, the stack of each container, in the order of the tiles,
|
||||
and the first window of a stack is the one in view."""
|
||||
@@ -28,6 +60,25 @@ class FakePlatform:
|
||||
self.moves = moves
|
||||
self.focus_follows_move = focus_follows_move
|
||||
|
||||
def has(self, feature: str) -> bool:
|
||||
return feature == "pointer" and self.has_pointer
|
||||
|
||||
@property
|
||||
def pointer(self) -> FakePointer:
|
||||
return FakePointer(self)
|
||||
|
||||
def resize(self, start: tuple[int, int], dx: int) -> None:
|
||||
"""The edge of the tile that `start` is 4 pixels outside of moves by `dx`, when the daemon
|
||||
follows the pointer."""
|
||||
if not self.follows_pointer:
|
||||
return
|
||||
for i, tile in enumerate(self.tiles[:-1]):
|
||||
if abs(start[0] - (tile.x + tile.w + 4)) <= 1:
|
||||
a, b = tile, self.tiles[i + 1]
|
||||
self.tiles[i] = Rect(a.x, a.y, a.w + dx, a.h)
|
||||
self.tiles[i + 1] = Rect(b.x + dx, b.y, b.w - dx, b.h)
|
||||
return
|
||||
|
||||
def wait_for(self, predicate: Any, timeout: float = 10) -> bool:
|
||||
return bool(predicate())
|
||||
|
||||
@@ -157,7 +208,7 @@ class FakePlatform:
|
||||
"id": str(i),
|
||||
"locked": False,
|
||||
"windows": {
|
||||
"elements": [window(t, TILES[i]) for t in stack],
|
||||
"elements": [window(t, self.tiles[i]) for t in stack],
|
||||
"focused": 0,
|
||||
},
|
||||
}
|
||||
@@ -170,7 +221,7 @@ class FakePlatform:
|
||||
"floating_windows": {"elements": [], "focused": 0},
|
||||
"layout": {"Default": "Columns"},
|
||||
"tile": True,
|
||||
"latest_layout": [rect(r) for r in TILES[: len(containers)]],
|
||||
"latest_layout": [rect(r) for r in self.tiles[: len(containers)]],
|
||||
}
|
||||
|
||||
monitor = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""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, stacks, tiling, workspaces
|
||||
from komorebi_vm.core.scenarios import focus, moving, resize, stacks, tiling, workspaces
|
||||
from tests.fake_platform import FakePlatform
|
||||
|
||||
|
||||
@@ -51,3 +51,29 @@ def test_a_daemon_that_is_right_passes_workspaces() -> None:
|
||||
workspaces.run(platform, checks, clients)
|
||||
assert checks.failed == 0, checks.failures
|
||||
assert checks.passed > 7
|
||||
|
||||
|
||||
def test_a_daemon_that_follows_the_pointer_passes_resize() -> None:
|
||||
platform = FakePlatform()
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
resize.run(platform, checks, clients)
|
||||
assert checks.failed == 0, checks.failures
|
||||
assert checks.passed > 8
|
||||
|
||||
|
||||
def test_a_daemon_that_ignores_the_pointer_fails_resize() -> None:
|
||||
platform = FakePlatform(follows_pointer=False)
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
resize.run(platform, checks, clients)
|
||||
assert any("pixels wider" in f for f in checks.failures)
|
||||
|
||||
|
||||
def test_a_platform_with_no_pointer_skips_resize() -> None:
|
||||
platform = FakePlatform(pointer=False)
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
passed = checks.passed
|
||||
resize.run(platform, checks, clients)
|
||||
assert (checks.passed, checks.failed) == (passed, 0)
|
||||
@@ -4,7 +4,7 @@ from PIL import Image
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, OsWindow
|
||||
from komorebi_vm.core.platform import Client, OsWindow, Pointer
|
||||
from komorebi_vm.core.scenarios import tiling
|
||||
from komorebi_vm.core.snapshot import Snapshot, parse
|
||||
|
||||
@@ -35,6 +35,13 @@ class FakePlatform:
|
||||
def hidden(self, client: Client) -> bool:
|
||||
return False
|
||||
|
||||
def has(self, feature: str) -> bool:
|
||||
return False
|
||||
|
||||
@property
|
||||
def pointer(self) -> Pointer:
|
||||
raise AssertionError("no pointer")
|
||||
|
||||
def work_area(self) -> Rect:
|
||||
return Rect(0, 0, 1920, 1080)
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ import re
|
||||
import time
|
||||
|
||||
from komorebi_vm import Checks, Kde, Pointer, daemon
|
||||
from komorebi_vm.core.platform import Client
|
||||
from komorebi_vm.core.scenarios import resize
|
||||
from komorebi_vm.kde_platform import KdePlatform
|
||||
|
||||
# the module's unit, which the session starts when it logs in: the daemon the suite drags against
|
||||
UNIT = "komorebi.service"
|
||||
@@ -54,7 +57,8 @@ kde.sh("busctl --user call org.kde.KWin /KWin org.kde.KWin reconfigure")
|
||||
|
||||
# the session started the module's unit when it logged in
|
||||
checks.check(
|
||||
"komorebi answers", kde.wait_for(lambda: kde.run("komorebic state")[0] == 0, timeout=120)
|
||||
"komorebi answers",
|
||||
kde.wait_for(lambda: kde.run("komorebic state")[0] == 0, timeout=120),
|
||||
)
|
||||
|
||||
# The windows tiled before the daemon has the panel's room are put in the room that was there, and a
|
||||
@@ -80,7 +84,9 @@ for x, y in [(1, 1), (W - 2, 1), (W // 3, H // 2), (W - 2, H - 2), (17, H - 2)]:
|
||||
kde.wait_for(lambda x=x, y=y: where() == (x, y), timeout=3)
|
||||
gx, gy = where()
|
||||
worst = max(worst, abs(gx - x), abs(gy - y))
|
||||
checks.check(f"the pointer is put within a pixel of where it is asked ({worst})", worst <= 1)
|
||||
checks.check(
|
||||
f"the pointer is put within a pixel of where it is asked ({worst})", worst <= 1
|
||||
)
|
||||
|
||||
for n in range(1, WINDOWS + 1):
|
||||
kde.spawn(f"foot -T win{n} sleep 3000")
|
||||
@@ -193,17 +199,23 @@ def run_case(spec: str) -> list[str]:
|
||||
for e in "LTRB":
|
||||
if e in held and has_neighbor(e, name, before):
|
||||
if abs(moved[e] - want[e]) > CELL:
|
||||
problems.append(f"frame {e} moved {moved[e]}, the pointer moved {want[e]}")
|
||||
problems.append(
|
||||
f"frame {e} moved {moved[e]}, the pointer moved {want[e]}"
|
||||
)
|
||||
elif abs(moved[e]) > CELL:
|
||||
why = "was not dragged" if e not in held else "has no neighbor"
|
||||
problems.append(f"frame {e} moved {moved[e]} but {why}")
|
||||
|
||||
# the layout, which is exact
|
||||
tile_moved = {e: edges(tiles_after[name])[e] - edges(tiles_before[name])[e] for e in "LTRB"}
|
||||
tile_moved = {
|
||||
e: edges(tiles_after[name])[e] - edges(tiles_before[name])[e] for e in "LTRB"
|
||||
}
|
||||
for e in "LTRB":
|
||||
if e in held and has_neighbor(e, name, before):
|
||||
if abs(tile_moved[e] - want[e]) > 2:
|
||||
problems.append(f"tile {e} moved {tile_moved[e]}, the pointer moved {want[e]}")
|
||||
problems.append(
|
||||
f"tile {e} moved {tile_moved[e]}, the pointer moved {want[e]}"
|
||||
)
|
||||
elif abs(tile_moved[e]) > 1:
|
||||
why = "was not dragged" if e not in held else "has no neighbor"
|
||||
problems.append(f"tile {e} moved {tile_moved[e]} but {why}")
|
||||
@@ -216,7 +228,9 @@ def run_case(spec: str) -> list[str]:
|
||||
for e in "LTRB":
|
||||
m = edges(tiles_after[other])[e] - edges(tiles_before[other])[e]
|
||||
if abs(m) > 1 and not any(abs(m - f) <= 2 for f in follows):
|
||||
problems.append(f"{other} tile {e} moved {m}: not with the dragged edge")
|
||||
problems.append(
|
||||
f"{other} tile {e} moved {m}: not with the dragged edge"
|
||||
)
|
||||
|
||||
# still a tiling
|
||||
names = list(after)
|
||||
@@ -246,6 +260,18 @@ cases = [
|
||||
]
|
||||
for spec in cases:
|
||||
problems = run_case(spec)
|
||||
checks.check(f"{spec}: " + ("as expected" if not problems else "; ".join(problems)), not problems)
|
||||
checks.check(
|
||||
f"{spec}: " + ("as expected" if not problems else "; ".join(problems)),
|
||||
not problems,
|
||||
)
|
||||
|
||||
print("== the same drag, through the neutral platform")
|
||||
# the scenario of komorebi_vm.core.scenarios.resize is what runs on Windows too: it reads the
|
||||
# layout from the daemon's state and the frames from the operating system
|
||||
resize.run(
|
||||
KdePlatform(kde, (W, H), pointer),
|
||||
checks,
|
||||
[Client(f"win{n}") for n in range(1, WINDOWS + 1)],
|
||||
)
|
||||
|
||||
checks.finish()
|
||||
Reference in new issue
Block a user