summaryrefslogtreecommitdiffstats
path: root/scripts/test-focus.py
blob: e1bbe2d80410e3a2fd565a2978c0d0ae9411c2a8 (plain) (blame)
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
52
53
54
55
56
#!/usr/bin/env python3
"""Drive the focus-routing gate: 3 windows, type markers, verify routing.

Connects to the QEMU monitor once and keeps the socket open (the per-call
scripts/sendkeys.py pattern loses the socket when the monitor resets).

Usage:  python3 scripts/test-focus.py /tmp/qmon.sock
"""
import socket
import sys
import time

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(sys.argv[1] if len(sys.argv) > 1 else "/tmp/sysboot-mon.sock")


def sk(k, d=0.35):
    sock.sendall(f"sendkey {k}\n".encode())
    time.sleep(d)


def line(txt, d=0.8):
    for ch in txt:
        if ch == " ":
            sk("spc", 0.1)
        elif ch.isupper():
            sk("shift-" + ch.lower(), 0.12)
        else:
            sk(ch, 0.12)
    sk("ret", d)


time.sleep(0.5)

# Home is focused at boot.
line("windows")          # expect: home + nothing (or existing windows)
time.sleep(1.5)

# F1 -> term1 (focused on creation)
sk("f1", 1.5)
line("echo TERM1MARK")
time.sleep(1.0)

# F1 -> term2 (focused on creation)
sk("f1", 1.5)
line("echo TERM2MARK")
time.sleep(1.0)

# F2 cycles z-order: term2 -> term1
sk("f2", 0.8)
line("echo CYCLED")
time.sleep(1.0)

# F2 again: term1 -> home (window 0, oldest)
sk("f2", 0.8)
line("windows")