mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-23 00:44:15 +01:00
With the commands of the Backend trait carried out, the daemon tiles a real KWin. A command looks up the UUID KWin knows the window by, is queued as JSON for the bridge, and returns; the held Poll call is answered with the queue, one millisecond after the first command, so that a retile reaches KWin as one batch. The bridge sets the frame, activates, raises, minimizes, restores or closes the window, and reports what it could not do. set_rect records the frame it asked for in the table, so the window manager sees it at once, and the geometry event that follows says what the client made of it. A KWin script cannot move the pointer, so the pointer follows the focus through KWin's own "Move Mouse to Focus" action, invoked over kglobalaccel once KWin reports the window active. The commands are typed in bridge.js, and the declarations of KWin's API let the bridge set a window's frame, its minimized state and the active window, raise and close it, and nothing else. The session the tests of both sides share grows a second batch: the backend's tests check that set_rect, focus, raise, minimize, unminimize and close send it, and the bridge's tests answer the bridge with it and check what KWin is asked to do, down to the command for a window that has closed, which comes back as failed. The bridge's tests also cover findWindow's fallback to KWin's list, a frame set as a plain object, and a command KWin throws on. Three VM suites check it against a real KWin. vm-core-e2e (from the spike's m2-e2e, the sections that need no komorebic) compares what the daemon asked for, read from its debug log, with what KWin has, read with kdotool: three windows inside the screen, not overlapping, sharing it, the same focused window on both sides, and the same again after a minimize, a restore and a close. vm-client-geometry (slow) has eight real clients answer the frames komorebi asks for: Qt programs and xterm take them exactly, foot sizes itself to whole cells, GTK 4 programs and Firefox keep to their minimum sizes. vm-latency (slow) times retiles from a recording of the session bus: on HVF, from the daemon's answer to the last frame KWin reports, p50 17.3 ms, p95 27.7 ms. vm-kwin-events no longer checks that nothing moves. The VM library gives session commands the test user's home and data directories rather than root's, which a GTK client was refused. The bridge's second request for a position after a resize, which matters for windows off the screen, comes with the scrolling layout.
92 lines
2.9 KiB
Python
92 lines
2.9 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from komorebi_vm import latency
|
|
from komorebi_vm.latency import Message, Round
|
|
|
|
|
|
def call(time: float, body: dict[str, object]) -> str:
|
|
return (
|
|
f"method call time={time:.6f} sender=:1.5 -> destination=org.komorebi.Bridge serial=1"
|
|
" path=/org/komorebi/Bridge; interface=org.komorebi.Bridge; member=Event\n"
|
|
f' string "{json.dumps(body)}"\n'
|
|
)
|
|
|
|
|
|
def answer(time: float, cmds: list[dict[str, object]]) -> str:
|
|
batches = [{"batch": 1, "cmds": cmds}]
|
|
return (
|
|
f"method return time={time:.6f} sender=:1.3 -> destination=:1.5 serial=9 reply_serial=2\n"
|
|
f' string "{json.dumps(batches)}"\n'
|
|
)
|
|
|
|
|
|
def geo(uuid: str, x: int) -> dict[str, object]:
|
|
return {"op": "geo", "id": uuid, "x": x, "y": 0, "w": 100, "h": 100}
|
|
|
|
|
|
def frame(time: float, uuid: str) -> str:
|
|
return call(time, {"type": "geometry", "id": uuid, "geo": {"x": 0, "y": 0, "w": 9, "h": 9}})
|
|
|
|
|
|
def test_messages_are_parsed_with_their_time_member_and_string() -> None:
|
|
text = call(1.5, {"type": "added"}) + (
|
|
"method return time=2.000000 sender=:1.1 -> destination=:1.2 serial=3 reply_serial=1\n"
|
|
" boolean true\n"
|
|
)
|
|
|
|
assert latency.messages(text) == [
|
|
Message("method call", 1.5, "Event", '{"type": "added"}'),
|
|
Message("method return", 2.0, "", ""),
|
|
]
|
|
|
|
|
|
def test_a_round_lasts_until_the_last_window_it_moved_reports_its_frame() -> None:
|
|
text = (
|
|
answer(10.0, [geo("a", 0), geo("b", 100)])
|
|
+ frame(10.004, "a")
|
|
+ frame(10.010, "b")
|
|
+ frame(10.016, "a")
|
|
)
|
|
|
|
(only,) = latency.rounds(text)
|
|
assert (only.sent, only.windows) == (10.0, 2)
|
|
assert only.seconds == pytest.approx(0.016)
|
|
|
|
|
|
def test_asking_again_for_the_same_frames_is_not_a_round() -> None:
|
|
text = (
|
|
answer(10.0, [geo("a", 0)])
|
|
+ frame(10.01, "a")
|
|
+ answer(11.0, [geo("a", 0), {"op": "activate", "id": "a"}])
|
|
+ answer(12.0, [geo("a", 50)])
|
|
+ frame(12.02, "a")
|
|
)
|
|
|
|
rounds = latency.rounds(text)
|
|
assert [r.sent for r in rounds] == [10.0, 12.0]
|
|
assert (rounds[1].sent, rounds[1].windows) == (12.0, 1)
|
|
assert rounds[1].seconds == pytest.approx(0.02)
|
|
|
|
|
|
def test_a_window_that_never_reports_leaves_its_round_unsettled() -> None:
|
|
text = answer(10.0, [geo("a", 0)]) + frame(13.0, "a")
|
|
|
|
assert latency.rounds(text) == [Round(10.0, 1, None)]
|
|
|
|
|
|
def test_a_round_ends_where_the_next_one_starts() -> None:
|
|
text = answer(10.0, [geo("a", 0)]) + answer(10.5, [geo("a", 9)]) + frame(10.6, "a")
|
|
|
|
assert [r.seconds for r in latency.rounds(text)] == [None, pytest.approx(0.1)]
|
|
|
|
|
|
def test_percentile_is_the_nearest_rank() -> None:
|
|
values = [float(n) for n in range(1, 21)]
|
|
|
|
assert latency.percentile(values, 0.5) == 10.0
|
|
assert latency.percentile(values, 0.95) == 19.0
|
|
assert latency.percentile(values, 1.0) == 20.0
|
|
assert latency.percentile([3.0], 0.5) == 3.0
|