diff --git a/e2e/platforms/tart_macos/macos_platform.py b/e2e/platforms/tart_macos/macos_platform.py index 46f4f480..dee462e5 100644 --- a/e2e/platforms/tart_macos/macos_platform.py +++ b/e2e/platforms/tart_macos/macos_platform.py @@ -35,6 +35,10 @@ LAUNCHES = 3 # the programs whose windows are not for the daemon to tile: the Terminal the agent runs in, and # the desktop widgets of the stock image (Notification Center draws them as windows) IGNORED_APPS = ("Terminal", "Notification Center") +# macOS does not let a window go entirely off the screen, so the daemon parks one with a sliver of it +# on the display (1 px in the corner it hides a window in, 5 px for one that scrolled away): a window +# with no more than this showing in either direction is put away +HIDDEN_SLIVER = 5 def with_ignored_apps(config: dict[str, Any]) -> dict[str, Any]: @@ -48,6 +52,14 @@ def with_ignored_apps(config: dict[str, Any]) -> dict[str, Any]: return merged +def _shows_more_than_a_sliver(frame: Rect, display: Rect) -> bool: + """Whether more than `HIDDEN_SLIVER` pixels of the window are on the display, in both + directions: a window that is cut to a thin strip is put away as much as one that is gone.""" + width = min(frame.x + frame.w, display.x + display.w) - max(frame.x, display.x) + height = min(frame.y + frame.h, display.y + display.h) - max(frame.y, display.y) + return width > HIDDEN_SLIVER and height > HIDDEN_SLIVER + + class MacosPlatform: """One macOS guest: its agent, and the daemon in it.""" @@ -264,14 +276,15 @@ class MacosPlatform: ) def hidden(self, client: Client) -> bool: - # the daemon puts a window of another workspace away by moving it off every display; a - # minimized one is the user's, and one that is on a display is in view + # the daemon puts a window of another workspace away by moving it to the corner of its + # display, with a sliver showing (`HIDDEN_SLIVER`); a minimized one is the user's, and one + # that shows more than that is in view window = self._find(client.title) if window is None or window["minimized"]: return False f = window["frame"] frame = Rect(f["left"], f["top"], f["right"], f["bottom"]) - return not any(frame.overlaps(display) for display in self.displays()) + return not any(_shows_more_than_a_sliver(frame, d) for d in self.displays()) def close(self, client: Client) -> None: self._agent.call("close", title=client.title) diff --git a/e2e/platforms/tart_macos/tests/test_platform.py b/e2e/platforms/tart_macos/tests/test_platform.py index e60d1e40..9a805674 100644 --- a/e2e/platforms/tart_macos/tests/test_platform.py +++ b/e2e/platforms/tart_macos/tests/test_platform.py @@ -69,6 +69,26 @@ def test_a_window_off_every_display_is_hidden(tmp_path: Path) -> None: assert platform(agent, tmp_path).hidden(Client("away")) +@pytest.mark.parametrize( + "where", + [ + (1279, 799, 600, 400), # the corner the daemon hides a window in: one pixel shows + (-599, 799, 600, 400), # the other corner + (1275, 100, 600, 400), # a window that scrolled away: a 5 px strip + ], +) +def test_a_window_with_only_a_sliver_on_the_display_is_hidden( + where: tuple[int, int, int, int], tmp_path: Path +) -> None: + agent = FakeAgent([window("parked", *where)]) + assert platform(agent, tmp_path).hidden(Client("parked")) + + +def test_a_window_cut_to_more_than_a_sliver_is_in_view(tmp_path: Path) -> None: + agent = FakeAgent([window("cut", 1200, 100, 600, 400)]) + assert not platform(agent, tmp_path).hidden(Client("cut")) + + def test_a_window_on_the_display_is_not_hidden(tmp_path: Path) -> None: agent = FakeAgent([window("here", 100, 100, 400, 300)]) assert not platform(agent, tmp_path).hidden(Client("here"))