diff --git a/nix/tests/vm/lib/komorebi_vm/core/platform.py b/nix/tests/vm/lib/komorebi_vm/core/platform.py index 976cf125..d20d264c 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/platform.py +++ b/nix/tests/vm/lib/komorebi_vm/core/platform.py @@ -151,6 +151,10 @@ class Platform(Protocol): """Closes the window, as its close button would.""" ... + def minimize(self, client: Client) -> None: + """Minimizes the window, as its title bar button would. `activate` restores it.""" + ... + def work_area(self) -> Rect: """The area of the first display that windows may take.""" ... diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/minimizing.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/minimizing.py new file mode 100644 index 00000000..3a03895a --- /dev/null +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/minimizing.py @@ -0,0 +1,40 @@ +"""A window that is minimized leaves its room to the others, and takes it back when restored.""" + +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: + """Minimizes the first of `clients`, which are tiled windows of the first workspace in a + container each, with more than two of them, and restores it.""" + target = clients[0] + others = clients[1:] + + 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) + platform.minimize(target) + checks.check( + f"with {target.title} minimized 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 :]), + ) + + platform.activate(target) + checks.check( + f"restored, {target.title} and the others are tiled where the layout says", + platform.wait_for(lambda: tiled(platform, clients), timeout=20), + ) + frames = [w.frame for c in clients if (w := platform.os_window(c)) is not None] + checks.check( + "... and not on each other", + not any(a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :]), + ) diff --git a/nix/tests/vm/lib/komorebi_vm/kde_platform.py b/nix/tests/vm/lib/komorebi_vm/kde_platform.py index c41dd6e3..f2b2cd90 100644 --- a/nix/tests/vm/lib/komorebi_vm/kde_platform.py +++ b/nix/tests/vm/lib/komorebi_vm/kde_platform.py @@ -125,6 +125,9 @@ class KdePlatform: def work_area(self) -> Rect: return Rect(0, 0, *self.size) + def minimize(self, client: Client) -> None: + self.kde.minimize(self.kde.wid(client.title)) + def activate(self, client: Client) -> None: self.kde.activate(self.kde.wid(client.title)) diff --git a/nix/tests/vm/lib/tests/fake_platform.py b/nix/tests/vm/lib/tests/fake_platform.py index 6d424b8e..a3707189 100644 --- a/nix/tests/vm/lib/tests/fake_platform.py +++ b/nix/tests/vm/lib/tests/fake_platform.py @@ -80,6 +80,7 @@ class FakePlatform: self.display_of: dict[str, int] = {} self.forgets_displays = False self.floats: list[str] = [] + self.minimized: list[str] = [] self.running = True self.placement: Any = None self.moves = moves @@ -222,6 +223,9 @@ class FakePlatform: if client.title in self.floats: self.floats.remove(client.title) return + if client.title in self.minimized: + self.minimized.remove(client.title) + return if client.title in self.unmanaged: self.unmanaged.remove(client.title) return @@ -247,7 +251,7 @@ class FakePlatform: return self._find(title)[1] def hidden(self, client: Client) -> bool: - if client.title in self.floats: + if client.title in self.floats or client.title in self.minimized: return False if client.title in self.unmanaged: return False @@ -258,7 +262,17 @@ class FakePlatform: def work_area(self) -> Rect: return Rect(0, 0, 1920, 1080) + def minimize(self, client: Client) -> None: + self._find_remove(client.title) + self.minimized.append(client.title) + self.focuses[self.current] = max(0, min(self.focus, len(self.containers) - 1)) + self._relayout() + def activate(self, client: Client) -> None: + if client.title in self.minimized: + self.minimized.remove(client.title) + self.containers.append([client.title]) + self._relayout() self.current, self.focus = self._find(client.title) stack = self.containers[self.focus] stack.insert(0, stack.pop(stack.index(client.title))) @@ -267,6 +281,8 @@ class FakePlatform: return Image.new("RGB", (4, 4)) def os_window(self, client: Client) -> OsWindow | None: + if client.title in self.minimized: + return OsWindow(client.title, Rect(0, 0, 0, 0), focused=False) if client.title in self.floats: return OsWindow(client.title, Rect(300, 300, 600, 400), focused=False) if client.title in self.unmanaged: diff --git a/nix/tests/vm/lib/tests/test_focus_moving.py b/nix/tests/vm/lib/tests/test_focus_moving.py index b5fe6dbc..9bb8de9d 100644 --- a/nix/tests/vm/lib/tests/test_focus_moving.py +++ b/nix/tests/vm/lib/tests/test_focus_moving.py @@ -11,6 +11,7 @@ from komorebi_vm.core.scenarios import ( hotplug, layouts, lifecycle, + minimizing, monocle, moving, placement, @@ -183,6 +184,27 @@ def test_a_float_that_stays_in_the_tiling_fails_floating() -> None: assert checks.failed > 0 +def test_a_daemon_that_is_right_passes_minimizing() -> None: + platform = FakePlatform() + checks = Checks() + clients = opened(platform, checks) + minimizing.run(platform, checks, clients) + assert checks.failed == 0, checks.failures + assert checks.passed > 3 + + +def test_a_daemon_that_keeps_the_room_of_a_minimized_window_fails_minimizing() -> None: + class Keeping(FakePlatform): + def _relayout(self) -> None: + pass + + platform = Keeping() + checks = Checks() + clients = opened(platform, checks) + minimizing.run(platform, checks, clients) + assert checks.failed > 0 + + def test_a_command_the_port_lacks_is_skipped_by_name() -> None: platform = FakePlatform() checks = Checks() diff --git a/nix/tests/vm/lib/tests/test_tiling.py b/nix/tests/vm/lib/tests/test_tiling.py index bacc2f74..8aa4e6ba 100644 --- a/nix/tests/vm/lib/tests/test_tiling.py +++ b/nix/tests/vm/lib/tests/test_tiling.py @@ -69,6 +69,9 @@ class FakePlatform: def komorebic(self, *args: str) -> str: return "" + def minimize(self, client: Client) -> None: + pass + def activate(self, client: Client) -> None: pass diff --git a/nix/tests/vm/suites/core-e2e/test.py b/nix/tests/vm/suites/core-e2e/test.py index 3d3edb67..71a91553 100644 --- a/nix/tests/vm/suites/core-e2e/test.py +++ b/nix/tests/vm/suites/core-e2e/test.py @@ -21,6 +21,7 @@ from komorebi_vm.core.scenarios import ( focus, layouts, lifecycle, + minimizing, monocle, moving, placement, @@ -452,6 +453,7 @@ checks.check( ) layouts.run(platform, checks, neutral) floating.run(platform, checks, neutral) +minimizing.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