mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
feat(nix): core-e2e as shared steps and KDE extras
This commit is contained in:
1 parent
2c58920db0
commit
5e0721bec4
2 files changed
+456
-467
No files matched your search
@@ -0,0 +1,353 @@
|
||||
"""What only KDE can tell about the daemon and a real KWin, round the shared scenarios of
|
||||
`core-e2e`.
|
||||
|
||||
The shared scenarios ask the operating system where the windows are and what has the focus. What
|
||||
is here reads the other side of the bridge: the frame the daemon last asked KWin for, the focus
|
||||
change it last handled (both from its log), the parking desktop, what KWin does when the daemon
|
||||
stops or crashes, and when KWin itself restarts.
|
||||
"""
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from komorebi_vm import daemon
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client
|
||||
from komorebi_vm.kde_platform import CELL, PARK, KdePlatform
|
||||
|
||||
OUTPUT_WIDTH = 1920
|
||||
|
||||
|
||||
def _asked(platform: KdePlatform, title: str) -> Rect | None:
|
||||
return daemon.asked(platform.kde.komorebi_log(), title)
|
||||
|
||||
|
||||
def _where_asked(platform: KdePlatform, title: str) -> bool:
|
||||
"""KWin has the window where the daemon asked: the same place, and the size up to a cell."""
|
||||
kde = platform.kde
|
||||
want, wid = _asked(platform, title), kde.wid(title)
|
||||
if want is None or wid == "":
|
||||
return False
|
||||
have = kde.rect(wid)
|
||||
return (
|
||||
(have.x, have.y) == (want.x, want.y)
|
||||
and 0 <= want.w - have.w < CELL
|
||||
and 0 <= want.h - have.h < CELL
|
||||
)
|
||||
|
||||
|
||||
def _focus_agrees(platform: KdePlatform) -> bool:
|
||||
"""The window KWin has focused is the one the daemon last handled a focus change for."""
|
||||
kde = platform.kde
|
||||
log = kde.komorebi_log()
|
||||
focus_changes = [e.window for e in daemon.events(log) if e.kind == "FocusChange"]
|
||||
active = kde.active()
|
||||
if not focus_changes or active == "":
|
||||
return False
|
||||
return daemon.window_ids(log).get(kde.title(active)) == focus_changes[-1]
|
||||
|
||||
|
||||
def _answering(platform: KdePlatform) -> bool:
|
||||
"""`komorebic monitor-information` is answered, with the session's one output."""
|
||||
status, out = platform.kde.run("komorebic monitor-information")
|
||||
return status == 0 and json.loads(out)[0]["size"]["right"] == OUTPUT_WIDTH
|
||||
|
||||
|
||||
def _parked(platform: KdePlatform, clients: list[Client]) -> list[str]:
|
||||
"""The titles of these windows that are on the parking desktop, which is the last desktop."""
|
||||
kde = platform.kde
|
||||
names = kde.desktop_names()
|
||||
if PARK not in names:
|
||||
return []
|
||||
park = names.index(PARK) + 1
|
||||
return sorted(
|
||||
c.title for c in clients if kde.wid(c.title) != "" and kde.desk(kde.wid(c.title)) == park
|
||||
)
|
||||
|
||||
|
||||
def _on_a_workspace_desktop(platform: KdePlatform, clients: list[Client]) -> bool:
|
||||
"""Every one of these windows that is open is on a desktop that is a workspace."""
|
||||
kde = platform.kde
|
||||
return all(kde.desk(kde.wid(c.title)) in (1, 2) for c in clients if kde.wid(c.title) != "")
|
||||
|
||||
|
||||
def _managed(platform: KdePlatform, clients: list[Client]) -> bool:
|
||||
state = platform.state()
|
||||
return all(state.workspace_of(c.title) is not None for c in clients)
|
||||
|
||||
|
||||
def start(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""The daemon loaded its script into KWin, which runs it, and answers komorebic."""
|
||||
kde = platform.kde
|
||||
checks.check(
|
||||
"the daemon loaded its script into KWin",
|
||||
kde.wait_for(lambda: "loaded the KWin bridge script" in kde.komorebi_log(), timeout=30),
|
||||
)
|
||||
checks.check("KWin runs the script", kde.script_loaded())
|
||||
checks.check(
|
||||
"the daemon is up and answering komorebic",
|
||||
kde.wait_for(lambda: _answering(platform), timeout=30),
|
||||
)
|
||||
|
||||
|
||||
def windows_where_asked(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""Every window is where the daemon last asked KWin for it."""
|
||||
kde = platform.kde
|
||||
checks.check(
|
||||
"every window is where the daemon asked for it",
|
||||
kde.wait_for(lambda: all(_where_asked(platform, c.title) for c in clients), timeout=20),
|
||||
)
|
||||
|
||||
|
||||
def focus_agrees_with_the_log(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""KWin and the daemon agree on the focused window: the one the daemon last handled a focus
|
||||
change for, by its log."""
|
||||
checks.check(
|
||||
"KWin and the daemon agree on the focused window",
|
||||
platform.kde.wait_for(lambda: _focus_agrees(platform)),
|
||||
)
|
||||
|
||||
|
||||
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,
|
||||
and stacks the windows with `stack left` and unstacks them."""
|
||||
kde = platform.kde
|
||||
out = kde.machine.out_dir
|
||||
(out / "state-kfde-tiled.json").write_text(json.dumps(kde.state(), indent=2))
|
||||
platform.activate(clients[-1])
|
||||
kde.komorebic("stack", "left")
|
||||
checks.check(
|
||||
"the windows are stacked",
|
||||
kde.wait_for(lambda: sorted(map(len, kde.containers())) == [1, 2]),
|
||||
)
|
||||
(out / "state-kfde-stack.json").write_text(json.dumps(kde.state(), indent=2))
|
||||
kde.komorebic("unstack")
|
||||
checks.check(
|
||||
"and unstacked",
|
||||
kde.wait_for(lambda: sorted(map(len, kde.containers())) == [1, 1, 1]),
|
||||
)
|
||||
|
||||
|
||||
# how many lines of the daemon's log `bridge_did_everything` has looked at
|
||||
_LOOKED_AT: dict[int, int] = {}
|
||||
_WINDOW_ID = re.compile(r'"id":"(\{[^}]+\})"')
|
||||
|
||||
|
||||
def bridge_did_everything(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""KWin carried out every command the daemon sent it since the last time this looked: the
|
||||
daemon logs a warning when the bridge could not do one.
|
||||
|
||||
A command for a window that is gone is not a failure: the daemon asks for the place of a window
|
||||
that a scenario closes a moment later, and KWin has nothing to place. Only a window that is
|
||||
still open counts.
|
||||
"""
|
||||
kde = platform.kde
|
||||
lines = kde.komorebi_log().splitlines()
|
||||
start = _LOOKED_AT.get(id(platform), 0)
|
||||
_LOOKED_AT[id(platform)] = len(lines)
|
||||
alive = set(kde.run("kdotool search --class foot")[1].split())
|
||||
failed = []
|
||||
for i in range(start, len(lines)):
|
||||
if "the bridge could not do" not in lines[i]:
|
||||
continue
|
||||
ids = set(_WINDOW_ID.findall(lines[i]))
|
||||
# a window id that is not written the way the daemon writes it is not a window that is gone
|
||||
known_form = all(a.startswith("{") for a in alive)
|
||||
if not ids or ids & alive or not known_form:
|
||||
failed.append(i)
|
||||
for i in failed[:3]:
|
||||
print(" " + "\n ".join(x[-200:] for x in lines[max(0, i - 3) : i + 1]))
|
||||
checks.check("KWin carried out every command since the last step", not failed)
|
||||
|
||||
|
||||
def no_window_is_left(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""Closes `clients` that are open, and the daemon has no window."""
|
||||
kde = platform.kde
|
||||
for client in clients:
|
||||
if kde.wid(client.title) != "":
|
||||
platform.close(client)
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
|
||||
|
||||
def _focus(platform: KdePlatform, client: Client, other: Client) -> None:
|
||||
"""Gives the window the focus and waits until the daemon has it focused too, so that a command
|
||||
that acts on the focused window acts on this one.
|
||||
|
||||
The other window is given the focus first: KWin sends no event for the focus of a window that
|
||||
already has it, and a daemon that has just started may have another one focused.
|
||||
"""
|
||||
platform.activate(other)
|
||||
platform.activate(client)
|
||||
platform.kde.wait_for(
|
||||
lambda: (
|
||||
platform.state().focused_title(monitor=platform.state().focused_monitor) == client.title
|
||||
),
|
||||
timeout=20,
|
||||
)
|
||||
|
||||
|
||||
def _diagnose(platform: KdePlatform, clients: list[Client], what: str) -> None:
|
||||
"""Prints where the daemon and KWin have the windows, for a failure to be read."""
|
||||
kde = platform.kde
|
||||
state = platform.state()
|
||||
desks = {c.title: kde.desk(kde.wid(c.title)) for c in clients if kde.wid(c.title) != ""}
|
||||
focus = state.focused_title(monitor=state.focused_monitor)
|
||||
active = kde.title(kde.active()) if kde.active() else ""
|
||||
print(f" {what}: desktops {kde.desktop_names()}, windows on {desks}, focus {focus!r},")
|
||||
print(f" KWin's active window is {active!r}")
|
||||
print(f" managed {[w.title for w in state.workspace().windows()]}")
|
||||
|
||||
|
||||
def _two_windows(platform: KdePlatform) -> list[Client]:
|
||||
clients = [platform.spawn("park1"), platform.spawn("park2")]
|
||||
platform.kde.wait_for(lambda: _managed(platform, clients), timeout=20)
|
||||
_focus(platform, clients[1], clients[0])
|
||||
return clients
|
||||
|
||||
|
||||
def parking(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""A clean stop undoes what a monocle did, and a crash with a monocle on leaves nothing stuck
|
||||
behind: the next start removes the stale parking desktop and brings the parked window back.
|
||||
|
||||
It opens two windows of its own."""
|
||||
kde = platform.kde
|
||||
two = _two_windows(platform)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"the window that is not in monocle is out of sight on a parking desktop",
|
||||
kde.wait_for(lambda: len(_parked(platform, two)) == 1),
|
||||
)
|
||||
_diagnose(platform, two, "monocle before the stop")
|
||||
kde.komorebic("stop")
|
||||
checks.check("the daemon exited", kde.wait_for(lambda: not kde.komorebi_running()))
|
||||
checks.check(
|
||||
"the parking desktop is gone", kde.wait_for(lambda: PARK not in kde.desktop_names())
|
||||
)
|
||||
checks.check(
|
||||
"and every window is on a workspace's desktop",
|
||||
kde.wait_for(lambda: _on_a_workspace_desktop(platform, two)),
|
||||
)
|
||||
|
||||
platform.start_komorebi()
|
||||
checks.check("the daemon answers", kde.wait_for(lambda: _answering(platform), timeout=30))
|
||||
checks.check("it manages the two windows again", kde.wait_for(lambda: _managed(platform, two)))
|
||||
_focus(platform, two[1], two[0])
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"a window is parked and a parking desktop exists",
|
||||
kde.wait_for(lambda: len(_parked(platform, two)) == 1),
|
||||
)
|
||||
_diagnose(platform, two, "monocle after the restart")
|
||||
kde.kill_komorebi()
|
||||
checks.check(
|
||||
"the daemon is dead and the parking desktop is still there, with a window on it",
|
||||
PARK in kde.desktop_names() and len(_parked(platform, two)) == 1,
|
||||
)
|
||||
platform.start_komorebi()
|
||||
checks.check(
|
||||
"the next start removed the stale parking desktop",
|
||||
kde.wait_for(lambda: _answering(platform) and PARK not in kde.desktop_names()),
|
||||
)
|
||||
checks.check(
|
||||
"and brought the parked window back",
|
||||
kde.wait_for(lambda: _on_a_workspace_desktop(platform, two)),
|
||||
)
|
||||
checks.check("it manages the two windows again", kde.wait_for(lambda: _managed(platform, two)))
|
||||
_focus(platform, two[1], two[0])
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"after a crash and a restart a monocle still hides the other window",
|
||||
kde.wait_for(lambda: len(_parked(platform, two)) == 1),
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"and turned off, nothing is out of sight",
|
||||
kde.wait_for(lambda: _parked(platform, two) == []),
|
||||
)
|
||||
for client in two:
|
||||
platform.close(client)
|
||||
|
||||
|
||||
def kwin_restart(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""KWin restarts under the daemon: it loads its script into the new KWin, lets go of the
|
||||
windows of the old one, and tiles what opens there. The suite ends with a window of the new
|
||||
KWin, `afterwards`."""
|
||||
kde = platform.kde
|
||||
loaded = kde.komorebi_log().count("loaded the KWin bridge script")
|
||||
kde.restart_kwin()
|
||||
checks.check(
|
||||
"the daemon loaded its script into the new KWin",
|
||||
kde.wait_for(
|
||||
lambda: kde.komorebi_log().count("loaded the KWin bridge script") == loaded + 1,
|
||||
timeout=30,
|
||||
),
|
||||
)
|
||||
checks.check(
|
||||
"the daemon let go of the windows of the old KWin",
|
||||
kde.wait_for(lambda: kde.managed_all() == 0),
|
||||
)
|
||||
platform.spawn("afterwards")
|
||||
checks.check(
|
||||
"a window opened in the new KWin is managed",
|
||||
kde.wait_for(lambda: kde.managed_all() == 1),
|
||||
)
|
||||
width = platform.size[0]
|
||||
checks.check(
|
||||
"... and tiled on its own",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
_where_asked(platform, "afterwards")
|
||||
and kde.rect(kde.wid("afterwards")).w > width - 100
|
||||
),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def stopped(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
|
||||
"""`komorebic stop` ends the daemon, removes its socket and its script, and leaves the window
|
||||
`afterwards` open."""
|
||||
kde = platform.kde
|
||||
kde.komorebic("stop")
|
||||
checks.check("the daemon exited", kde.wait_for(lambda: not kde.komorebi_running()))
|
||||
checks.check(
|
||||
"its socket is gone",
|
||||
kde.run(f"test -e {kde.runtime}/komorebi/komorebi.sock")[0] != 0,
|
||||
)
|
||||
checks.check("the script is no longer in KWin", kde.wait_for(lambda: not kde.script_loaded()))
|
||||
checks.check("the window stays", kde.wid("afterwards") != "")
|
||||
@@ -10,10 +10,9 @@
|
||||
# (`komorebi/tests/monocle.rs`), and that `komorebic stop` gives KWin back what the daemon set up in
|
||||
# it. A window manager that agrees with itself proves nothing, so what the daemon believes is read
|
||||
# from its debug log and from `komorebic state`, and what KWin has through kdotool.
|
||||
import json
|
||||
from typing import cast
|
||||
|
||||
from komorebi_vm import Checks, Kde, Rect, daemon
|
||||
from komorebi_vm.recorder import Recorder
|
||||
from komorebi_vm import Checks, Kde
|
||||
from komorebi_vm.core.platform import Client
|
||||
from komorebi_vm.core.scenarios import (
|
||||
closing,
|
||||
@@ -45,12 +44,12 @@ from komorebi_vm.core.scenarios import (
|
||||
workspace_moves,
|
||||
workspaces,
|
||||
)
|
||||
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 core_e2e as kde_core
|
||||
from komorebi_vm.recorder import Recorder
|
||||
|
||||
W, H = 1920, 1080
|
||||
PARK = "komorebi-park"
|
||||
# foot sizes itself to whole cells of its font, so its frame can be short of the one asked for
|
||||
CELL = 24
|
||||
|
||||
start_all()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
@@ -58,492 +57,129 @@ machine.wait_for_unit("user@1000.service")
|
||||
|
||||
checks = Checks()
|
||||
kde = Kde.headless(machine, "main", size=(W, H), scale=SCALE)
|
||||
platform = KdePlatform(kde, (W, H))
|
||||
|
||||
|
||||
def daemon_log() -> str:
|
||||
return kde.komorebi_log()
|
||||
|
||||
|
||||
def inside(r: Rect) -> bool:
|
||||
return r.x >= 0 and r.y >= 0 and r.x + r.w <= W and r.y + r.h <= H
|
||||
|
||||
|
||||
def asked(title: str) -> Rect | None:
|
||||
return daemon.asked(daemon_log(), title)
|
||||
|
||||
|
||||
def where_asked(title: str) -> bool:
|
||||
"""KWin has the window where the daemon asked: the same place, and the size up to a cell."""
|
||||
want, wid = asked(title), kde.wid(title)
|
||||
if want is None or wid == "":
|
||||
return False
|
||||
have = kde.rect(wid)
|
||||
return (
|
||||
(have.x, have.y) == (want.x, want.y)
|
||||
and 0 <= want.w - have.w < CELL
|
||||
and 0 <= want.h - have.h < CELL
|
||||
)
|
||||
|
||||
|
||||
def focus_agrees() -> bool:
|
||||
"""The window KWin has focused is the one the daemon last handled a focus change for."""
|
||||
log = daemon_log()
|
||||
focus_changes = [e.window for e in daemon.events(log) if e.kind == "FocusChange"]
|
||||
active = kde.active()
|
||||
if not focus_changes or active == "":
|
||||
return False
|
||||
return daemon.window_ids(log).get(kde.title(active)) == focus_changes[-1]
|
||||
|
||||
|
||||
def answering() -> bool:
|
||||
"""`komorebic monitor-information` is answered, with the session's one output."""
|
||||
status, out = kde.run("komorebic monitor-information")
|
||||
return status == 0 and json.loads(out)[0]["size"]["right"] == W
|
||||
|
||||
|
||||
def parked() -> list[str]:
|
||||
"""The titles of the windows that are on the parking desktop, which is the last desktop."""
|
||||
names = kde.desktop_names()
|
||||
if PARK not in names:
|
||||
return []
|
||||
park = names.index(PARK) + 1
|
||||
return sorted(
|
||||
t for t in ["win1", "win2"] if kde.wid(t) != "" and kde.desk(kde.wid(t)) == park
|
||||
)
|
||||
|
||||
|
||||
def on_a_workspace_desktop() -> bool:
|
||||
"""Every window that is open is on a desktop that is a workspace, not on the parking one."""
|
||||
return all(
|
||||
kde.desk(kde.wid(t)) in (1, 2) for t in ["win1", "win2"] if kde.wid(t) != ""
|
||||
)
|
||||
|
||||
|
||||
def state_agrees() -> bool:
|
||||
"""The window komorebi's state has focused is the one KWin has."""
|
||||
active = kde.active()
|
||||
return active != "" and kde.title(active) == kde.focused_title()
|
||||
|
||||
|
||||
def at(title: str) -> tuple[int, int]:
|
||||
"""Where KWin has the window: foot rounds its size to its cells, but not its position."""
|
||||
r = kde.rect(kde.wid(title))
|
||||
return (r.x, r.y)
|
||||
|
||||
|
||||
def report(titles: list[str]) -> None:
|
||||
for title in titles:
|
||||
print(f" {title}: asked {asked(title)}, has {kde.rect(kde.wid(title))}")
|
||||
|
||||
|
||||
print("== 1. start")
|
||||
kde.start_komorebi()
|
||||
platform.start_komorebi()
|
||||
recorder = Recorder(kde, RECORDER)
|
||||
recorder.start("core-e2e")
|
||||
checks.check(
|
||||
"the daemon loaded its script into KWin",
|
||||
kde.wait_for(lambda: "loaded the KWin bridge script" in daemon_log(), timeout=30),
|
||||
)
|
||||
checks.check("KWin runs the script", kde.script_loaded())
|
||||
checks.check(
|
||||
"the daemon is up and answering komorebic", kde.wait_for(answering, timeout=30)
|
||||
)
|
||||
|
||||
print("== 2. three windows are tiled")
|
||||
titles = ["win1", "win2", "win3"]
|
||||
for title in titles:
|
||||
kde.spawn(f"foot -T {title} sleep 3000")
|
||||
kde.wait_for(lambda title=title: kde.wid(title) != "", timeout=30)
|
||||
kde.wait_for(
|
||||
lambda title=title: title in daemon.window_ids(daemon_log()), timeout=10
|
||||
)
|
||||
settled = kde.wait_for(lambda: all(where_asked(t) for t in titles), timeout=20)
|
||||
report(titles)
|
||||
checks.check("every window is where the daemon asked for it", settled)
|
||||
rects = [kde.rect(kde.wid(t)) for t in titles]
|
||||
for title, rect in zip(titles, rects, strict=True):
|
||||
checks.check(f"{title} is inside the screen", inside(rect))
|
||||
checks.check("win1 and win2 do not overlap", not rects[0].overlaps(rects[1]))
|
||||
checks.check("win1 and win3 do not overlap", not rects[0].overlaps(rects[2]))
|
||||
checks.check("win2 and win3 do not overlap", not rects[1].overlaps(rects[2]))
|
||||
checks.check(
|
||||
"the windows share the screen: none is full width", all(r.w < W - 20 for r in rects)
|
||||
# The shared scenarios (komorebi_vm.core.scenarios) are what runs on Windows too: they ask the
|
||||
# operating system where the windows are, and not the daemon's log. After the ones that move
|
||||
# windows or the focus, an extra reads the daemon's side of the bridge.
|
||||
NEUTRAL = ("neutral1", "neutral2", "neutral3")
|
||||
opened = run_suite(
|
||||
checks,
|
||||
platform_only("kde", kde_core.start, platform, checks, []),
|
||||
shared(tiling.run, platform, checks, NEUTRAL),
|
||||
)
|
||||
checks.check(
|
||||
"KWin and the daemon agree on the focused window", kde.wait_for(focus_agrees)
|
||||
)
|
||||
checks.check(
|
||||
"komorebi manages the three windows", kde.wait_for(lambda: kde.managed() == 3)
|
||||
)
|
||||
checks.check(
|
||||
"komorebi's state focuses the window KWin does", kde.wait_for(state_agrees)
|
||||
)
|
||||
|
||||
print("== 3. the focus moves by hand")
|
||||
kde.activate(kde.wid("win1"))
|
||||
checks.check(
|
||||
"KWin focused win1", kde.wait_for(lambda: kde.title(kde.active()) == "win1")
|
||||
)
|
||||
checks.check("... and the daemon followed", kde.wait_for(focus_agrees))
|
||||
checks.check("... and its state says so", kde.wait_for(state_agrees))
|
||||
|
||||
print("== 4. the focus moves on komorebic's commands")
|
||||
kde.komorebic("focus", "right")
|
||||
checks.check(
|
||||
"after 'focus right' KWin has given the focus to another window",
|
||||
kde.wait_for(lambda: kde.title(kde.active()) not in ("", "win1")),
|
||||
)
|
||||
checks.check(
|
||||
"... and komorebi's state focuses the same one", kde.wait_for(state_agrees)
|
||||
)
|
||||
kde.komorebic("focus", "left")
|
||||
checks.check(
|
||||
"'focus left' gives it back to win1",
|
||||
kde.wait_for(lambda: kde.title(kde.active()) == "win1"),
|
||||
)
|
||||
checks.check("... and komorebi's state says so", kde.wait_for(state_agrees))
|
||||
kde.komorebic("cycle-focus", "next")
|
||||
checks.check(
|
||||
"'cycle-focus next' focuses win2, the next container in komorebi's order",
|
||||
kde.wait_for(lambda: kde.title(kde.active()) == "win2"),
|
||||
)
|
||||
checks.check("... and komorebi's state says so", kde.wait_for(state_agrees))
|
||||
kde.komorebic("cycle-focus", "previous")
|
||||
checks.check(
|
||||
"'cycle-focus previous' goes back to win1",
|
||||
kde.wait_for(lambda: kde.title(kde.active()) == "win1"),
|
||||
)
|
||||
checks.check("moving the focus moved no window", all(where_asked(t) for t in titles))
|
||||
|
||||
print("== 5. the windows move on komorebic's commands")
|
||||
left, top_right = at("win1"), at("win2")
|
||||
kde.komorebic("move", "right")
|
||||
checks.check(
|
||||
"after 'move right' win1 and win2 have swapped tiles",
|
||||
kde.wait_for(lambda: at("win1") == top_right and at("win2") == left, timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"... every window is where the daemon asked for it",
|
||||
kde.wait_for(lambda: all(where_asked(t) for t in titles), timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"... and win1 keeps the focus",
|
||||
kde.wait_for(lambda: kde.title(kde.active()) == "win1" and state_agrees()),
|
||||
)
|
||||
kde.komorebic("cycle-move", "previous")
|
||||
checks.check(
|
||||
"'cycle-move previous' puts win1 and win2 back",
|
||||
kde.wait_for(lambda: at("win1") == left and at("win2") == top_right, timeout=20),
|
||||
)
|
||||
report(titles)
|
||||
|
||||
print("== 6. monocle")
|
||||
focused = kde.active()
|
||||
tile = kde.rect(focused)
|
||||
kde.komorebic("toggle-monocle")
|
||||
neutral = cast(list[Client], opened[1])
|
||||
args = (platform, checks, neutral)
|
||||
|
||||
|
||||
def fills_the_work_area(wid: str) -> bool:
|
||||
r = kde.rect(wid)
|
||||
return r.w > W - 120 and r.h > H - 120
|
||||
def after_each_shared(*steps): # noqa: ANN002, ANN202
|
||||
"""The steps, with a check after each shared one that KWin carried out what the daemon sent, so
|
||||
that a scenario that makes the bridge fail is named."""
|
||||
out = []
|
||||
for step in steps:
|
||||
out.append(step)
|
||||
if step.scope == "shared":
|
||||
out.append(platform_only("kde", kde_core.bridge_did_everything, *args))
|
||||
return out
|
||||
|
||||
|
||||
checks.check(
|
||||
"in monocle the focused window fills the work area",
|
||||
kde.wait_for(lambda: fills_the_work_area(focused), timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"komorebi's state has it as the monocle container",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
kde.state()["monitors"]["elements"][0]["workspaces"]["elements"][0][
|
||||
"monocle_container"
|
||||
]
|
||||
is not None
|
||||
)
|
||||
),
|
||||
)
|
||||
checks.check(
|
||||
"... and it still has the focus", kde.title(kde.active()) == kde.title(focused)
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"toggling back puts it on its tile",
|
||||
kde.wait_for(lambda: kde.rect(focused) == tile, timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"... and every window is where the daemon asked for it",
|
||||
kde.wait_for(lambda: all(where_asked(t) for t in titles), timeout=20),
|
||||
)
|
||||
|
||||
kde.komorebic("monocle-focus-behaviour", "cycle")
|
||||
kde.komorebic("toggle-monocle")
|
||||
kde.wait_for(lambda: fills_the_work_area(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_the_work_area(kde.active()),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
kde.komorebic("monocle-focus-behaviour", "no-op")
|
||||
checks.check(
|
||||
"the three windows are tiled again",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
all(where_asked(t) for t in titles)
|
||||
and all(kde.rect(kde.wid(t)).w < W - 20 for t in titles)
|
||||
run_suite(
|
||||
checks,
|
||||
*after_each_shared(
|
||||
platform_only("kde", kde_core.windows_where_asked, *args),
|
||||
platform_only("kde", kde_core.focus_agrees_with_the_log, *args),
|
||||
shared(focus.run, *args),
|
||||
platform_only("kde", kde_core.windows_where_asked, *args),
|
||||
shared(moving.run, *args),
|
||||
platform_only("kde", kde_core.windows_where_asked, *args),
|
||||
shared(stacks.run, *args),
|
||||
platform_only("kde", kde_core.fixtures, *args),
|
||||
shared(layouts.run, *args),
|
||||
shared(floating.run, *args),
|
||||
shared(minimizing.run, *args),
|
||||
platform_only("kde", kde_core.windows_where_asked, *args),
|
||||
shared(maximizing.run, *args),
|
||||
shared(resize_commands.run, *args),
|
||||
shared(promoting.run, *args),
|
||||
shared(flipping.run, *args),
|
||||
shared(pausing.run, *args),
|
||||
shared(tiling_off.run, *args),
|
||||
shared(scrolling.run, *args),
|
||||
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(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
|
||||
shared(closing.run, *args, Client("neutral1")),
|
||||
platform_only(
|
||||
"kde", kde_core.windows_where_asked, platform, checks, neutral[1:]
|
||||
),
|
||||
timeout=20,
|
||||
# the rules start from a workspace with no window: close what is left, wherever it is
|
||||
platform_only("kde", kde_core.no_window_is_left, platform, checks, neutral[1:]),
|
||||
),
|
||||
)
|
||||
|
||||
print("== 7. minimize and restore")
|
||||
kde.minimize(kde.wid("win2"))
|
||||
two = ["win1", "win3"]
|
||||
checks.check(
|
||||
"the other two windows take the screen",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
all(where_asked(t) for t in two)
|
||||
and all(kde.rect(kde.wid(t)).w > W // 2 - 40 for t in two)
|
||||
),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
report(two)
|
||||
kde.activate(kde.wid("win2"))
|
||||
checks.check(
|
||||
"restored, the three windows are tiled again",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
all(where_asked(t) for t in titles)
|
||||
and all(kde.rect(kde.wid(t)).w < W - 20 for t in titles)
|
||||
),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
report(titles)
|
||||
|
||||
print("== 8. close")
|
||||
kde.close(kde.wid("win3"))
|
||||
checks.check(
|
||||
"KWin closed win3", kde.wait_for(lambda: kde.wid("win3") == "", timeout=10)
|
||||
)
|
||||
checks.check(
|
||||
"the two that are left share the screen again",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
all(where_asked(t) for t in ["win1", "win2"])
|
||||
and not kde.rect(kde.wid("win1")).overlaps(kde.rect(kde.wid("win2")))
|
||||
),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
report(["win1", "win2"])
|
||||
checks.check(
|
||||
"komorebi manages the two that are left", kde.wait_for(lambda: kde.managed() == 2)
|
||||
)
|
||||
checks.check(
|
||||
"KWin carried out every command", "the bridge could not do" not in daemon_log()
|
||||
)
|
||||
|
||||
print("== 9. a clean stop undoes what a monocle did")
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"the window that is not in monocle is out of sight on a parking desktop",
|
||||
kde.wait_for(lambda: len(parked()) == 1),
|
||||
)
|
||||
kde.komorebic("stop")
|
||||
exited = kde.wait_for(lambda: not kde.komorebi_running())
|
||||
if not exited:
|
||||
print(kde.systemctl("status", "komorebi@main.service", "--no-pager", "-l"))
|
||||
print("\n".join(daemon_log().splitlines()[-15:]))
|
||||
checks.check("the daemon exited", exited)
|
||||
checks.check(
|
||||
"the parking desktop is gone", kde.wait_for(lambda: PARK not in kde.desktop_names())
|
||||
)
|
||||
checks.check(
|
||||
"and every window is on a workspace's desktop", kde.wait_for(on_a_workspace_desktop)
|
||||
)
|
||||
|
||||
print("== 10. a crash with a monocle on leaves nothing stuck behind")
|
||||
kde.start_komorebi()
|
||||
checks.check("the daemon answers", kde.wait_for(answering, timeout=30))
|
||||
checks.check(
|
||||
"it manages the two windows again", kde.wait_for(lambda: kde.managed() == 2)
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"a window is parked and a parking desktop exists",
|
||||
kde.wait_for(lambda: len(parked()) == 1),
|
||||
)
|
||||
kde.kill_komorebi()
|
||||
checks.check(
|
||||
"the daemon is dead and the parking desktop is still there, with a window on it",
|
||||
PARK in kde.desktop_names() and len(parked()) == 1,
|
||||
)
|
||||
kde.start_komorebi()
|
||||
checks.check(
|
||||
"the next start removed the stale parking desktop",
|
||||
kde.wait_for(lambda: answering() and PARK not in kde.desktop_names()),
|
||||
)
|
||||
checks.check("and brought the parked window back", kde.wait_for(on_a_workspace_desktop))
|
||||
checks.check(
|
||||
"it manages the two windows again", kde.wait_for(lambda: kde.managed() == 2)
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"after a crash and a restart a monocle still hides the other window",
|
||||
kde.wait_for(lambda: len(parked()) == 1),
|
||||
)
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"and turned off, nothing is out of sight", kde.wait_for(lambda: parked() == [])
|
||||
)
|
||||
|
||||
print("== 11. KWin restarts under the daemon")
|
||||
kde.restart_kwin()
|
||||
checks.check(
|
||||
"the daemon loaded its script into the new KWin",
|
||||
kde.wait_for(
|
||||
lambda: daemon_log().count("loaded the KWin bridge script") == 2, timeout=30
|
||||
),
|
||||
)
|
||||
checks.check(
|
||||
"komorebi let go of the windows of the old KWin",
|
||||
kde.wait_for(lambda: kde.managed() == 0),
|
||||
)
|
||||
kde.spawn("foot -T afterwards sleep 3000")
|
||||
kde.wait_for(lambda: kde.wid("afterwards") != "", timeout=30)
|
||||
checks.check(
|
||||
"a window opened in the new KWin is managed",
|
||||
kde.wait_for(lambda: kde.managed() == 1),
|
||||
)
|
||||
checks.check(
|
||||
"... and tiled on its own",
|
||||
kde.wait_for(
|
||||
lambda: (
|
||||
where_asked("afterwards") and kde.rect(kde.wid("afterwards")).w > W - 100
|
||||
),
|
||||
timeout=20,
|
||||
),
|
||||
)
|
||||
report(["afterwards"])
|
||||
|
||||
print(
|
||||
"== 12. tiling, focus, moving, stacks, monocle, workspaces and closing, through the neutral platform"
|
||||
)
|
||||
# the scenarios of komorebi_vm.core.scenarios are what runs on Windows too: it asks the
|
||||
# operating system where the windows are, and not the daemon's log
|
||||
kde.close(kde.wid("afterwards"))
|
||||
checks.check(
|
||||
"the window of the last section is closed", kde.wait_for(lambda: kde.managed() == 0)
|
||||
)
|
||||
platform = KdePlatform(kde, (W, H))
|
||||
neutral = tiling.run(platform, checks, titles=("neutral1", "neutral2", "neutral3"))
|
||||
focus.run(platform, checks, neutral)
|
||||
moving.run(platform, checks, neutral)
|
||||
stacks.run(platform, checks, neutral)
|
||||
|
||||
# what `komorebic state` prints, kept as a file 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
|
||||
(machine.out_dir / "state-kfde-tiled.json").write_text(
|
||||
json.dumps(kde.state(), indent=2)
|
||||
)
|
||||
platform.activate(neutral[-1])
|
||||
kde.komorebic("stack", "left")
|
||||
checks.check(
|
||||
"the windows are stacked",
|
||||
kde.wait_for(lambda: sorted(map(len, kde.containers())) == [1, 2]),
|
||||
)
|
||||
(machine.out_dir / "state-kfde-stack.json").write_text(
|
||||
json.dumps(kde.state(), indent=2)
|
||||
)
|
||||
kde.komorebic("unstack")
|
||||
checks.check(
|
||||
"and unstacked",
|
||||
kde.wait_for(lambda: sorted(map(len, kde.containers())) == [1, 1, 1]),
|
||||
)
|
||||
layouts.run(platform, checks, neutral)
|
||||
floating.run(platform, checks, neutral)
|
||||
minimizing.run(platform, checks, neutral)
|
||||
maximizing.run(platform, checks, neutral)
|
||||
resize_commands.run(platform, checks, neutral)
|
||||
promoting.run(platform, checks, neutral)
|
||||
flipping.run(platform, checks, neutral)
|
||||
pausing.run(platform, checks, neutral)
|
||||
tiling_off.run(platform, checks, neutral)
|
||||
scrolling.run(platform, checks, neutral)
|
||||
padding.run(platform, checks, neutral)
|
||||
monocle.run(platform, checks, neutral)
|
||||
workspace_moves.run(platform, checks, neutral)
|
||||
workspaces.run(platform, checks, neutral)
|
||||
# the third window is on workspace 1 now: the first is closed, and the second takes its room
|
||||
closing.run(platform, checks, neutral, Client("neutral1"))
|
||||
|
||||
# the rules start from a workspace with no window: close what is left, wherever it is
|
||||
for title in ("neutral2", "neutral3"):
|
||||
platform.close(Client(title))
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
platform.komorebic("focus-workspace", "0")
|
||||
rules.run(platform, checks)
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
print("== 12. rules by class")
|
||||
rules_class.run(platform, checks)
|
||||
print("== 12. rules by exe")
|
||||
rules_exe.run(platform, checks)
|
||||
nothing = (platform, checks, [])
|
||||
run_suite(
|
||||
checks,
|
||||
shared(rules.run, platform, checks),
|
||||
platform_only("kde", kde_core.no_window_is_left, *nothing),
|
||||
shared(rules_class.run, platform, checks),
|
||||
shared(rules_exe.run, platform, checks),
|
||||
shared(placement.run, platform, checks),
|
||||
platform_only("kde", kde_core.no_window_is_left, *nothing),
|
||||
shared(startup_rules.run, platform, checks),
|
||||
platform_only("kde", kde_core.no_window_is_left, *nothing),
|
||||
shared(config_reload.run, platform, checks),
|
||||
platform_only(
|
||||
"kde", kde_core.no_window_is_left, platform, checks, [Client("reload-stays")]
|
||||
),
|
||||
)
|
||||
|
||||
print("== 12a. where a window that opens goes, from the placement rules of the config")
|
||||
placement.run(platform, checks)
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
|
||||
print("== 12a2. the workspace rules of the config, with a window open before the daemon")
|
||||
startup_rules.run(platform, checks)
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
|
||||
print("== 12a3. the file is reloaded when it changes")
|
||||
config_reload.run(platform, checks)
|
||||
platform.close(Client("reload-stays"))
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
# a window for the stop to leave behind
|
||||
platform.spawn("afterwards")
|
||||
checks.check("it is managed", kde.wait_for(lambda: kde.managed_all() == 1, timeout=20))
|
||||
|
||||
print("== 12b. a daemon that stops and starts again takes the windows up")
|
||||
lifecycle.run(platform, checks, [Client("afterwards"), platform.spawn("beside")])
|
||||
checks.check("the daemon answers", kde.wait_for(answering, timeout=30))
|
||||
print("== 12b2. the same, with a window put away on another workspace")
|
||||
lifecycle_hidden.run(platform, checks, [Client("afterwards"), Client("beside")])
|
||||
checks.check("the daemon answers", kde.wait_for(answering, timeout=30))
|
||||
besides = [Client("afterwards"), platform.spawn("beside")]
|
||||
run_suite(
|
||||
checks,
|
||||
shared(lifecycle.run, platform, checks, besides),
|
||||
platform_only("kde", kde_core.start, platform, checks, []),
|
||||
shared(
|
||||
lifecycle_hidden.run, platform, checks, [Client("afterwards"), Client("beside")]
|
||||
),
|
||||
platform_only("kde", kde_core.start, platform, checks, []),
|
||||
)
|
||||
platform.close(Client("after-the-restart"))
|
||||
platform.close(Client("beside"))
|
||||
checks.check("one window is left", kde.wait_for(lambda: kde.managed_all() == 1, timeout=20))
|
||||
checks.check(
|
||||
"one window is left", kde.wait_for(lambda: kde.managed_all() == 1, timeout=20)
|
||||
)
|
||||
|
||||
print("== 12c. a window sent to a monitor that does not exist")
|
||||
# KNOWN FAILURE, to follow up on: move_container_to_monitor takes the container out before it
|
||||
# looks the monitor up. See docs/dev/BEHAVIOUR.md. The window is lost, so this stays last.
|
||||
commands.unknown_monitor(
|
||||
platform,
|
||||
# looks the monitor up. See docs/dev/BEHAVIOUR.md. The window is lost, so this stays last of the
|
||||
# shared scenarios.
|
||||
run_suite(
|
||||
checks,
|
||||
[Client("afterwards")],
|
||||
known_failure="the container is removed before the monitor is looked up, on both ports",
|
||||
shared(
|
||||
commands.unknown_monitor,
|
||||
platform,
|
||||
checks,
|
||||
[Client("afterwards")],
|
||||
"the container is removed before the monitor is looked up, on both ports",
|
||||
),
|
||||
# what only KDE can tell about the daemon stopping, crashing, and KWin restarting
|
||||
platform_only("kde", kde_core.parking, platform, checks, []),
|
||||
platform_only("kde", kde_core.kwin_restart, platform, checks, []),
|
||||
platform_only("kde", kde_core.stopped, platform, checks, []),
|
||||
)
|
||||
|
||||
print("== 13. komorebic stop")
|
||||
kde.komorebic("stop")
|
||||
checks.check("the daemon exited", kde.wait_for(lambda: not kde.komorebi_running()))
|
||||
checks.check(
|
||||
"its socket is gone",
|
||||
kde.run(f"test -e {kde.runtime}/komorebi/komorebi.sock")[0] != 0,
|
||||
)
|
||||
checks.check(
|
||||
"the script is no longer in KWin", kde.wait_for(lambda: not kde.script_loaded())
|
||||
)
|
||||
checks.check("the window stays", kde.wid("afterwards") != "")
|
||||
|
||||
recorder.stop()
|
||||
kde.stop()
|
||||
checks.finish()
|
||||
Reference in new issue
Block a user