Files
komorebi/nix/tests/vm/lib/komorebi_vm/daemon.py
T
LGUG2Z d6ad3b4292 feat(wm): a window the user maximizes
KWin maximizes a window for the user as well as for komorebi: the title bar, a
double click and a shortcut do it, and nobody asks the window manager. A window
that stayed a tile would be asked to move at the next retile, so komorebi has to
know.

The bridge reports KWin's maximizedChanged as a maximized event, true only when
the window is maximized both ways. The table turns it into a MaximizeChange, and
adopt_maximize_change takes the window out of the layout as toggle-maximize
does, or, when the user restores it, puts it back in a container of its own at
the index it came from. A window that is already maximized when komorebi starts,
or that opens maximized, is the workspace's maximized window from the start.
komorebi's own maximize is reported too and finds the workspace as it left it,
so it changes nothing.

While a window is maximized, what is asked of the layout does nothing, by the
same rule as for toggle-maximize.

A maximized window of a monitor that is unplugged goes to the monitor that is
left and stays maximized: evacuate_monitor makes it the maximized window of the
workspace it goes to, and the maximized window that workspace had goes back to
its tile. Until now it came back as a tile.

vm-user-maximize maximizes windows with kdotool in a headless KWin, and checks
the daemon's state, the frames, that the layout commands do nothing, and that
toggle-maximize and the user's restore both put the window back in its tile.
2026-10-28 07:20:57 -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`, `MaximizeChange`)."""
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