summaryrefslogtreecommitdiff
path: root/gui-wm/wayfire/tests/render-regression/layer-check.py
blob: 8b1a3bb8214df3e143f0218f65643c06795fdd8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Panel replication and popup ordering in the desktop cube."""
import io
import subprocess
import sys
import time
from PIL import Image
from ipc import ipc, ENV

baseline = '--baseline' in sys.argv

def check(ok, label, value):
    print(label, value, 'PASS' if ok else 'FAIL', flush=True)
    if not baseline:
        assert ok, (label, value)

def solid(key, layer, color, box):
    r, g, b, a = color
    x, y, w, h = box
    ipc('test/solid', dict(key=key, layer=layer, output='HEADLESS-1',
                          r=r, g=g, b=b, a=a, x=x, y=y, w=w, h=h))

# A shared top-layer panel must appear on every face, including empty workspaces.
ipc('wayfire/set-config-options', {'cube/rotate_layer_shell': '*'})
solid('panel', 3, (0., 1., 1., 1.), (0, 0, 100, 20))
try:
    for x in range(3):
        value = ipc('test/workspace-panel', {'output': 'HEADLESS-1', 'x': x, 'y': 0})['cyan']
        check(value == 2000, f'Panel pixels on workspace {x}', value)
finally:
    ipc('test/solid', {'key': 'panel', 'close': True})
    ipc('wayfire/set-config-options', {'cube/rotate_layer_shell': ''})

# Overlay launchers stay above the transformed desktop, with or without a panel namespace.
ipc('test/rectangle', {'show': True})
solid('popup', 5, (1., 0., 1., 1.), (0, 0, 10000, 10000))
try:
    for namespace in ['', 'waybar']:
        ipc('wayfire/set-config-options', {'cube/rotate_layer_shell': namespace})
        ipc('test/cube', {'output': 'HEADLESS-1'})
        time.sleep(1)
        shot = Image.open(io.BytesIO(subprocess.check_output(
            ['grim', '-o', 'HEADLESS-1', '-'], env=ENV))).convert('RGB')
        leaks = sum(p != (255, 0, 255) for p in shot.get_flattened_data())
        check(leaks == 0, f'Desktop pixels above overlay ({namespace or "fixed panels"})', leaks)
        ipc('test/cube', {'output': 'HEADLESS-1', 'stop': True})
        time.sleep(.5)
finally:
    ipc('test/rectangle', {'show': False})
    ipc('test/solid', {'key': 'popup', 'close': True})
    ipc('test/cube', {'output': 'HEADLESS-1', 'stop': True})
    ipc('wayfire/set-config-options', {'cube/rotate_layer_shell': ''})