feat(nix): placement by the class of a window is a shared case

The shared placement scenario opens a window with a class and a rule that
puts the windows of that class first. The KDE extra by_app_id is gone;
by_program (foot.exe) stays.
This commit is contained in:
LGUG2Z committed 2026-10-30 12:52:21 -07:00
1 parent fec9b1e3da
commit f2a5c234e1
6 files changed
+43 -51

No files matched your search

+1 -1
View File
@@ -138,7 +138,7 @@ daemon with none.
| 1, no rules: after the one in focus | shared `placement` |
| 2, every window to the primary tile | shared `placement` |
| 3, by the number of the place, as a number and as text | shared `placement` |
| 4, by the app id (`Class`), by the title, and after the one in focus | extra `by_app_id` (the shared scenario matches by title only; a candidate for it) |
| 4, by the app id (`Class`), by the title, and after the one in focus | shared `placement`, its case "by the class: first, and by the title: last" |
| 5, `Exe` `foot.exe` matches `foot` | extra `by_program` (KDE: no `.exe` on this port) |
## monitors and layout_flip
@@ -5,12 +5,13 @@ from typing import Any
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.platform import Client, Platform
CASES: list[tuple[str, Any, list[str], list[str]]] = [
# (what it says, the placement rules, the titles in the order they open, the order they end in)
("no rules: after the one in focus", None, ["a", "b", "c"], ["a", "b", "c"]),
("every window to the primary tile", "Primary", ["a", "b", "c"], ["c", "b", "a"]),
("by the number of the place, counted from 1", 2, ["a", "b", "c"], ["a", "c", "b"]),
("text that is a number is the same place", "2", ["a", "b", "c"], ["a", "c", "b"]),
CASES: list[tuple[str, Any, list[str], list[str], dict[str, str]]] = [
# (what it says, the placement rules, the titles in the order they open, the order they end in,
# the class of the windows that have one, by title)
("no rules: after the one in focus", None, ["a", "b", "c"], ["a", "b", "c"], {}),
("every window to the primary tile", "Primary", ["a", "b", "c"], ["c", "b", "a"], {}),
("by the number of the place, counted from 1", 2, ["a", "b", "c"], ["a", "c", "b"], {}),
("text that is a number is the same place", "2", ["a", "b", "c"], ["a", "c", "b"], {}),
(
"by the title: first, last, and after the one in focus",
{
@@ -19,6 +20,17 @@ CASES: list[tuple[str, Any, list[str], list[str]]] = [
},
["one", "two", "special", "a chat room", "four"],
["special", "one", "two", "a chat room", "four"],
{},
),
(
"by the class: first, and by the title: last",
{
"Primary": {"kind": "Class", "id": "special-class", "matching_strategy": "Equals"},
"Last": [{"kind": "Title", "id": "chat", "matching_strategy": "Contains"}],
},
["one", "two", "three", "a chat room", "four"],
["three", "one", "two", "a chat room", "four"],
{"three": "special-class"},
),
]
@@ -46,7 +58,8 @@ def _settled(platform: Platform, title: str, count: int) -> None:
def run(platform: Platform, checks: Checks, known_failures: dict[str, str] | None = None) -> None:
"""Starts the daemon with each case's rules, opens its windows one after the other, and checks
the order they are in.
the order they are in. A window that has a class in the case is opened with it, for a rule that
matches by its class.
`known_failures` maps the description of a case to why a port is known to fail it, whether
its daemon does not start with the rules or puts the windows in another order. The case is
@@ -57,7 +70,7 @@ def run(platform: Platform, checks: Checks, known_failures: dict[str, str] | Non
the one before is managed and has the focus, because "after the one in focus" depends on it.
"""
known = known_failures or {}
for description, rules, titles, want in CASES:
for description, rules, titles, want, classes in CASES:
reason = known.get(description)
try:
platform.restart_with(_config(rules))
@@ -68,7 +81,7 @@ def run(platform: Platform, checks: Checks, known_failures: dict[str, str] | Non
continue
clients: list[Client] = []
for title in titles:
clients.append(platform.spawn(title))
clients.append(platform.spawn(title, app_id=classes.get(title)))
_settled(platform, title, len(clients))
got = _order(platform)
message = f"{description}: {', '.join(want)} ({got})"
@@ -1,11 +1,10 @@
"""What only KDE can tell about the placement rules of the config, beside the shared `placement`.
The rules match a window by what it is called: its Wayland app id (`Class`) and its program
(`Exe`), as well as its title. The shared scenario checks the places, by number and by title; these
check that the names a rule matches are the ones a real KWin window has, and that `foot.exe` is
`foot`.
(`Exe`), as well as its title. The shared scenario checks the places, by number, by title and by
class; this checks that `foot.exe` is `foot`.
The suite runs the shared scenario, then `by_app_id` and `by_program`, with no window open.
The suite runs the shared scenario, then `by_program`, with no window open.
"""
from typing import Any
@@ -47,38 +46,6 @@ def _close(platform: KdePlatform, opened: list[Client]) -> None:
platform.wait_for(lambda: platform.state().managed() == 0, timeout=20)
def by_app_id(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
"""A window with the app id `special` goes first, one titled `chat` goes last, and one no rule
matches goes after the one in focus."""
platform.restart_with(
_config(
{
"Primary": {"kind": "Class", "id": "special", "matching_strategy": "Equals"},
"Last": [{"kind": "Title", "id": "chat", "matching_strategy": "Contains"}],
}
)
)
opened: list[Client] = []
for title in ("one", "two"):
_open(platform, opened, title, None)
_open(platform, opened, "three", "special")
checks.check(
f"the window with the app id special is first ({_order(platform)})",
_order(platform) == ["three", "one", "two"],
)
_open(platform, opened, "a chat room", None)
checks.check(
f"the chat room is last ({_order(platform)})",
_order(platform) == ["three", "one", "two", "a chat room"],
)
_open(platform, opened, "four", None)
checks.check(
f"a window no rule matches goes after the one in focus, the chat room ({_order(platform)})",
_order(platform) == ["three", "one", "two", "a chat room", "four"],
)
_close(platform, opened)
def by_program(platform: KdePlatform, checks: Checks, clients: list[Client]) -> None:
"""A rule for the program `foot.exe`, the name of a Windows executable, matches `foot`, which
is what opens every window here, so every window goes to the primary tile."""
+6 -1
View File
@@ -69,6 +69,7 @@ class FakePlatform:
manages: bool = True,
loads_resize: bool = True,
answers_queries: bool = True,
matches_class: bool = True,
) -> None:
self.panel = panel
"""The height of a panel along the bottom of the first display, which the work area leaves
@@ -77,6 +78,7 @@ class FakePlatform:
"""A daemon that tiles on the whole display, under the panel."""
self.second = second
"""The rectangle of the second display, when it is not one of the first's size."""
self.matches_class = matches_class
self.loads_resize = loads_resize
self.answers_queries = answers_queries
self.saved: dict[str, list[Rect]] = {}
@@ -295,8 +297,11 @@ class FakePlatform:
if isinstance(rules, dict):
for place, matches in rules.items():
for match in matches if isinstance(matches, list) else [matches]:
if match["kind"] == "Class" and not self.matches_class:
continue
equals = match["matching_strategy"] == "Equals"
if (title == match["id"]) if equals else (match["id"] in title):
value = self.classes.get(title, "") if match["kind"] == "Class" else title
if (value == match["id"]) if equals else (match["id"] in value):
index = _place_index(place, n)
elif rules is not None:
index = 0 if rules == "Primary" else int(rules) - 1
+9 -1
View File
@@ -3,7 +3,7 @@ are wrong in one way."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.geometry import Rect
from komorebi_vm.core.scenarios import commands, handover, queries, title_rule
from komorebi_vm.core.scenarios import commands, handover, placement, queries, title_rule
from tests.fake_platform import FakePlatform
@@ -118,3 +118,11 @@ def test_a_daemon_that_does_not_load_a_resize_fails_queries() -> None:
queries.run(platform, checks)
assert any("quick-save-resize: a resize is undone" in f for f in checks.failures)
assert any("save-resize: a resize is undone" in f for f in checks.failures)
def test_a_daemon_that_ignores_the_class_of_a_placement_rule_fails_placement() -> None:
platform = FakePlatform(matches_class=False)
checks = Checks()
placement.run(platform, checks)
assert [f for f in checks.failures if "by the class" in f], checks.failures
assert checks.failed == 1
+2 -3
View File
@@ -2,8 +2,8 @@
# opens goes. The daemon reads the rules from a `komorebi.json` it is started with. The shared
# scenario (`komorebi_vm.core.scenarios.placement`, which runs on Windows too) checks the places, by
# number and by title. What only a real KWin can tell is in
# `komorebi_vm.platforms.kde.extras.placement`: that the names the rules match are the ones a real
# window has (its Wayland app id, its program, and `foot.exe` being `foot`).
# `komorebi_vm.platforms.kde.extras.placement`: that the program a rule matches is the one a real
# window has (`foot.exe` being `foot`). The class (the Wayland app id) is a case of the shared one.
# `komorebi/tests/placement.rs` checks the same against the fake.
from komorebi_vm import Checks, Kde
from komorebi_vm.core.scenarios import placement
@@ -24,7 +24,6 @@ args = (platform, checks, [])
run_suite(
checks,
shared(placement.run, platform, checks),
platform_only("kde", kde_placement.by_app_id, *args),
platform_only("kde", kde_placement.by_program, *args),
)