mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 22:33:12 +01:00
feat(nix): the handover scenario is shared
minimize, unmanage and manage on the focused window now run through the neutral platform. The check that the unmanaged window is centered is neutral: inside the work area and not on a tile of the layout.
This commit is contained in:
1 parent
8b64b3373a
commit
7d32b02ec8
6 files changed
+121
-50
No files matched your search
@@ -46,7 +46,7 @@ The suite had its own layout loop (section 2) and then called the shared `layout
|
||||
| 2, each window where the daemon last asked KWin for it | extra `layouts_by_count` (KDE only: reads the daemon's log) |
|
||||
| 3, the layouts and the sweep of commands | shared `layouts` and `sweep` |
|
||||
| 3, `replace-configuration` made the window manager from the file | extra `replace_configuration` |
|
||||
| 3b, `minimize`, `unmanage`, `manage` | extra `handover` |
|
||||
| 3b, `minimize`, `unmanage`, `manage` | shared `handover`; the check that the unmanaged window is centered is now "inside the work area and not on a tile of the layout" |
|
||||
| 3c, a title rule decides when the window has its title | shared `title_rule` (the window renames itself through `spawn(rename_to=, after=)`). Not kept: the daemon-log line "should not be managed" for the first title, and `healthy` after it |
|
||||
| 4, every command that only prints | shared `prints` |
|
||||
| 4, `komorebic query ...`, `quick-save-resize`, `save-resize` | extra `queries` (candidates for the shared list) |
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
"""`minimize`, `unmanage` and `manage`: the daemon lets go of the focused window, and takes it up
|
||||
again."""
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.platform import Client, Platform
|
||||
from komorebi_vm.core.scenarios.support import focus_agrees
|
||||
from komorebi_vm.core.scenarios.tiling import _where_the_layout_says
|
||||
|
||||
|
||||
def _on_a_tile(platform: Platform, client: Client) -> bool:
|
||||
"""The window is where the daemon's layout puts one of its tiles."""
|
||||
window = platform.os_window(client)
|
||||
layout = platform.state().workspace().latest_layout
|
||||
return window is not None and any(
|
||||
_where_the_layout_says(window.frame, tile, platform.tolerance) for tile in layout
|
||||
)
|
||||
|
||||
|
||||
def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""Runs `minimize`, `unmanage` and `manage` on the window that has the focus, which is one of
|
||||
`clients`: tiled windows of the first workspace, in a container each.
|
||||
|
||||
They take a window out of the daemon's hands, so a sweep of commands does not run them. The
|
||||
window is tiled again at the end.
|
||||
"""
|
||||
title = platform.state().focused_title()
|
||||
target = Client(title)
|
||||
before = platform.state().managed()
|
||||
platform.wait_for(lambda: focus_agrees(platform, clients, title), timeout=10)
|
||||
|
||||
def has_let_go() -> bool:
|
||||
return platform.state().managed() == before - 1 and platform.os_window(target) is not None
|
||||
|
||||
def has_it() -> bool:
|
||||
return platform.state().managed() == before and _on_a_tile(platform, target)
|
||||
|
||||
platform.komorebic("minimize")
|
||||
checks.check(
|
||||
f"minimize: the daemon lets go of {title}, which stays open",
|
||||
platform.wait_for(has_let_go, timeout=10),
|
||||
)
|
||||
platform.activate(target)
|
||||
checks.check(f"{title}, restored, is tiled again", platform.wait_for(has_it, timeout=10))
|
||||
|
||||
platform.wait_for(lambda: focus_agrees(platform, clients, title), timeout=10)
|
||||
platform.komorebic("unmanage")
|
||||
checks.check(
|
||||
f"unmanage: the daemon lets go of {title}, which stays open",
|
||||
platform.wait_for(has_let_go, timeout=10),
|
||||
)
|
||||
area = platform.work_area()
|
||||
|
||||
def left_alone() -> bool:
|
||||
window = platform.os_window(target)
|
||||
return (
|
||||
window is not None and window.frame.inside(area, 2) and not _on_a_tile(platform, target)
|
||||
)
|
||||
|
||||
checks.check(
|
||||
f"{title} is inside the work area and not on a tile of the layout",
|
||||
platform.wait_for(left_alone, timeout=10),
|
||||
)
|
||||
platform.komorebic("manage")
|
||||
checks.check(f"manage: {title} is tiled again", platform.wait_for(has_it, timeout=10))
|
||||
@@ -6,7 +6,7 @@ command is understood and leaves the daemon healthy, as the operating system see
|
||||
reads KWin (`kdotool`) and the daemon's log.
|
||||
|
||||
The suite runs `setup`, `layouts_by_count`, the shared `layouts` and `sweep`,
|
||||
`replace_configuration`, `handover`, the shared `title_rule` and `prints`, `queries` and
|
||||
`replace_configuration`, the shared `handover`, `title_rule` and `prints`, `queries` and
|
||||
`at_the_end`.
|
||||
The daemon runs on a session with two outputs, and `clients` are five windows on the first.
|
||||
"""
|
||||
@@ -173,49 +173,6 @@ def replace_configuration(platform: KdePlatform, checks: Checks, clients: list[C
|
||||
)
|
||||
|
||||
|
||||
def handover(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""`minimize`, `unmanage` and `manage` on the focused window: the daemon lets go of it, and
|
||||
takes it up again.
|
||||
|
||||
They take a window out of the daemon's hands, so the shared sweep does not run them.
|
||||
"""
|
||||
kde = platform.kde
|
||||
focused = kde.active()
|
||||
title = kde.title(focused)
|
||||
before = kde.managed()
|
||||
kde.wait_for(lambda: kde.focused_title() == title, timeout=10)
|
||||
kde.komorebic("minimize")
|
||||
checks.check(
|
||||
f"minimize: the daemon lets go of {title} when KWin minimizes it",
|
||||
kde.wait_for(lambda: kde.managed() == before - 1, timeout=10) and kde.wid(title) != "",
|
||||
)
|
||||
kde.activate(focused)
|
||||
checks.check(
|
||||
f"{title}, restored, is tiled again",
|
||||
kde.wait_for(lambda: kde.managed() == before and healthy(platform) == 0, timeout=10),
|
||||
)
|
||||
kde.wait_for(lambda: kde.focused_title() == title, timeout=10)
|
||||
kde.komorebic("unmanage")
|
||||
checks.check(
|
||||
f"unmanage: the daemon lets go of {title}, which stays open",
|
||||
kde.wait_for(lambda: kde.managed() == before - 1, timeout=10) and kde.wid(title) != "",
|
||||
)
|
||||
width, height = platform.size[0] // OUTPUTS, platform.size[1]
|
||||
|
||||
def centered() -> bool:
|
||||
r = kde.rect(focused)
|
||||
return (
|
||||
abs(r.x + r.w // 2 - width // 2) <= CELL and abs(r.y + r.h // 2 - height // 2) <= CELL
|
||||
)
|
||||
|
||||
checks.check(f"{title} is in the middle of the work area", kde.wait_for(centered, timeout=10))
|
||||
kde.komorebic("manage")
|
||||
checks.check(
|
||||
f"manage: {title} is tiled again",
|
||||
kde.wait_for(lambda: kde.managed() == before and healthy(platform) == 0, timeout=10),
|
||||
)
|
||||
|
||||
|
||||
def queries(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""`komorebic query` answers, and the resize commands that save and load are understood."""
|
||||
kde = platform.kde
|
||||
|
||||
@@ -65,6 +65,8 @@ class FakePlatform:
|
||||
second: Rect | None = None,
|
||||
follows_renames: bool = True,
|
||||
honours_ignore: bool = True,
|
||||
unmanages: bool = True,
|
||||
manages: bool = True,
|
||||
) -> None:
|
||||
self.panel = panel
|
||||
"""The height of a panel along the bottom of the first display, which the work area leaves
|
||||
@@ -73,6 +75,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.unmanages = unmanages
|
||||
self.manages = manages
|
||||
self.let_go: list[str] = []
|
||||
"""The windows `unmanage` let go of, the last one at the end."""
|
||||
self.follows_renames = follows_renames
|
||||
self.honours_ignore = honours_ignore
|
||||
self.clock = 0.0
|
||||
@@ -579,6 +585,23 @@ class FakePlatform:
|
||||
case ("flip-layout", "horizontal"):
|
||||
self.flipped = not self.flipped
|
||||
self._relayout()
|
||||
case ("minimize",):
|
||||
self.minimize(Client(self.containers[self.focus][0]))
|
||||
case ("unmanage",):
|
||||
title = self.containers[self.focus][0]
|
||||
if self.unmanages:
|
||||
self._find_remove(title)
|
||||
self.unmanaged.append(title)
|
||||
self.let_go.append(title)
|
||||
self.focus = max(0, min(self.focus, len(self.containers) - 1))
|
||||
self._relayout()
|
||||
case ("manage",):
|
||||
if self.let_go and self.manages:
|
||||
title = self.let_go.pop()
|
||||
self.unmanaged.remove(title)
|
||||
self.containers.append([title])
|
||||
self.focus = len(self.containers) - 1
|
||||
self._relayout()
|
||||
case ("toggle-pause",):
|
||||
self.paused = not self.paused
|
||||
case ("toggle-tiling",):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
are wrong in one way."""
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.scenarios import title_rule
|
||||
from komorebi_vm.core.scenarios import handover, title_rule
|
||||
from tests.fake_platform import FakePlatform
|
||||
|
||||
|
||||
@@ -36,3 +36,29 @@ def test_a_daemon_that_misses_the_rename_fails_title_rule() -> None:
|
||||
opened(platform, checks)
|
||||
title_rule.run(platform, checks)
|
||||
assert any("it is tiled" in f for f in checks.failures)
|
||||
|
||||
|
||||
def test_a_daemon_that_lets_go_and_takes_up_again_passes_handover() -> None:
|
||||
platform = FakePlatform()
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
base = checks.passed
|
||||
handover.run(platform, checks, clients)
|
||||
assert checks.failed == 0, checks.failures
|
||||
assert checks.passed - base == 5
|
||||
|
||||
|
||||
def test_a_daemon_that_keeps_an_unmanaged_window_fails_handover() -> None:
|
||||
platform = FakePlatform(unmanages=False)
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
handover.run(platform, checks, clients)
|
||||
assert any("unmanage" in f for f in checks.failures)
|
||||
|
||||
|
||||
def test_a_daemon_that_does_not_manage_again_fails_handover() -> None:
|
||||
platform = FakePlatform(manages=False)
|
||||
checks = Checks()
|
||||
clients = opened(platform, checks)
|
||||
handover.run(platform, checks, clients)
|
||||
assert any("manage: " in f for f in checks.failures)
|
||||
@@ -5,12 +5,13 @@
|
||||
# (`komorebi_vm.core.scenarios.commands`, which run on Windows too) check that, for every layout with
|
||||
# five windows and for every command, and that a command is understood (exit status 0). What only
|
||||
# a real KWin can tell is in `komorebi_vm.platforms.kde.extras.commands`: every layout with fewer
|
||||
# windows, that what the daemon asks KWin for is what KWin carries out, and the commands that take
|
||||
# a window out of the daemon's hands. The Rust tests check what each command does against the fake.
|
||||
# windows, and that what the daemon asks KWin for is what KWin carries out. The commands that take
|
||||
# a window out of the daemon's hands and a title rule are shared scenarios. The Rust tests check
|
||||
# what each command does against the fake.
|
||||
import shlex
|
||||
|
||||
from komorebi_vm import Checks, Kde
|
||||
from komorebi_vm.core.scenarios import commands, title_rule
|
||||
from komorebi_vm.core.scenarios import commands, handover, title_rule
|
||||
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 commands as kde_commands
|
||||
@@ -44,7 +45,7 @@ run_suite(
|
||||
platform_only("kde", kde.komorebic, "change-layout", "bsp"),
|
||||
shared(commands.sweep, *args, CONFIG),
|
||||
platform_only("kde", kde_commands.replace_configuration, *args),
|
||||
platform_only("kde", kde_commands.handover, *args),
|
||||
shared(handover.run, *args),
|
||||
shared(title_rule.run, platform, checks),
|
||||
shared(commands.prints, platform, checks),
|
||||
platform_only("kde", kde_commands.queries, *args),
|
||||
|
||||
Reference in new issue
Block a user