diff --git a/nix/tests/vm/lib/komorebi_vm/core/platform.py b/nix/tests/vm/lib/komorebi_vm/core/platform.py index 14ddf242..f3257b43 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/platform.py +++ b/nix/tests/vm/lib/komorebi_vm/core/platform.py @@ -150,10 +150,15 @@ class Platform(Protocol): def hidden(self, client: Client) -> bool: """The window exists but is out of sight because the daemon put it away: the other windows - of a stack, the windows of another workspace, those behind a monocle. + of a stack, the windows of a workspace that is not the one its display shows, those + behind a monocle. - That is a window parked on a desktop of its own on KDE, and cloaked on Windows. A window - the user minimized is not hidden in this sense. + It is false for a window the system does not have, for one the user minimized, and for one + that floats. A scenario that asks for a window to be put away also asks the daemon where + it is (`state()`), because a port may answer true for any window that is not on the + screen, whoever took it off: on KDE that is one on a virtual desktop that is not shown, + on Windows a cloaked one, which includes the windows of another virtual desktop. A scenario + that asks for windows to be in view counts those the system has (`support.in_view`). """ ... diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py index b61444a3..6d20321a 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py @@ -16,6 +16,18 @@ def os_focused(platform: Platform, clients: list[Client]) -> str: return "" +def in_view(platform: Platform, clients: list[Client]) -> list[str]: + """The titles of the windows of `clients` that are on the screen: the operating system has + them, and the daemon has not put them away. Sorted. + + A window the system does not have is not in view, though `Platform.hidden` says no for it + too: a window that is gone must not count as one that is shown. + """ + return sorted( + c.title for c in clients if platform.os_window(c) is not None and not platform.hidden(c) + ) + + def positions(platform: Platform, clients: list[Client]) -> dict[str, tuple[int, int]]: """Where the operating system has each window, by title. diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspace_moves.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspace_moves.py index f63f95b2..c45db175 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspace_moves.py +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspace_moves.py @@ -4,11 +4,7 @@ away.""" 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 _in_view(platform: Platform, clients: list[Client]) -> list[str]: - return sorted(c.title for c in clients if not platform.hidden(c)) +from komorebi_vm.core.scenarios.support import focus_agrees, in_view def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: @@ -24,7 +20,7 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: platform.komorebic("move-to-workspace", "1") checks.check( "after 'move-to-workspace 1' the window is there, in view, and the others are put away", - platform.wait_for(lambda: _in_view(platform, clients) == [target.title], timeout=20), + platform.wait_for(lambda: in_view(platform, clients) == [target.title], timeout=20), ) checks.check( "... the daemon has it on workspace 1", @@ -38,18 +34,18 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: platform.komorebic("focus-last-workspace") checks.check( "'focus-last-workspace' brings the others back and puts the window away", - platform.wait_for(lambda: _in_view(platform, clients) == rest, timeout=20), + platform.wait_for(lambda: in_view(platform, clients) == rest, timeout=20), ) platform.komorebic("focus-last-workspace") checks.check( "... and again, it goes back to the window", - platform.wait_for(lambda: _in_view(platform, clients) == [target.title], timeout=20), + platform.wait_for(lambda: in_view(platform, clients) == [target.title], timeout=20), ) platform.komorebic("move-to-workspace", "0") checks.check( "'move-to-workspace 0' has every window in view again", - platform.wait_for(lambda: _in_view(platform, clients) == everyone, timeout=20), + platform.wait_for(lambda: in_view(platform, clients) == everyone, timeout=20), ) checks.check( "... tiled where the layout says", diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspaces.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspaces.py index 57c963c4..b2dc9991 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspaces.py +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/workspaces.py @@ -3,11 +3,7 @@ others away.""" 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 - - -def _in_view(platform: Platform, clients: list[Client]) -> list[str]: - return sorted(c.title for c in clients if not platform.hidden(c)) +from komorebi_vm.core.scenarios.support import focus_agrees, in_view, os_focused def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: @@ -21,7 +17,7 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: platform.activate(last) platform.wait_for(lambda: focus_agrees(platform, clients, last.title)) checks.check( - "every window is in view", _in_view(platform, clients) == sorted(c.title for c in clients) + "every window is in view", in_view(platform, clients) == sorted(c.title for c in clients) ) platform.komorebic("send-to-workspace", "1") @@ -35,15 +31,15 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: ) checks.check( "... and the others are still in view", - platform.wait_for(lambda: _in_view(platform, clients) == rest), + platform.wait_for(lambda: in_view(platform, clients) == rest), ) platform.komorebic("focus-workspace", "1") - platform.wait_for(lambda: _in_view(platform, clients) == [last.title]) - print(f" in view after the switch: {_in_view(platform, clients)}") + platform.wait_for(lambda: in_view(platform, clients) == [last.title]) + print(f" in view after the switch: {in_view(platform, clients)}") checks.check( "after 'focus-workspace 1' only the window sent there is in view", - platform.wait_for(lambda: _in_view(platform, clients) == [last.title]), + platform.wait_for(lambda: in_view(platform, clients) == [last.title]), ) checks.check( "... it has the focus, and the daemon agrees", @@ -53,7 +49,7 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: platform.komorebic("focus-workspace", "0") checks.check( "after 'focus-workspace 0' the others are in view and the one sent away is put away", - platform.wait_for(lambda: _in_view(platform, clients) == rest), + platform.wait_for(lambda: in_view(platform, clients) == rest), ) checks.check( "... and one of them has the focus", diff --git a/nix/tests/vm/lib/komorebi_vm/kde_platform.py b/nix/tests/vm/lib/komorebi_vm/kde_platform.py index 3382a878..93c5a880 100644 --- a/nix/tests/vm/lib/komorebi_vm/kde_platform.py +++ b/nix/tests/vm/lib/komorebi_vm/kde_platform.py @@ -116,7 +116,10 @@ class KdePlatform: """The window is on the parking desktop, or on a desktop that is not the one in view. KDE keeps the windows of a workspace on a virtual desktop of its own and parks the ones a - stack or a monocle puts away, so both are out of sight. + stack or a monocle puts away, so both are out of sight. That is every window that is on a + desktop that is not shown, whoever put it there: this is the quirk + `Platform.hidden` warns of. With more than one output, the desktop in view is that of + the output KWin considers active, so only the windows of the first are certain. """ wid = self.kde.wid(client.title) if wid == "": diff --git a/nix/tests/vm/lib/tests/test_focus_moving.py b/nix/tests/vm/lib/tests/test_focus_moving.py index cd0c6a3b..5dd492e9 100644 --- a/nix/tests/vm/lib/tests/test_focus_moving.py +++ b/nix/tests/vm/lib/tests/test_focus_moving.py @@ -2,7 +2,7 @@ from komorebi_vm.core.checks import Checks from komorebi_vm.core.geometry import Rect -from komorebi_vm.core.platform import OsWindow +from komorebi_vm.core.platform import Client, OsWindow from komorebi_vm.core.scenarios import ( closing, commands, @@ -72,6 +72,23 @@ def test_a_move_that_loses_the_focus_fails() -> None: assert any("keeps the focus" in f for f in checks.failures) +def test_a_window_that_is_gone_is_not_in_view_for_workspaces() -> None: + """`hidden` is false for a window the system does not have, which is not one that is shown.""" + + class Vanishes(FakePlatform): + def os_window(self, client: Client) -> OsWindow | None: + return None if client.title == "win1" else super().os_window(client) + + def hidden(self, client: Client) -> bool: + return False if client.title == "win1" else super().hidden(client) + + platform = Vanishes() + checks = Checks() + clients = opened(platform, checks) + workspaces.run(platform, checks, clients) + assert any("in view" in f for f in checks.failures) + + def test_a_daemon_that_is_right_passes_stacks() -> None: platform = FakePlatform() checks = Checks()