mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-21 08:01:39 +01:00
When an output gets another resolution or scale, or a panel starts, grows or hides, the work area the layout fills is not the one komorebi tiled in, and nothing moved the windows until something else tiled them again. The bridge now sends the outputs, with their geometry and the work area of the desktop each shows, when KWin says they changed, when a dock window opens, closes or moves, and once a second, because KWin has no signal for the room a panel leaves. The table turns a monitor whose size or work area changed into a monitor notification. It is not a window event, since it is about no window: it goes to the monitor reconciliator, a thread that takes the window manager's lock as the threads of events and messages do, reads the size and work area of every monitor again and tiles the workspace in front of the focused monitor. Another monitor's windows keep their tiles until a retile. Every subscriber is notified of it, whether or not the state changed. vm-hotplug starts with the scale of one of two outputs changing under a running daemon. The VM library gets kde.outputs, which lists, disables, enables and scales outputs, for the commits that unplug and plug them.
99 lines
3.4 KiB
Python
99 lines
3.4 KiB
Python
# Monitors that change, against a real headless KWin with two outputs. What only a real KWin can
|
|
# tell: that `kscreen-doctor` changing the scale of an output reaches komorebi as a change of that
|
|
# monitor's size, that the windows on it are tiled again in the size it has now, and that they
|
|
# fill it again when it has its size back. `komorebi/tests/monitor_resize.rs` checks the same
|
|
# against the fake.
|
|
from komorebi_vm import Checks, Kde, Rect
|
|
|
|
W, H = 1920, 1080
|
|
|
|
start_all()
|
|
machine.wait_for_unit("multi-user.target")
|
|
machine.wait_for_unit("user@1000.service")
|
|
|
|
checks = Checks()
|
|
kde = Kde.headless(machine, "main", size=(W, H), outputs=2, scale=SCALE)
|
|
|
|
TITLES = ["w1", "w2", "w3"]
|
|
|
|
|
|
def monitor(idx: int) -> Rect:
|
|
"""The bounds komorebi has for a monitor."""
|
|
size = kde.state()["monitors"]["elements"][idx]["size"]
|
|
return Rect(size["left"], size["top"], size["right"], size["bottom"])
|
|
|
|
|
|
def tiled_in(area: Rect) -> bool:
|
|
"""Every one of the three windows is inside `area`, and none is on another.
|
|
|
|
A pixel is allowed at each edge: at a fractional scale KWin reports frames that are not
|
|
whole pixels.
|
|
"""
|
|
rects = [kde.rect(kde.wid(title)) for title in TITLES]
|
|
return all(r.inside(area, slack=1) for r in rects) and not any(
|
|
a.overlaps(b) for i, a in enumerate(rects) for b in rects[i + 1 :]
|
|
)
|
|
|
|
|
|
def resizes_handled() -> int:
|
|
"""How many times the daemon has read the sizes of its monitors again."""
|
|
return kde.komorebi_log().count("updated monitor size and work area")
|
|
|
|
|
|
print("== 1. two outputs, and three windows on the left one")
|
|
left, right = kde.outputs.names()
|
|
print(f" outputs: {left} (left), {right} (right)")
|
|
kde.start_komorebi()
|
|
checks.check(
|
|
"the daemon answers komorebic, with both monitors",
|
|
kde.wait_for(
|
|
lambda: kde.run("komorebic state")[0] == 0
|
|
and len(kde.state()["monitors"]["elements"]) == 2,
|
|
timeout=30,
|
|
),
|
|
)
|
|
for title in TITLES:
|
|
kde.spawn(f"foot -T {title} sleep 3000")
|
|
kde.wait_for(lambda title=title: kde.wid(title) != "", timeout=30)
|
|
checks.check(
|
|
"komorebi has the three windows on the left monitor",
|
|
kde.wait_for(lambda: kde.managed(0) == 3),
|
|
)
|
|
checks.check("the left monitor has the size of its output", monitor(0) == Rect(0, 0, W, H))
|
|
checks.check("the windows are tiled inside it", kde.wait_for(lambda: tiled_in(monitor(0))))
|
|
|
|
print("== 2. the scale of the left output changes")
|
|
before = resizes_handled()
|
|
kde.outputs.scale(left, 1.5)
|
|
smaller = Rect(0, 0, W * 2 // 3, H * 2 // 3)
|
|
checks.check(
|
|
f"komorebi has the new size of the monitor, {smaller}",
|
|
kde.wait_for(lambda: monitor(0) == smaller, timeout=20),
|
|
)
|
|
checks.check("it read the sizes again for it", resizes_handled() > before)
|
|
checks.check(
|
|
"the windows are tiled again inside the monitor as it is now",
|
|
kde.wait_for(lambda: tiled_in(smaller)),
|
|
)
|
|
|
|
print("== 3. and back")
|
|
kde.outputs.scale(left, 1)
|
|
checks.check(
|
|
"the monitor has its size back",
|
|
kde.wait_for(lambda: monitor(0) == Rect(0, 0, W, H), timeout=20),
|
|
)
|
|
checks.check(
|
|
"the windows fill it again, side by side",
|
|
kde.wait_for(lambda: tiled_in(Rect(0, 0, W, H)) and kde.rect(kde.wid("w1")).w < W - 100),
|
|
)
|
|
|
|
print("== 4. nothing is left behind")
|
|
checks.check(
|
|
"komorebi is running and answers",
|
|
kde.komorebi_running() and kde.run("komorebic state")[0] == 0,
|
|
)
|
|
kde.stop_komorebi()
|
|
checks.check("komorebi stopped", not kde.komorebi_running())
|
|
|
|
checks.finish()
|