feat(nix): the flipping scenario

flip-layout horizontal puts every window where the mirror of its place
is, with every window where the layout says, and flipping again gives
the places back. core-e2e passes 244 checks on KDE.
This commit is contained in:
LGUG2Z committed 2026-10-30 12:03:00 -07:00
1 parent 63d5833a84
commit d58353d22e
4 files changed
+78

No files matched your search

@@ -0,0 +1,46 @@
"""A flipped layout is the layout mirrored, and flipping it back gives the layout back."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.platform import Client, Platform
from komorebi_vm.core.scenarios.layouts import tiled
def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
"""Flips the layout of the first workspace, which has `clients` tiled in a container each,
horizontally and back."""
area = platform.work_area()
def centres() -> dict[str, int]:
found = {}
for client in clients:
window = platform.os_window(client)
if window is not None:
found[client.title] = window.frame.x + window.frame.w // 2
return found
before = centres()
def mirrored() -> bool:
now = centres()
return len(now) == len(before) and all(
abs((2 * area.x + area.w - before[t]) - now[t]) <= platform.tolerance for t in before
)
platform.komorebic("flip-layout", "horizontal")
checks.check(
"after 'flip-layout horizontal' every window is where the mirror of its place is",
platform.wait_for(mirrored, timeout=20),
)
checks.check(
"... and every window is where the layout says",
platform.wait_for(lambda: tiled(platform, clients), timeout=20),
)
platform.komorebic("flip-layout", "horizontal")
checks.check(
"flipped again, every window is where it was",
platform.wait_for(
lambda: all(abs(centres()[t] - before[t]) <= platform.tolerance for t in before),
timeout=20,
),
)
+8
View File
@@ -80,6 +80,7 @@ class FakePlatform:
self.display_of: dict[str, int] = {}
self.forgets_displays = False
self.floats: list[str] = []
self.flipped = False
self.last = 0
self.maximized: str | None = None
self.workspace_padding = 0
@@ -254,6 +255,10 @@ class FakePlatform:
Rect(w + i * width + c, w + c, width - 2 * c, 1080 - 2 * w - 2 * c)
for i in range(n)
] + list(TILES[n:])
if self.flipped:
self.tiles = [Rect(1920 - t.x - t.w, t.y, t.w, t.h) for t in self.tiles[:n]] + list(
TILES[n:]
)
def _container(self, title: str) -> int:
return self._find(title)[1]
@@ -413,6 +418,9 @@ class FakePlatform:
case ("promote",):
self.containers.insert(0, self.containers.pop(self.focus))
self.focus = 0
case ("flip-layout", "horizontal"):
self.flipped = not self.flipped
self._relayout()
case ("toggle-float",):
if self.floats:
self.containers.insert(self.focus, [self.floats.pop()])
@@ -5,6 +5,7 @@ from komorebi_vm.core.geometry import Rect
from komorebi_vm.core.scenarios import (
closing,
commands,
flipping,
floating,
focus,
focus_follows_mouse,
@@ -317,6 +318,27 @@ def test_a_daemon_that_does_not_promote_fails_promoting() -> None:
assert checks.failed > 0
def test_a_daemon_that_is_right_passes_flipping() -> None:
platform = FakePlatform()
checks = Checks()
clients = opened(platform, checks)
flipping.run(platform, checks, clients)
assert checks.failed == 0, checks.failures
assert checks.passed > 3
def test_a_daemon_that_does_not_flip_fails_flipping() -> None:
class Stubborn(FakePlatform):
def komorebic(self, *args: str) -> str:
return "" if args[0] == "flip-layout" else super().komorebic(*args)
platform = Stubborn()
checks = Checks()
clients = opened(platform, checks)
flipping.run(platform, checks, clients)
assert checks.failed > 0
def test_a_command_the_port_lacks_is_skipped_by_name() -> None:
platform = FakePlatform()
checks = Checks()
+2
View File
@@ -17,6 +17,7 @@ from komorebi_vm.core.platform import Client
from komorebi_vm.core.scenarios import (
closing,
commands,
flipping,
floating,
focus,
layouts,
@@ -462,6 +463,7 @@ minimizing.run(platform, checks, neutral)
maximizing.run(platform, checks, neutral)
resize_commands.run(platform, checks, neutral)
promoting.run(platform, checks, neutral)
flipping.run(platform, checks, neutral)
padding.run(platform, checks, neutral)
monocle.run(platform, checks, neutral)
workspace_moves.run(platform, checks, neutral)