mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
feat(nix): the rules_class scenario, and an app id for Platform.spawn
A workspace rule by class sends a window to its workspace, an ignore rule by class leaves one alone, and a window of another class stays where it opened. Platform.spawn takes an app_id, which is foot's -a on KDE and the window class on Windows. core-e2e passes 271 checks on KDE.
This commit is contained in:
1 parent
6a6d5ce49a
commit
733a5a4934
7 files changed
+97
-6
No files matched your search
@@ -114,8 +114,12 @@ class Platform(Protocol):
|
||||
"""The daemon's state."""
|
||||
...
|
||||
|
||||
def spawn(self, title: str) -> Client:
|
||||
"""Opens a window with this title and waits until the platform has it."""
|
||||
def spawn(self, title: str, app_id: str | None = None) -> Client:
|
||||
"""Opens a window with this title and waits until the platform has it.
|
||||
|
||||
`app_id` is the class of the window (its app id on Wayland, its window class on Windows)
|
||||
for a rule that matches by it; the platform's own when there is none.
|
||||
"""
|
||||
...
|
||||
|
||||
def os_window(self, client: Client) -> OsWindow | None:
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
"""Rules that match a window by its class (its app id on Wayland) decide where it goes, or that it
|
||||
is left alone."""
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.platform import Platform
|
||||
|
||||
|
||||
def run(platform: Platform, checks: Checks) -> None:
|
||||
"""Gives the daemon a workspace rule and an ignore rule by class, opens a window of each
|
||||
class and one of neither, and checks where each went.
|
||||
|
||||
The daemon must be running, on the first workspace, which is the one in view, with no window,
|
||||
and with workspaces 0 and 1. The rules are cleared afterwards.
|
||||
"""
|
||||
platform.komorebic("ensure-workspaces", "0", "2")
|
||||
platform.komorebic("workspace-rule", "class", "e2e-sent", "0", "1")
|
||||
platform.komorebic("ignore-rule", "class", "e2e-left")
|
||||
|
||||
sent = platform.spawn("by-class-sent", app_id="e2e-sent")
|
||||
checks.check(
|
||||
"a window a class rule matches goes to the workspace the rule names",
|
||||
platform.wait_for(lambda: platform.state().workspace_of(sent.title) == 1, timeout=20),
|
||||
)
|
||||
checks.check(
|
||||
"... where it is put away while another workspace is in view",
|
||||
platform.wait_for(lambda: platform.hidden(sent)),
|
||||
)
|
||||
|
||||
left = platform.spawn("by-class-left", app_id="e2e-left")
|
||||
checks.check(
|
||||
"a window an ignore rule by class matches is not managed",
|
||||
not platform.wait_for(
|
||||
lambda: platform.state().workspace_of(left.title) is not None, timeout=3
|
||||
),
|
||||
)
|
||||
|
||||
plain = platform.spawn("by-class-plain", app_id="e2e-other")
|
||||
checks.check(
|
||||
"a window of another class stays on the first workspace",
|
||||
platform.wait_for(lambda: platform.state().workspace_of(plain.title) == 0, timeout=20),
|
||||
)
|
||||
|
||||
platform.komorebic("clear-all-workspace-rules")
|
||||
for client in (sent, left, plain):
|
||||
platform.close(client)
|
||||
checks.check(
|
||||
"the three windows are closed",
|
||||
platform.wait_for(lambda: platform.state().managed() == 0, timeout=20),
|
||||
)
|
||||
@@ -74,8 +74,9 @@ class KdePlatform:
|
||||
def state(self) -> Snapshot:
|
||||
return snapshot.parse(self.kde.state())
|
||||
|
||||
def spawn(self, title: str) -> Client:
|
||||
self.kde.spawn(f"foot -T {shlex.quote(title)} sleep 3000")
|
||||
def spawn(self, title: str, app_id: str | None = None) -> Client:
|
||||
name = f"-a {shlex.quote(app_id)} " if app_id else ""
|
||||
self.kde.spawn(f"foot {name}-T {shlex.quote(title)} sleep 3000")
|
||||
self.kde.wait_for(lambda: self.kde.wid(title) != "", timeout=30)
|
||||
return Client(title)
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ class FakePlatform:
|
||||
self.display_of: dict[str, int] = {}
|
||||
self.forgets_displays = False
|
||||
self.floats: list[str] = []
|
||||
self.class_rules: dict[str, int] = {}
|
||||
self.ignored_classes: set[str] = set()
|
||||
self.tiling = True
|
||||
self.paused = False
|
||||
self.flipped = False
|
||||
@@ -144,7 +146,13 @@ class FakePlatform:
|
||||
"""The titles in view, in the order of the tiles."""
|
||||
return [stack[0] for stack in self.containers]
|
||||
|
||||
def spawn(self, title: str) -> Client:
|
||||
def spawn(self, title: str, app_id: str | None = None) -> Client:
|
||||
if app_id in self.ignored_classes:
|
||||
self.unmanaged.append(title)
|
||||
return Client(title)
|
||||
if app_id in self.class_rules:
|
||||
self.spaces[self.class_rules[app_id]].append([title])
|
||||
return Client(title)
|
||||
if self.paused:
|
||||
self.unmanaged.append(title)
|
||||
return Client(title)
|
||||
@@ -379,12 +387,17 @@ class FakePlatform:
|
||||
self.monocle = None if self.monocle else top
|
||||
case ("ensure-workspaces", _, _) | ("clear-all-workspace-rules",):
|
||||
if args[0] == "clear-all-workspace-rules":
|
||||
self.class_rules.clear()
|
||||
self.rules.clear()
|
||||
self.initial_rules.clear()
|
||||
case ("initial-workspace-rule", "title", title, _, number):
|
||||
self.initial_rules[title] = int(number)
|
||||
case ("workspace-rule", "title", title, _, number):
|
||||
self.rules[title] = int(number)
|
||||
case ("workspace-rule", "class", name, _, number):
|
||||
self.class_rules[name] = int(number)
|
||||
case ("ignore-rule", "class", name):
|
||||
self.ignored_classes.add(name)
|
||||
case ("ignore-rule", "title", title):
|
||||
self.ignored.add(title)
|
||||
case ("move-to-workspace", number):
|
||||
|
||||
@@ -25,6 +25,7 @@ from komorebi_vm.core.scenarios import (
|
||||
resize,
|
||||
resize_commands,
|
||||
rules,
|
||||
rules_class,
|
||||
scrolling,
|
||||
stacks,
|
||||
startup_rules,
|
||||
@@ -433,6 +434,25 @@ def test_a_daemon_that_loses_the_focused_window_off_screen_fails_scrolling() ->
|
||||
assert checks.failed > 0
|
||||
|
||||
|
||||
def test_a_daemon_that_is_right_passes_rules_class() -> None:
|
||||
platform = FakePlatform()
|
||||
checks = Checks()
|
||||
rules_class.run(platform, checks)
|
||||
assert checks.failed == 0, checks.failures
|
||||
assert checks.passed > 4
|
||||
|
||||
|
||||
def test_a_daemon_that_ignores_class_rules_fails_rules_class() -> None:
|
||||
class Deaf(FakePlatform):
|
||||
def komorebic(self, *args: str) -> str:
|
||||
return "" if "class" in args else super().komorebic(*args)
|
||||
|
||||
platform = Deaf()
|
||||
checks = Checks()
|
||||
rules_class.run(platform, checks)
|
||||
assert checks.failed > 0
|
||||
|
||||
|
||||
def test_a_command_the_port_lacks_is_skipped_by_name() -> None:
|
||||
platform = FakePlatform()
|
||||
checks = Checks()
|
||||
|
||||
@@ -21,7 +21,7 @@ class FakePlatform:
|
||||
def wait_for(self, predicate, timeout: float = 10) -> bool: # noqa: ANN001
|
||||
return predicate()
|
||||
|
||||
def spawn(self, title: str) -> Client:
|
||||
def spawn(self, title: str, app_id: str | None = None) -> Client:
|
||||
self.opened.append(title)
|
||||
return Client(title)
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ from komorebi_vm.core.scenarios import (
|
||||
promoting,
|
||||
resize_commands,
|
||||
rules,
|
||||
rules_class,
|
||||
scrolling,
|
||||
stacks,
|
||||
startup_rules,
|
||||
@@ -484,6 +485,9 @@ for title in ("neutral2", "neutral3"):
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
platform.komorebic("focus-workspace", "0")
|
||||
rules.run(platform, checks)
|
||||
checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20))
|
||||
print("== 12. rules by class")
|
||||
rules_class.run(platform, checks)
|
||||
|
||||
print("== 12a. where a window that opens goes, from the placement rules of the config")
|
||||
placement.run(platform, checks)
|
||||
|
||||
Reference in new issue
Block a user