Files
komorebi/nix/tests/vm/lib/komorebi_vm/daemon.py
T
LGUG2Z a86e2bdc63 build(nix): a NixOS module for komorebi
On NixOS, running komorebi should take one flake input and one module line. The
flake exports `services.komorebi` as nixosModules.default (and .komorebi). It
adds the flake's overlay, which gains komorebi-full, installs komorebi and
komorebic, and runs the daemon in every Plasma session as a systemd user unit,
wanted by plasma-workspace.target and ordered after plasma-core.target, which
Plasma orders after KWin. systemd starts a daemon that fails again; the exit
status of a SIGTERM (130) counts as success, so a stopped unit is not failed.
The unit's PATH is the one a terminal in the session has, instead of the few
store paths NixOS gives a unit.

The options are enable, package, logLevel and a read-only execStart, the command
line the unit runs. There is no configFile: the daemon reads no configuration
file yet, and an option that linked one would do nothing.

nixos-module-eval evaluates seven scenarios as real NixOS systems and checks
their assertions, the unit and execStart, with builtins.tryEval for the two that
must not evaluate. Nothing in it builds a Linux package, so it runs on a Mac as
well.

The VM nodes import the module, so every suite runs komorebi as the module
installs it. The headless node's komorebi@NAME runs execStart, which has
--log-level, so the nodes set logLevel to debug and the suites stop passing it;
latency, which times the daemon, keeps the default level. The session node
starts the module's unit at login; render-smoke turns it off, since a tiled
terminal would cover the desktop it looks at. A new fast suite, vm-module, logs
in to Plasma and checks that the unit runs the daemon with the module's log
level and PATH, that a window opened in the session is tiled, that a killed
daemon is started again, and that a stop is not a failure.

docs/installation.md covers NixOS first, and building from source on other
distributions. There is no binary cache: the Komorebi license does not allow
third parties to redistribute binaries.
2026-10-28 07:20:37 -07:00

64 lines
2.3 KiB
Python

"""What the komorebi daemon logs about the events it handles.
A test reads the daemon's view of the desktop from its log
([`Kde.komorebi_log`](komorebi_vm.kde.Kde.komorebi_log)), at the debug level
the test nodes set (`services.komorebi.logLevel`): every event it handles is an
info line, every focus change KWin reports names the window by the daemon's id
and its title, and every frame the daemon asks KWin for is a debug line.
"""
import re
from dataclasses import dataclass
from komorebi_vm.kde import Rect
_EVENT = re.compile(r"processing event: (\w+) for window (\d+) with notification (\w+)")
_ACTIVATED = re.compile(r"KWin activated window (\d+) \((.*)\)$", re.MULTILINE)
_REQUEST = re.compile(
r"asking for window (\d+) to be at "
r"Rect \{ left: (-?\d+), top: (-?\d+), right: (-?\d+), bottom: (-?\d+) \}"
)
@dataclass(frozen=True)
class Event:
"""A window event the daemon handled."""
kind: str
"""The event (`Show`, `Destroy`, `FocusChange`, `Minimize`, `Restore`)."""
window: int
"""The daemon's id for the window."""
notification: str
"""The KWin signal it came from (`WindowAdded`, ...)."""
def events(log: str) -> list[Event]:
"""Returns the window events the daemon handled, in the order it handled them."""
return [Event(kind, int(window), signal) for kind, window, signal in _EVENT.findall(log)]
def window_ids(log: str) -> dict[str, int]:
"""Returns the daemon's id for each window KWin has given the focus, by title.
A title that two windows had is the later one's.
"""
return {title: int(window) for window, title in _ACTIVATED.findall(log)}
def requests(log: str) -> dict[int, Rect]:
"""Returns the frame the daemon last asked KWin for, for each window, by the daemon's id."""
return {
int(window): Rect(int(x), int(y), int(w), int(h))
for window, x, y, w, h in _REQUEST.findall(log)
}
def asked(log: str, title: str) -> Rect | None:
"""Returns the frame the daemon last asked KWin for, for the window with this title.
`None` if KWin never gave the window the focus (which is how its title reaches the log), or
the daemon never asked for a frame for it.
"""
window = window_ids(log).get(title)
return requests(log).get(window) if window is not None else None