mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
feat(nix): the platform says where a resize border is pressed
The press point of the resize scenarios was a gap outside the frame, which is KDE's resize zone. On Windows there is no invisible border on the top of a window, so a press there reached the desktop. Platform.resize_grab gives each port its own point; KDE keeps the gap outside the frame.
This commit is contained in:
1 parent
b80c18a9be
commit
b4edd1c023
7 files changed
+40
-8
No files matched your search
@@ -23,6 +23,7 @@ docstrings of `Platform` are the contract; this is the audit behind them.
|
||||
| `displays()` | each display's rectangle in the desktop's coordinates, left to right, as the system says | displays are not one size (on Windows the first is the basic adapter, 1280x800, and the second, the only one whose mode can change, is 1024x768 by default and follows `resize_display`) and a scenario does not compute where the next begins |
|
||||
| `add_display()`, `remove_display()` | plugs a display in to the right, unplugs the last; return when the system agrees | Windows removes only a display `add_display` plugged in (a hotplug port is used once); KDE enables a disabled output and disables the last enabled one, so a headless session with two outputs can unplug at once. A scenario unplugs only after plugging in, unless its suite started with more than one display |
|
||||
| `work_area()` | the area of the first display that windows may take, as the system says: the display less panels, docks and the taskbar | KDE asks KWin (a script: its placement area), and answers with the whole output only if KWin does not answer. A headless session has no panel, so there it is the output |
|
||||
| `resize_grab(frame, grab)` | where the pointer is pressed to take a window by an edge or corner | KDE: the gap outside the frame on every side (`resize.outside_grab`). Windows: left, right and bottom are the invisible border outside the visible frame; the top has none, so it is inside the frame's top row |
|
||||
| `close`, `minimize`, `activate`, `move_window` | act on the window as the user would; raise if there is no such window | `close` returns before the window is gone (a scenario waits for `os_window` to be `None`); `move_window` puts the top left of the *visible* frame at (x, y) |
|
||||
| `lock()`, `unlock()` | lock and unlock the screen and return when it is so | the lock screen is `LogonUI` on Windows and the Plasma greeter on KDE; a scenario asks only what the daemon and the windows do |
|
||||
| `pointer` | moves in the pixels of the first display; a drag is one press, a glide, one release | a window manager that follows the pointer by a hover delay (Windows) or by its own focus policy (KDE) has to be given time: `focus_follows_mouse.SETTLE` |
|
||||
|
||||
@@ -258,6 +258,17 @@ class Platform(Protocol):
|
||||
size."""
|
||||
...
|
||||
|
||||
def resize_grab(self, frame: Rect, grab: str) -> tuple[int, int]:
|
||||
"""Where the pointer is pressed to take a window of this frame by `grab`: `left`, `right`,
|
||||
`top`, `bottom`, or a corner (`topleft`, `topright`, `bottomleft`, `bottomright`).
|
||||
|
||||
It is the platform's knowledge, because where a window's resize zone is differs: on KDE it
|
||||
is the gap outside the frame on every side (`resize.outside_grab`), on Windows the left,
|
||||
right and bottom zones are an invisible border outside the visible frame, and the top one
|
||||
is inside it.
|
||||
"""
|
||||
...
|
||||
|
||||
def fullscreen(self, client: Client, on: bool = True) -> None:
|
||||
"""Takes the window fullscreen, as the program's own key does it (`on`), or brings it back
|
||||
from fullscreen (`on` false). The daemon is not asked: it learns of it from the system, and
|
||||
|
||||
@@ -5,7 +5,8 @@ from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, Platform
|
||||
from komorebi_vm.core.scenarios.layouts import tiled
|
||||
|
||||
# how far outside a window's frame its resize border is pressed: the gap between two tiles
|
||||
# how far outside a window's frame its resize border is pressed by a platform whose border is the
|
||||
# gap between two tiles (`outside_grab`)
|
||||
OFFSET = 4
|
||||
# the shortest drag, in pixels: far enough to be a drag on any display
|
||||
MIN_DRAG = 60
|
||||
@@ -48,7 +49,7 @@ def run(platform: Platform, checks: Checks, clients: list[Client], dx: int | Non
|
||||
window = platform.os_window(Client(titles[left]))
|
||||
assert window is not None
|
||||
before = list(layout)
|
||||
grab = (window.frame.x + window.frame.w + OFFSET, window.frame.y + window.frame.h // 2)
|
||||
grab = platform.resize_grab(window.frame, "right")
|
||||
|
||||
platform.pointer.drag(grab, (grab[0] + dx, grab[1]))
|
||||
|
||||
@@ -140,8 +141,9 @@ def _settled(platform: Platform, clients: list[Client]) -> dict[str, Rect]:
|
||||
return last
|
||||
|
||||
|
||||
def _press_point(grab: str, r: Rect) -> tuple[int, int]:
|
||||
"""Where the pointer is pressed for a grab: in the gap outside the frame."""
|
||||
def outside_grab(r: Rect, grab: str) -> tuple[int, int]:
|
||||
"""Where the pointer is pressed for a grab by a platform whose resize border is the gap outside
|
||||
the frame, `OFFSET` pixels from it: what KDE has on every side."""
|
||||
left, right, top, bottom = r.x - OFFSET, r.x + r.w + OFFSET, r.y - OFFSET, r.y + r.h + OFFSET
|
||||
cx, cy = r.x + r.w // 2, r.y + r.h // 2
|
||||
return {
|
||||
@@ -184,7 +186,9 @@ def _stacked(layout: list[Rect]) -> tuple[int, int] | None:
|
||||
return None
|
||||
|
||||
|
||||
def _cases(layout: list[Rect], titles: list[str], area: Rect) -> list[tuple[str, str, int, int]]:
|
||||
def _cases(
|
||||
platform: Platform, layout: list[Rect], titles: list[str], area: Rect
|
||||
) -> list[tuple[str, str, int, int]]:
|
||||
"""Drags to make, as (window, grab, dx, dy), from the layout: both sides of an edge that two
|
||||
tiles share, a horizontal one, a corner next to two neighbours, and an edge of the screen."""
|
||||
cases: list[tuple[str, str, int, int]] = []
|
||||
@@ -212,7 +216,7 @@ def _cases(layout: list[Rect], titles: list[str], area: Rect) -> list[tuple[str,
|
||||
cases.append((titles[k], "bottomleft", -72, 72))
|
||||
break
|
||||
first = min(range(len(layout)), key=lambda i: layout[i].x)
|
||||
if _press_point("left", layout[first])[0] >= area.x:
|
||||
if platform.resize_grab(layout[first], "left")[0] >= area.x:
|
||||
cases.append((titles[first], "left", -72, 0))
|
||||
return cases
|
||||
|
||||
@@ -230,7 +234,7 @@ def _problems(
|
||||
before = _settled(platform, clients)
|
||||
tiles_before = _tiles(platform)
|
||||
|
||||
px, py = _press_point(grab, before[name])
|
||||
px, py = platform.resize_grab(before[name], grab)
|
||||
end = (max(area.x, px + dx), max(area.y, py + dy))
|
||||
platform.pointer.drag((px, py), end)
|
||||
platform.wait_for(lambda: _tiles(platform) != tiles_before, timeout=3)
|
||||
@@ -303,7 +307,7 @@ def edge_cases(platform: Platform, checks: Checks, clients: list[Client]) -> Non
|
||||
tiles = _tiles(platform)
|
||||
titles = list(tiles)
|
||||
layout = [tiles[t] for t in titles]
|
||||
for case in _cases(layout, titles, platform.work_area()):
|
||||
for case in _cases(platform, layout, titles, platform.work_area()):
|
||||
problems = _problems(platform, clients, case)
|
||||
name, grab, dx, dy = case
|
||||
checks.check(
|
||||
|
||||
@@ -12,6 +12,7 @@ from komorebi_vm.core import snapshot
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, OsWindow, Predicate
|
||||
from komorebi_vm.core.platform import Pointer as PointerDevice
|
||||
from komorebi_vm.core.scenarios.resize import outside_grab
|
||||
from komorebi_vm.core.snapshot import Snapshot
|
||||
from komorebi_vm.kde import Kde
|
||||
|
||||
@@ -226,6 +227,9 @@ class KdePlatform:
|
||||
if not self.kde.wait_for(lambda: self._locked(False), timeout=30):
|
||||
raise AssertionError("the screen did not unlock")
|
||||
|
||||
def resize_grab(self, frame: Rect, grab: str) -> tuple[int, int]:
|
||||
return outside_grab(frame, grab)
|
||||
|
||||
def move_window(self, client: Client, x: int, y: int) -> None:
|
||||
self.kde.sh(f"kdotool windowmove {self._wid(client)} {x} {y}")
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ from PIL import Image
|
||||
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, OsWindow
|
||||
from komorebi_vm.core.scenarios.resize import outside_grab
|
||||
from komorebi_vm.core.snapshot import Snapshot, parse
|
||||
|
||||
DISPLAYS = [Rect(0, 0, 1920, 1080), Rect(1920, 0, 1280, 720), Rect(3200, 0, 1920, 1080)]
|
||||
@@ -156,6 +157,9 @@ class FakeDesk:
|
||||
def unlock(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def resize_grab(self, frame, grab): # noqa: ANN001, ANN201
|
||||
return outside_grab(frame, grab)
|
||||
|
||||
def move_window(self, client: Client, x: int, y: int) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ from PIL import Image
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, OsWindow
|
||||
from komorebi_vm.core.scenarios.commands import PRINTED
|
||||
from komorebi_vm.core.scenarios.resize import outside_grab
|
||||
from komorebi_vm.core.snapshot import Snapshot, parse
|
||||
|
||||
SCREEN = Rect(0, 0, 1920, 1080)
|
||||
@@ -214,6 +215,9 @@ class FakePlatform:
|
||||
if self.retiles_on_unlock:
|
||||
self.moved.clear()
|
||||
|
||||
def resize_grab(self, frame, grab): # noqa: ANN001, ANN201
|
||||
return outside_grab(frame, grab)
|
||||
|
||||
def move_window(self, client: Client, x: int, y: int) -> None:
|
||||
here = self.os_window(client)
|
||||
assert here is not None
|
||||
|
||||
@@ -6,6 +6,7 @@ from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.geometry import Rect
|
||||
from komorebi_vm.core.platform import Client, OsWindow, Pointer
|
||||
from komorebi_vm.core.scenarios import tiling
|
||||
from komorebi_vm.core.scenarios.resize import outside_grab
|
||||
from komorebi_vm.core.snapshot import Snapshot, parse
|
||||
|
||||
|
||||
@@ -103,6 +104,9 @@ class FakePlatform:
|
||||
def unlock(self) -> None:
|
||||
pass
|
||||
|
||||
def resize_grab(self, frame: Rect, grab: str) -> tuple[int, int]:
|
||||
return outside_grab(frame, grab)
|
||||
|
||||
def move_window(self, client: Client, x: int, y: int) -> None:
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user