From d5eff2c445552ca3eb8703d5c1dc66c12562a627 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 09:38:56 -0700 Subject: [PATCH] feat(nix): the KWin helpers several KDE extras use --- .../platforms/kde/extras/core_e2e.py | 20 ++------- .../lib/komorebi_vm/platforms/kde/support.py | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 nix/tests/vm/lib/komorebi_vm/platforms/kde/support.py diff --git a/nix/tests/vm/lib/komorebi_vm/platforms/kde/extras/core_e2e.py b/nix/tests/vm/lib/komorebi_vm/platforms/kde/extras/core_e2e.py index fe028db5..a697b665 100644 --- a/nix/tests/vm/lib/komorebi_vm/platforms/kde/extras/core_e2e.py +++ b/nix/tests/vm/lib/komorebi_vm/platforms/kde/extras/core_e2e.py @@ -12,29 +12,15 @@ import re from komorebi_vm import daemon from komorebi_vm.core.checks import Checks -from komorebi_vm.core.geometry import Rect from komorebi_vm.core.platform import Client -from komorebi_vm.kde_platform import CELL, PARK, KdePlatform +from komorebi_vm.kde_platform import PARK, KdePlatform +from komorebi_vm.platforms.kde.support import where_asked OUTPUT_WIDTH = 1920 -def _asked(platform: KdePlatform, title: str) -> Rect | None: - return daemon.asked(platform.kde.komorebi_log(), title) - - def _where_asked(platform: KdePlatform, title: str) -> bool: - """KWin has the window where the daemon asked: the same place, and the size up to a cell.""" - kde = platform.kde - want, wid = _asked(platform, title), kde.wid(title) - if want is None or wid == "": - return False - have = kde.rect(wid) - return ( - (have.x, have.y) == (want.x, want.y) - and 0 <= want.w - have.w < CELL - and 0 <= want.h - have.h < CELL - ) + return where_asked(platform, title) def _focus_agrees(platform: KdePlatform) -> bool: diff --git a/nix/tests/vm/lib/komorebi_vm/platforms/kde/support.py b/nix/tests/vm/lib/komorebi_vm/platforms/kde/support.py new file mode 100644 index 00000000..8d47030c --- /dev/null +++ b/nix/tests/vm/lib/komorebi_vm/platforms/kde/support.py @@ -0,0 +1,42 @@ +"""What several KDE suites and extras ask of KWin and the daemon's log, once. + +Each function takes a `KdePlatform`, so a suite or an extra that needs one of them imports it from +here and does not write it again. +""" + +from komorebi_vm import daemon +from komorebi_vm.core.geometry import Rect +from komorebi_vm.kde_platform import CELL, PARK, KdePlatform + + +def asked(platform: KdePlatform, title: str) -> Rect | None: + """The frame the daemon last asked KWin for, for the window with this title, from its log.""" + return daemon.asked(platform.kde.komorebi_log(), title) + + +def where_asked(platform: KdePlatform, title: str) -> bool: + """KWin has the window where the daemon asked: the same place, and the size up to a cell.""" + kde = platform.kde + want, wid = asked(platform, title), kde.wid(title) + if want is None or wid == "": + return False + have = kde.rect(wid) + return ( + (have.x, have.y) == (want.x, want.y) + and 0 <= want.w - have.w < CELL + and 0 <= want.h - have.h < CELL + ) + + +def park_desktop(platform: KdePlatform) -> int: + """The number of the parking desktop, counted from 1 as kdotool counts, or 0 for none.""" + names = platform.kde.desktop_names() + return names.index(PARK) + 1 if PARK in names else 0 + + +def parked(platform: KdePlatform, title: str) -> bool: + """Whether the window is on the parking desktop, out of sight.""" + kde = platform.kde + desk = park_desktop(platform) + wid = kde.wid(title) + return desk != 0 and wid != "" and kde.desk(wid) == desk