mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-13 12:23:38 +01:00
fix(e2e): a window the daemon parked with a sliver showing is put away
macOS does not let a window go entirely off the screen, so the daemon hides one at the corner of its display with one pixel of it showing (five for a window that scrolled away). The port called a window hidden only when no pixel of it was on a display, so it said every window the daemon had put away was in view. A window is put away now when no more than a sliver of it shows, in either direction. Against a real guest this takes workspaces, workspace_moves, monocle, lifecycle_hidden, rules_exe and startup_rules from failing to passing (18, 18, 22, 23, 5 and 5 checks).
This commit is contained in:
1 parent
18d7f9a506
commit
098b7d011e
2 files changed
+36
-3
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in new issue
Block a user