feat(nix): the display_change scenario, and resizable_display

A display whose mode changes: the daemon's monitor follows, the windows
stay on a display and apart, and changed back they are where they were.
Platform.resizable_display says which display can change its mode, or None
and the scenario is skipped; KDE says None, as the virtual outputs of the
headless KWin have one mode. Platform.resize_display changes the mode.
This commit is contained in:
LGUG2Z committed 2026-10-30 12:53:13 -07:00
1 parent 3beb1b82d9
commit 4db3f97e2e
8 files changed
+141 -5

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ platform". The sections the shared scenario repeats are gone; the rest are `kde_
| Was (section) | Now |
|---|---|
| 1, the daemon answers with both monitors; three windows on the left; the monitor's size; tiled | extra `setup` |
| 2, the scale of the left output changes and returns | extra `scale` |
| 2, the scale of the left output changes and returns | extra `scale` (KDE's scale is not a mode, so the shared `display_change` is skipped on KDE) |
| 3, `move-to-monitor 1`: containers, KWin's `OutputChange`, tiled on the right | extra `sent_by_the_daemon` |
| 4, the user moves a window to the right output | shared `hotplug.user_move` (the suite runs it before the unplug) |
| 5, one monitor after the unplug | shared "after a display is unplugged the daemon has one monitor fewer" |
@@ -214,6 +214,18 @@ class Platform(Protocol):
after it plugged one in, unless its suite started the platform with more than one."""
...
def resizable_display(self) -> int | None:
"""The place in `displays()` of a display whose mode (its resolution) can be changed, or
`None` when the platform has none that can, and a scenario that needs one is skipped with
the reason. A scenario plugs in a display with `add_display` before it asks."""
...
def resize_display(self, index: int, width: int, height: int) -> None:
"""Gives the display `resizable_display` named another mode, `width` by `height` pixels,
and returns when the operating system has it: `displays()` says so. The daemon learns of
it later, so a scenario waits for its state to follow."""
...
def close(self, client: Client) -> None:
"""Closes the window, as its close button would, and returns without waiting for it to be
gone. Raises if there is no such window."""
@@ -0,0 +1,68 @@
"""A display whose mode changes: the daemon's monitor follows, and the windows stay put."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.platform import Client, Platform
from komorebi_vm.core.scenarios.hotplug import _in_one_of
from komorebi_vm.core.scenarios.support import positions
def _size_follows(platform: Platform, index: int, size: tuple[int, int]) -> bool:
"""The operating system's display and the daemon's monitor both have this size."""
displays, monitors = platform.displays(), platform.state().monitors
return (
index < len(displays)
and index < len(monitors)
and (displays[index].w, displays[index].h) == size
and (monitors[index].size.w, monitors[index].size.h) == size
)
def _clear(platform: Platform, clients: list[Client]) -> bool:
"""Every window is on a display, and none is over another."""
frames = [w.frame for c in clients if (w := platform.os_window(c)) is not None]
return _in_one_of(platform, clients, platform.displays()) and 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 mode of a display to a smaller one and back, and checks that the daemon's
monitor has the size of each, that the windows are inside the displays and apart while it is
small, and that they are where they were when the display is as it was.
`clients` are windows the daemon manages, each in a container of its own. A second display is
plugged in first if the platform has only one, and the platform says which display can change
its mode: where none can, the scenario is skipped.
"""
if len(platform.displays()) < 2:
platform.add_display()
platform.wait_for(lambda: len(platform.state().monitors) == len(platform.displays()))
index = platform.resizable_display()
if index is None:
checks.skip(
"a display changes its mode", "the platform cannot change the mode of a display"
)
return
before = platform.displays()[index]
size = (1280, 720) if before.w > 1280 else (1024, 768)
there = positions(platform, clients)
platform.resize_display(index, *size)
checks.check(
f"the display has the mode {size[0]}x{size[1]} and the daemon's monitor follows",
platform.wait_for(lambda: _size_follows(platform, index, size), timeout=30),
)
checks.check(
"... every window is on a display and clear of the others",
platform.wait_for(lambda: _clear(platform, clients), timeout=30),
)
platform.resize_display(index, before.w, before.h)
checks.check(
"changed back, the display and the monitor have their size again",
platform.wait_for(lambda: _size_follows(platform, index, (before.w, before.h)), timeout=30),
)
checks.check(
"... and every window is where it was",
platform.wait_for(lambda: positions(platform, clients) == there, timeout=30),
)
@@ -188,6 +188,14 @@ class KdePlatform:
self.kde.outputs.disable(names[-1])
self.kde.wait_for(lambda: len(self.kde.outputs.names()) == len(names) - 1, timeout=20)
def resizable_display(self) -> int | None:
"""None: the outputs of the headless KWin are virtual and have the one mode they were
started with (`kscreen-doctor` can only change their scale, which is not a mode)."""
return None
def resize_display(self, index: int, width: int, height: int) -> None:
raise AssertionError("no output of this session has another mode to change to")
def close(self, client: Client) -> None:
self.kde.close(self._wid(client))
+14 -2
View File
@@ -76,6 +76,8 @@ class FakePlatform:
cycles_in_monocle: bool = True,
no_op_in_monocle: bool = True,
follows_user_moves: bool = True,
resizable: bool = True,
follows_modes: bool = True,
) -> None:
self.panel = panel
"""The height of a panel along the bottom of the first display, which the work area leaves
@@ -84,6 +86,10 @@ class FakePlatform:
"""A daemon that tiles on the whole display, under the panel."""
self.second = second
"""The rectangle of the second display, when it is not one of the first's size."""
self.resizable = resizable
self.follows_modes = follows_modes
self.mode: dict[int, tuple[int, int]] = {}
"""The mode of the displays that are not 1920 by 1080."""
self.follows_user_moves = follows_user_moves
self.cycles_in_monocle = cycles_in_monocle
self.no_op_in_monocle = no_op_in_monocle
@@ -376,14 +382,20 @@ class FakePlatform:
def displays(self) -> list[Rect]:
return [SCREEN, *self._others()][: self.display_count]
def resizable_display(self) -> int | None:
return self.display_count - 1 if self.resizable and self.display_count > 1 else None
def _others(self) -> list[Rect]:
"""The displays after the first, side by side to its right."""
found = []
x = SCREEN.w
for n in range(1, max(self.display_count, 1)):
size = self.second if self.second is not None and n == 1 else SCREEN
found.append(Rect(x, 0, size.w, size.h))
x += size.w
width, height = (size.w, size.h)
if self.follows_modes:
width, height = self.mode.get(n, (width, height))
found.append(Rect(x, 0, width, height))
x += width
return found
def add_display(self) -> None:
+28
View File
@@ -5,6 +5,7 @@ from komorebi_vm.core.checks import Checks
from komorebi_vm.core.geometry import Rect
from komorebi_vm.core.scenarios import (
commands,
display_change,
handover,
hotplug,
monocle,
@@ -201,3 +202,30 @@ def test_a_daemon_that_ignores_a_window_moved_to_the_other_display_fails() -> No
clients = opened(platform, checks)
hotplug.user_move(platform, checks, clients)
assert any("the daemon has the window on the other monitor" in f for f in checks.failures)
def test_a_daemon_that_follows_a_mode_change_passes_display_change() -> None:
platform = FakePlatform()
checks = Checks()
clients = opened(platform, checks)
base = checks.passed
display_change.run(platform, checks, clients)
assert checks.failed == 0, checks.failures
assert checks.passed - base == 4
assert platform.displays()[1].w == 1920
def test_a_platform_with_no_resizable_display_skips_display_change() -> None:
platform = FakePlatform(resizable=False)
checks = Checks()
clients = opened(platform, checks)
display_change.run(platform, checks, clients)
assert checks.failed == 0 and len(checks.skipped) == 1, checks.skipped
def test_a_daemon_that_does_not_follow_a_mode_change_fails_display_change() -> None:
platform = FakePlatform(follows_modes=False)
checks = Checks()
clients = opened(platform, checks)
display_change.run(platform, checks, clients)
assert any("the daemon's monitor follows" in f for f in checks.failures)
+6
View File
@@ -54,6 +54,12 @@ class FakePlatform:
def remove_display(self) -> None:
pass
def resizable_display(self) -> int | None:
return None
def resize_display(self, index: int, width: int, height: int) -> None:
pass
def komorebic_status(self, *args: str) -> tuple[int, str]:
return 0, ""
+4 -2
View File
@@ -4,10 +4,11 @@
# KWin can tell is in `komorebi_vm.platforms.kde.extras.hotplug`: that `kscreen-doctor` changing
# the scale of an output reaches komorebi as a change of that monitor's size, and that KWin
# reports a window on another output when komorebi sent it there. A window the user moves to the
# other output is the shared `user_move`. `komorebi/tests/monitor_resize.rs`,
# other output is the shared `user_move`. The shared `display_change` is skipped here: the virtual
# outputs of the headless KWin have one mode, so `KdePlatform.resizable_display` has none. `komorebi/tests/monitor_resize.rs`,
# `komorebi/tests/hotplug.rs` and `komorebi/tests/follow_output.rs` check the same against the fake.
from komorebi_vm import Checks, Kde
from komorebi_vm.core.scenarios import hotplug
from komorebi_vm.core.scenarios import display_change, hotplug
from komorebi_vm.core.suite import platform_only, run_suite, shared
from komorebi_vm.kde_platform import KdePlatform
from komorebi_vm.platforms.kde.extras import hotplug as kde_hotplug
@@ -34,6 +35,7 @@ run_suite(
shared(hotplug.user_move, platform, checks, clients),
shared(hotplug.run, platform, checks, clients),
shared(hotplug.user_move, platform, checks, clients),
shared(display_change.run, platform, checks, clients),
platform_only("kde", kde_hotplug.after, platform, checks, clients),
)