git.lucas.co / cce-designer
graphic design tool
git clone https://git.lucas.co/cce-designer.git

scratch/test_offsets.py (2.5K)

 1 import subprocess
 2 import time
 3 import re
 4 import sys
 5 import os
 6 
 7 def run_clearctl(cmd_str):
 8     full_cmd = f"env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 /home/lsgalante/.local/bin/clearctl {cmd_str}"
 9     res = subprocess.run(full_cmd, shell=True, capture_output=True, text=True)
10     return res.stdout.strip()
11 
12 def get_window_rect(title):
13     stdout = run_clearctl("windows")
14     for line in stdout.splitlines():
15         if title in line:
16             m = re.search(r'\bx=(\d+)\s+y=(\d+)\s+w=(\d+)\s+h=(\d+)', line)
17             if m:
18                 return int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4))
19     return None
20 
21 def reset_pointer(window_x, window_y, window_w, window_h):
22     # Click at window center to focus it
23     cx = window_x + window_w // 2
24     cy = window_y + window_h // 2
25     print(f"Focusing window at ({cx}, {cy})...")
26     run_clearctl(f"pointer-move-to {cx} {cy}")
27     time.sleep(0.2)
28     run_clearctl("pointer-click left")
29     time.sleep(0.3)
30     # Press Escape to dismiss any open menus
31     run_clearctl("key-press Escape")
32     time.sleep(0.05)
33     run_clearctl("key-release Escape")
34     time.sleep(0.2)
35 
36 title = "Clear Design Interface"
37 rect = get_window_rect(title)
38 if not rect:
39     print(f"Error: Could not find window '{title}'", file=sys.stderr)
40     sys.exit(1)
41 
42 window_x, window_y, window_w, window_h = rect
43 print(f"Window: x={window_x}, y={window_y}, w={window_w}, h={window_h}")
44 
45 # File menu local coordinates
46 file_local_x = 250.5
47 file_local_y = 137.5
48 
49 # Test offset = 0
50 reset_pointer(window_x, window_y, window_w, window_h)
51 x0 = int(window_x + file_local_x)
52 y0 = int(window_y + file_local_y)
53 print(f"Testing Offset 0: screen ({x0}, {y0})")
54 run_clearctl(f"pointer-move-to {x0} {y0}")
55 time.sleep(0.3)
56 run_clearctl("pointer-click left")
57 time.sleep(1.0)
58 subprocess.run("env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 grim /home/lsgalante/.gemini/antigravity/brain/9048aec8-21a4-458f-94d4-efe127095c7f/screenshot_offset_0.png", shell=True)
59 
60 # Test offset = 24
61 reset_pointer(window_x, window_y, window_w, window_h)
62 x24 = int(window_x + 24 + file_local_x)
63 y24 = int(window_y + 24 + file_local_y)
64 print(f"Testing Offset 24: screen ({x24}, {y24})")
65 run_clearctl(f"pointer-move-to {x24} {y24}")
66 time.sleep(0.3)
67 run_clearctl("pointer-click left")
68 time.sleep(1.0)
69 subprocess.run("env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 grim /home/lsgalante/.gemini/antigravity/brain/9048aec8-21a4-458f-94d4-efe127095c7f/screenshot_offset_24.png", shell=True)
70 
71 print("Done testing offsets.")