mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 23:28:34 +01:00
feat(nix): the layouts and floating scenarios
layouts changes the layout of the first workspace to each of eight, with three windows and with five, and checks every window is where the daemon's layout says, inside the work area and clear of the others. floating floats a window, checks the others take its room, and that floating it again tiles it back. Both run in core-e2e: 209 checks pass on KDE.
This commit is contained in:
1 parent
b4dffcaa7a
commit
4835907b2e
5 files changed
+211
-1
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"""A window that floats leaves the tiling to the others, and goes back into it when it stops."""
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.platform import Client, Platform
|
||||
from komorebi_vm.core.scenarios.layouts import tiled
|
||||
from komorebi_vm.core.scenarios.support import focus_agrees
|
||||
|
||||
|
||||
def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""Floats the last of `clients`, which are tiled windows of the first workspace in a
|
||||
container each, with more than one of them, and then tiles it again."""
|
||||
target = clients[-1]
|
||||
others = clients[:-1]
|
||||
platform.activate(target)
|
||||
platform.wait_for(lambda: focus_agrees(platform, clients, target.title))
|
||||
|
||||
def area(c: Client) -> int:
|
||||
window = platform.os_window(c)
|
||||
return window.frame.w * window.frame.h if window is not None else 0
|
||||
|
||||
def floating() -> list[str]:
|
||||
return [w.title for w in platform.state().workspace().floating]
|
||||
|
||||
before = sum(area(c) for c in others)
|
||||
managed = platform.state().managed()
|
||||
|
||||
platform.komorebic("toggle-float")
|
||||
checks.check(
|
||||
f"after 'toggle-float' the daemon has {target.title} floating",
|
||||
platform.wait_for(lambda: floating() == [target.title], timeout=20),
|
||||
)
|
||||
checks.check("... and still manages every window", platform.state().managed() == managed)
|
||||
checks.check(
|
||||
"... the others take more room between them",
|
||||
platform.wait_for(lambda: sum(area(c) for c in others) > before, timeout=20),
|
||||
)
|
||||
frames = [w.frame for c in others if (w := platform.os_window(c)) is not None]
|
||||
checks.check(
|
||||
"... inside the work area and not on each other",
|
||||
all(f.inside(platform.work_area()) for f in frames)
|
||||
and not any(a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :]),
|
||||
)
|
||||
checks.check(
|
||||
f"... {target.title} is still there, and not put away",
|
||||
platform.os_window(target) is not None and not platform.hidden(target),
|
||||
)
|
||||
|
||||
platform.komorebic("toggle-float")
|
||||
checks.check(
|
||||
f"after another 'toggle-float' {target.title} floats no more",
|
||||
platform.wait_for(lambda: floating() == [], timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"... and every window is tiled where the layout says",
|
||||
platform.wait_for(lambda: tiled(platform, clients), timeout=20),
|
||||
)
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Each layout the daemon has tiles the windows it is given: where it says, none over another."""
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.platform import Client, Platform
|
||||
from komorebi_vm.core.scenarios.tiling import _where_the_layout_says
|
||||
|
||||
# the layouts both ports have, but for scrolling, which does not fit the work area
|
||||
LAYOUTS = (
|
||||
"bsp",
|
||||
"columns",
|
||||
"rows",
|
||||
"vertical-stack",
|
||||
"horizontal-stack",
|
||||
"ultrawide-vertical-stack",
|
||||
"grid",
|
||||
"right-main-vertical-stack",
|
||||
)
|
||||
|
||||
|
||||
def tiled(platform: Platform, clients: list[Client]) -> bool:
|
||||
"""Every window is where the daemon's own layout puts it, as the OS reports it."""
|
||||
workspace = platform.state().workspace()
|
||||
layout = workspace.latest_layout
|
||||
frames = [platform.os_window(c) for c in clients]
|
||||
if len(layout) != len(clients) or any(f is None for f in frames):
|
||||
return False
|
||||
by_title = {w.title: layout[i] for i, c in enumerate(workspace.containers) for w in c[:1]}
|
||||
return all(
|
||||
f is not None
|
||||
and f.title in by_title
|
||||
and _where_the_layout_says(f.frame, by_title[f.title], platform.tolerance)
|
||||
for f in frames
|
||||
)
|
||||
|
||||
|
||||
def _check_layout(platform: Platform, checks: Checks, clients: list[Client], layout: str) -> None:
|
||||
label = f"{layout}, {len(clients)} windows"
|
||||
platform.komorebic("change-layout", layout)
|
||||
checks.check(
|
||||
f"{label}: every window is where the layout says",
|
||||
platform.wait_for(lambda: tiled(platform, clients), timeout=20),
|
||||
)
|
||||
area = platform.work_area()
|
||||
frames = [w.frame for c in clients if (w := platform.os_window(c)) is not None]
|
||||
checks.check(f"{label}: ... inside the work area", all(f.inside(area) for f in frames))
|
||||
checks.check(
|
||||
f"{label}: ... and not on each other",
|
||||
not any(a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :]),
|
||||
)
|
||||
|
||||
|
||||
def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""Changes the layout of the first workspace to each of `LAYOUTS` with `clients`, which are
|
||||
tiled windows in a container each, and then with two windows more, which it closes.
|
||||
|
||||
The layout is `bsp` again at the end.
|
||||
"""
|
||||
for layout in LAYOUTS:
|
||||
_check_layout(platform, checks, clients, layout)
|
||||
|
||||
more = [platform.spawn("layouts-extra1"), platform.spawn("layouts-extra2")]
|
||||
everyone = clients + more
|
||||
checks.check(
|
||||
"two windows more are managed",
|
||||
platform.wait_for(lambda: platform.state().managed() == len(everyone), timeout=20),
|
||||
)
|
||||
for layout in LAYOUTS:
|
||||
_check_layout(platform, checks, everyone, layout)
|
||||
|
||||
platform.komorebic("change-layout", "bsp")
|
||||
for client in more:
|
||||
platform.close(client)
|
||||
checks.check(
|
||||
"the two windows are closed and the others tiled again",
|
||||
platform.wait_for(
|
||||
lambda: platform.state().managed() == len(clients) and tiled(platform, clients),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
@@ -79,6 +79,7 @@ class FakePlatform:
|
||||
self.display_count = 2
|
||||
self.display_of: dict[str, int] = {}
|
||||
self.forgets_displays = False
|
||||
self.floats: list[str] = []
|
||||
self.running = True
|
||||
self.placement: Any = None
|
||||
self.moves = moves
|
||||
@@ -109,6 +110,8 @@ class FakePlatform:
|
||||
def start_komorebi(self) -> None:
|
||||
"""A new daemon knows nothing: every window is tiled on the first workspace."""
|
||||
everyone = [t for containers in self.spaces for stack in containers for t in stack]
|
||||
everyone += self.floats
|
||||
self.floats = []
|
||||
self.spaces = [[[t] for t in everyone], [], []]
|
||||
self.focuses = [0, 0, 0]
|
||||
self.current = 0
|
||||
@@ -216,6 +219,9 @@ class FakePlatform:
|
||||
self.display_of[title] = 0
|
||||
|
||||
def close(self, client: Client) -> None:
|
||||
if client.title in self.floats:
|
||||
self.floats.remove(client.title)
|
||||
return
|
||||
if client.title in self.unmanaged:
|
||||
self.unmanaged.remove(client.title)
|
||||
return
|
||||
@@ -241,6 +247,8 @@ class FakePlatform:
|
||||
return self._find(title)[1]
|
||||
|
||||
def hidden(self, client: Client) -> bool:
|
||||
if client.title in self.floats:
|
||||
return False
|
||||
if client.title in self.unmanaged:
|
||||
return False
|
||||
s, i = self._find(client.title)
|
||||
@@ -259,6 +267,8 @@ class FakePlatform:
|
||||
return Image.new("RGB", (4, 4))
|
||||
|
||||
def os_window(self, client: Client) -> OsWindow | None:
|
||||
if client.title in self.floats:
|
||||
return OsWindow(client.title, Rect(300, 300, 600, 400), focused=False)
|
||||
if client.title in self.unmanaged:
|
||||
return OsWindow(client.title, Rect(100, 100, 400, 300), focused=False)
|
||||
try:
|
||||
@@ -356,6 +366,15 @@ class FakePlatform:
|
||||
break
|
||||
case ("focus-workspace", number):
|
||||
self.current = int(number)
|
||||
case ("toggle-float",):
|
||||
if self.floats:
|
||||
self.containers.insert(self.focus, [self.floats.pop()])
|
||||
else:
|
||||
title = self.containers[self.focus][0]
|
||||
self._find_remove(title)
|
||||
self.floats.append(title)
|
||||
self.focuses[self.current] = max(0, min(self.focus, len(self.containers) - 1))
|
||||
self._relayout()
|
||||
case ("unstack",):
|
||||
stack = self.containers.pop(self.focus)
|
||||
self.containers[self.focus : self.focus] = [[t] for t in stack]
|
||||
@@ -385,6 +404,7 @@ class FakePlatform:
|
||||
return {"left": r.x, "top": r.y, "right": r.w, "bottom": r.h}
|
||||
|
||||
def workspace(containers: list[list[str]], focus: int, current: bool) -> dict[str, Any]:
|
||||
floats = self.floats if current else []
|
||||
monocle = None
|
||||
if current and self.monocle is not None:
|
||||
whole = Rect(0, 0, 1920, 1080)
|
||||
@@ -408,7 +428,10 @@ class FakePlatform:
|
||||
},
|
||||
"monocle_container": monocle,
|
||||
"maximized_window": None,
|
||||
"floating_windows": {"elements": [], "focused": 0},
|
||||
"floating_windows": {
|
||||
"elements": [window(t, Rect(300, 300, 600, 400)) for t in floats],
|
||||
"focused": 0,
|
||||
},
|
||||
"layout": {"Default": "Columns"},
|
||||
"tile": True,
|
||||
"latest_layout": [rect(r) for r in self.tiles[: len(containers)]],
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
"""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.geometry import Rect
|
||||
from komorebi_vm.core.scenarios import (
|
||||
closing,
|
||||
commands,
|
||||
floating,
|
||||
focus,
|
||||
focus_follows_mouse,
|
||||
hotplug,
|
||||
layouts,
|
||||
lifecycle,
|
||||
monocle,
|
||||
moving,
|
||||
@@ -135,6 +138,51 @@ def test_a_daemon_that_does_not_take_its_windows_up_again_fails_lifecycle() -> N
|
||||
assert checks.failed > 0
|
||||
|
||||
|
||||
def test_a_daemon_that_is_right_passes_layouts() -> None:
|
||||
platform = FakePlatform()
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
layouts.run(platform, checks, clients)
|
||||
assert checks.failed == 0, checks.failures
|
||||
assert checks.passed > len(layouts.LAYOUTS) * 6
|
||||
|
||||
|
||||
def test_a_layout_that_puts_tiles_over_each_other_fails_layouts() -> None:
|
||||
class Overlapping(FakePlatform):
|
||||
def komorebic(self, *args: str) -> str:
|
||||
out = super().komorebic(*args)
|
||||
if args == ("change-layout", "grid"):
|
||||
self.tiles = [Rect(0, 0, 1000, 1080)] * len(self.containers)
|
||||
return out
|
||||
|
||||
platform = Overlapping()
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
layouts.run(platform, checks, clients)
|
||||
assert checks.failed > 0
|
||||
|
||||
|
||||
def test_a_daemon_that_is_right_passes_floating() -> None:
|
||||
platform = FakePlatform()
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
floating.run(platform, checks, clients)
|
||||
assert checks.failed == 0, checks.failures
|
||||
assert checks.passed > 6
|
||||
|
||||
|
||||
def test_a_float_that_stays_in_the_tiling_fails_floating() -> None:
|
||||
class Stubborn(FakePlatform):
|
||||
def komorebic(self, *args: str) -> str:
|
||||
return "" if args == ("toggle-float",) else super().komorebic(*args)
|
||||
|
||||
platform = Stubborn()
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
floating.run(platform, checks, clients)
|
||||
assert checks.failed > 0
|
||||
|
||||
|
||||
def test_a_command_the_port_lacks_is_skipped_by_name() -> None:
|
||||
platform = FakePlatform()
|
||||
checks = Checks()
|
||||
|
||||
@@ -17,7 +17,9 @@ from komorebi_vm.core.platform import Client
|
||||
from komorebi_vm.core.scenarios import (
|
||||
closing,
|
||||
commands,
|
||||
floating,
|
||||
focus,
|
||||
layouts,
|
||||
lifecycle,
|
||||
monocle,
|
||||
moving,
|
||||
@@ -448,6 +450,8 @@ checks.check(
|
||||
"and unstacked",
|
||||
kde.wait_for(lambda: sorted(map(len, kde.containers())) == [1, 1, 1]),
|
||||
)
|
||||
layouts.run(platform, checks, neutral)
|
||||
floating.run(platform, checks, neutral)
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user