mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-15 13:22:19 +01:00
feat(e2e): sync the neutral core from kfde 72631512
This commit is contained in:
1 parent
f6d877b82d
commit
7e5f956415
2 files changed
+24
-9
No files matched your search
@@ -58,11 +58,11 @@ def hue_of(image: Image.Image) -> str:
|
||||
|
||||
|
||||
def ring_hue(frame: Rect, image: Image.Image, reach: int = 12) -> str:
|
||||
"""The hue of the ring around a window: the colors within `reach` pixels of the left edge of
|
||||
its frame, on either side of it, at its middle. The window's own color is neutral, so what has
|
||||
a hue is the border; where the ports draw it, outside the frame or on its edge, differs."""
|
||||
"""The hue of the ring around a window: the colors within `reach` pixels outside the left edge
|
||||
of its frame, at its middle. Both ports draw the border outside the frame. What is inside it is
|
||||
the window's own, whatever its color, and is not read."""
|
||||
seen = set()
|
||||
for x in range(max(0, frame.x - reach), min(image.size[0], frame.x + reach)):
|
||||
for x in range(max(0, frame.x - reach), min(image.size[0], frame.x)):
|
||||
red, _, blue = pixels.pixel(image, x, frame.y + frame.h // 2)
|
||||
seen.add(_hue(red, blue))
|
||||
seen.discard("neither")
|
||||
@@ -88,13 +88,25 @@ def run(platform: Platform, checks: Checks) -> None:
|
||||
return platform.wait_for(lambda: hue_of(platform.screenshot(name)) == hue, timeout=20)
|
||||
|
||||
def has_ring(client: Client, hue: str, name: str) -> bool:
|
||||
"""The window has a ring of `hue` in a screenshot taken until it does."""
|
||||
"""The window has a ring of `hue` in a screenshot taken until it does. When it has not,
|
||||
what the last screenshot had is printed: the frame, and the colors it was read from."""
|
||||
|
||||
def ring() -> bool:
|
||||
window = platform.os_window(client)
|
||||
return window is not None and ring_hue(window.frame, platform.screenshot(name)) == hue
|
||||
|
||||
return platform.wait_for(ring, timeout=20)
|
||||
if platform.wait_for(ring, timeout=20):
|
||||
return True
|
||||
window = platform.os_window(client)
|
||||
if window is None:
|
||||
print(f" {client.title} has no window")
|
||||
else:
|
||||
image = platform.screenshot(name)
|
||||
f = window.frame
|
||||
y = f.y + f.h // 2
|
||||
row = [pixels.pixel(image, x, y) for x in range(max(0, f.x - 12), f.x + 4, 2)]
|
||||
print(f" {client.title} {f}: ring {ring_hue(f, image)}, wanted {hue}; pixels {row}")
|
||||
return False
|
||||
|
||||
platform.set_wallpaper(other)
|
||||
checks.check(
|
||||
|
||||
@@ -11,7 +11,7 @@ from tests.fake_platform import FakePlatform
|
||||
HUES = {"warm": (230, 40, 40), "cool": (40, 60, 230), "other": (60, 230, 60)}
|
||||
|
||||
|
||||
# the ring is the 4 pixels of the wallpaper's hue that the window leaves at its left
|
||||
# the ring is the wallpaper's hue outside the window, which is the color of what is inside it
|
||||
class FakeWallpaper(FakePlatform):
|
||||
def __init__(self, *args, **kwargs) -> None: # noqa: ANN002, ANN003
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -20,6 +20,8 @@ class FakeWallpaper(FakePlatform):
|
||||
self.workspace_wallpapers: dict[int, str] = {}
|
||||
self.workspace = 0
|
||||
self.puts_back = True
|
||||
# room outside the first window for its ring
|
||||
self.workspace_padding = 10
|
||||
|
||||
def put_file(self, path: str, data: bytes) -> None:
|
||||
assert data.startswith(b"\x89PNG"), "a picture"
|
||||
@@ -46,7 +48,8 @@ class FakeWallpaper(FakePlatform):
|
||||
|
||||
def komorebic(self, *args: str) -> str:
|
||||
if args[0] == "focus-workspace":
|
||||
self.workspace = int(args[1])
|
||||
self.workspace = self.current = int(args[1])
|
||||
self.focus = min(self.focus, max(0, len(self.containers) - 1))
|
||||
if self.puts_back or self.shown != self.wallpaper():
|
||||
self._show()
|
||||
return ""
|
||||
@@ -60,5 +63,5 @@ class FakeWallpaper(FakePlatform):
|
||||
window = self.os_window(client)
|
||||
if window is not None and window.focused:
|
||||
f = window.frame
|
||||
draw.rectangle((f.x + 4, f.y, f.x + f.w, f.y + f.h), fill=(48, 48, 48))
|
||||
draw.rectangle((f.x, f.y, f.x + f.w, f.y + f.h), fill=(48, 48, 48))
|
||||
return image
|
||||
Reference in new issue
Block a user