feat(nix): monocle focus behaviour is a shared scenario

monocle.focus_behaviour checks that with no-op the window keeps the work
area when the focus is moved in a direction, and with cycle another window
gets it. The KDE extra monocle_focus_behaviour is gone.
This commit is contained in:
LGUG2Z committed 2026-10-30 12:52:22 -07:00
1 parent 19c71eef9e
commit d14ce4d2e7
6 files changed
+115 -43

No files matched your search

+1 -1
View File
@@ -86,7 +86,7 @@ make. They are gone; what only KDE can read stayed, as `kde_core` steps after th
| 4, moving the focus moved no window | extra `windows_where_asked` after `focus` |
| 5, `move right`, `cycle-move previous`, the focus kept | shared `moving`; extra `windows_where_asked` after it |
| 6, monocle fills the work area, the state says so, back on the tile | shared `monocle` |
| 6, monocle focus behaviour `cycle` | extra `monocle_focus_behaviour` (a candidate for the shared scenario) |
| 6, monocle focus behaviour `cycle` | shared `monocle.focus_behaviour` (also `no-op`: the window keeps the work area); extra `windows_where_asked` after it |
| 7, minimize and restore | shared `minimizing`; extra `windows_where_asked` after it |
| 8, close, the others share the screen, the daemon manages the rest | shared `closing` |
| 8, KWin carried out every command | extra `bridge_did_everything` |
@@ -8,6 +8,17 @@ from komorebi_vm.core.scenarios.support import focus_agrees, os_focused, positio
PADDING = 120
def _fills(platform: Platform, client: Client) -> bool:
"""The window has the work area, up to the padding of the layout."""
window = platform.os_window(client)
area = platform.work_area()
return (
window is not None
and window.frame.w >= area.w - PADDING
and window.frame.h >= area.h - PADDING
)
def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
"""Toggles monocle on the focused one of `clients`, which are tiled windows of the first
workspace, each in a container of its own, and toggles it off again."""
@@ -15,15 +26,9 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
platform.activate(last)
platform.wait_for(lambda: focus_agrees(platform, clients, last.title))
before = positions(platform, clients)
area = platform.work_area()
def fills_the_work_area() -> bool:
window = platform.os_window(last)
return (
window is not None
and window.frame.w >= area.w - PADDING
and window.frame.h >= area.h - PADDING
)
return _fills(platform, last)
platform.komorebic("toggle-monocle")
checks.check(
@@ -64,3 +69,54 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None:
"... and the state has no monocle container",
platform.wait_for(lambda: platform.state().workspace().monocle is None),
)
def focus_behaviour(platform: Platform, checks: Checks, clients: list[Client]) -> None:
"""What `monocle-focus-behaviour` makes of focusing in a direction in a monocle: with `no-op`
the window keeps the work area, and with `cycle` another window gets it.
`clients` are two or more tiled windows of the first workspace, each in a container of its
own. The monocle is off and the behaviour is `no-op` at the end.
"""
first = clients[0]
platform.activate(first)
platform.wait_for(lambda: focus_agrees(platform, clients, first.title))
before = positions(platform, clients)
platform.komorebic("monocle-focus-behaviour", "no-op")
platform.komorebic("toggle-monocle")
platform.wait_for(lambda: _fills(platform, first), timeout=20)
platform.komorebic("focus", "right")
checks.check(
"with the no-op behaviour, focusing in a direction leaves the window the work area",
not platform.wait_for(lambda: os_focused(platform, clients) != first.title, timeout=3)
and _fills(platform, first),
)
platform.komorebic("monocle-focus-behaviour", "cycle")
platform.komorebic("focus", "right")
def another_has_it() -> bool:
title = os_focused(platform, clients)
return title not in ("", first.title) and _fills(platform, Client(title))
checks.check(
"with the cycle behaviour, focusing in a direction gives another window the work area",
platform.wait_for(another_has_it, timeout=20),
)
checks.check(
"... and the daemon's state has that window as the monocle container",
platform.wait_for(
lambda: (
[w.title for w in platform.state().workspace().monocle or []]
== [os_focused(platform, clients)]
)
),
)
platform.komorebic("toggle-monocle")
platform.komorebic("monocle-focus-behaviour", "no-op")
checks.check(
"the windows are tiled again, each on the tile it had",
platform.wait_for(lambda: positions(platform, clients) == before, timeout=20),
)
@@ -95,39 +95,6 @@ def focus_agrees_with_the_log(platform: KdePlatform, checks: Checks, clients: li
)
def monocle_focus_behaviour(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
"""With the `cycle` behaviour, focusing in a direction in a monocle gives another window the
work area. The behaviour is set back to `no-op`."""
kde = platform.kde
width, height = platform.size
def fills(wid: str) -> bool:
r = kde.rect(wid)
return r.w > width - 120 and r.h > height - 120
focused = kde.active()
kde.komorebic("monocle-focus-behaviour", "cycle")
kde.komorebic("toggle-monocle")
kde.wait_for(lambda: fills(focused), timeout=20)
kde.komorebic("focus", "right")
checks.check(
"with the cycle behaviour, focusing in a direction gives another window the work area",
kde.wait_for(lambda: kde.active() != focused and fills(kde.active()), timeout=20),
)
kde.komorebic("toggle-monocle")
kde.komorebic("monocle-focus-behaviour", "no-op")
checks.check(
"the windows are tiled again",
kde.wait_for(
lambda: (
all(_where_asked(platform, c.title) for c in clients)
and all(kde.rect(kde.wid(c.title)).w < width - 20 for c in clients)
),
timeout=20,
),
)
def fixtures(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
"""Keeps what `komorebic state` prints as files of the run, so that the unit tests of the
neutral core (tests/fixtures) are of a real state and not of one written from the serializer,
+13
View File
@@ -73,6 +73,8 @@ class FakePlatform:
matches_class: bool = True,
applies_rules_on_event: bool = True,
clears_rules: bool = True,
cycles_in_monocle: bool = True,
no_op_in_monocle: bool = True,
) -> None:
self.panel = panel
"""The height of a panel along the bottom of the first display, which the work area leaves
@@ -81,6 +83,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.cycles_in_monocle = cycles_in_monocle
self.no_op_in_monocle = no_op_in_monocle
self.monocle_cycles = False
"""The behaviour `monocle-focus-behaviour` set: focusing in a monocle cycles it."""
self.applies_rules_on_event = applies_rules_on_event
self.clears_rules = clears_rules
self.matches_class = matches_class
@@ -508,6 +514,13 @@ class FakePlatform:
self.follows_mouse = state == "enable" and not self.mouse_ignored
case ("toggle-focus-follows-mouse", *_):
self.follows_mouse = not self.follows_mouse and not self.mouse_ignored
case ("monocle-focus-behaviour", way):
self.monocle_cycles = way == "cycle"
case ("focus", "right") if self.monocle is not None:
cycles = self.monocle_cycles if self.no_op_in_monocle else True
if cycles and self.cycles_in_monocle:
self.focus = (self.focus + 1) % n
self.monocle = self.containers[self.focus][0]
case ("focus", "right"):
self.focus = min(self.focus + 1, n - 1)
case ("focus", "left"):
+36 -1
View File
@@ -3,7 +3,15 @@ are wrong in one way."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.geometry import Rect
from komorebi_vm.core.scenarios import commands, handover, placement, queries, rules, title_rule
from komorebi_vm.core.scenarios import (
commands,
handover,
monocle,
placement,
queries,
rules,
title_rule,
)
from tests.fake_platform import FakePlatform
@@ -147,3 +155,30 @@ def test_a_daemon_that_keeps_its_rules_when_cleared_fails_rules() -> None:
checks = Checks()
rules.run(platform, checks)
assert any("global state has none" in f for f in checks.failures), checks.failures
def test_a_daemon_that_cycles_a_monocle_only_when_told_passes_monocle_behaviour() -> None:
platform = FakePlatform()
checks = Checks()
clients = opened(platform, checks)
base = checks.passed
monocle.focus_behaviour(platform, checks, clients)
assert checks.failed == 0, checks.failures
assert checks.passed - base == 4
assert platform.monocle is None and not platform.monocle_cycles
def test_a_daemon_that_never_cycles_a_monocle_fails_monocle_behaviour() -> None:
platform = FakePlatform(cycles_in_monocle=False)
checks = Checks()
clients = opened(platform, checks)
monocle.focus_behaviour(platform, checks, clients)
assert any("with the cycle behaviour" in f for f in checks.failures), checks.failures
def test_a_daemon_that_cycles_a_monocle_with_no_op_fails_monocle_behaviour() -> None:
platform = FakePlatform(no_op_in_monocle=False)
checks = Checks()
clients = opened(platform, checks)
monocle.focus_behaviour(platform, checks, clients)
assert any("with the no-op behaviour" in f for f in checks.failures), checks.failures
+2 -1
View File
@@ -119,7 +119,8 @@ run_suite(
shared(padding.run, *args),
shared(monocle.run, *args),
platform_only("kde", kde_core.windows_where_asked, *args),
platform_only("kde", kde_core.monocle_focus_behaviour, *args),
shared(monocle.focus_behaviour, *args),
platform_only("kde", kde_core.windows_where_asked, *args),
shared(workspace_moves.run, *args),
shared(workspaces.run, *args),
# the third window is on workspace 1 now: the first is closed, and the second takes its room