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

scratch/test_focused_clicks.py (2.4K)

 1 import subprocess
 2 import time
 3 import re
 4 import sys
 5 
 6 def run_clearctl(cmd_str):
 7     full_cmd = f"env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 /home/lsgalante/.local/bin/clearctl {cmd_str}"
 8     res = subprocess.run(full_cmd, shell=True, capture_output=True, text=True)
 9     return res.stdout.strip()
10 
11 def get_window_rect(title):
12     stdout = run_clearctl("windows")
13     for line in stdout.splitlines():
14         if title in line:
15             m = re.search(r'\bx=(\d+)\s+y=(\d+)\s+w=(\d+)\s+h=(\d+)', line)
16             if m:
17                 return int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4))
18     return None
19 
20 def reset_pointer():
21     run_clearctl("key-press Escape")
22     time.sleep(0.05)
23     run_clearctl("key-release Escape")
24     time.sleep(0.2)
25 
26 title = "Clear Design Interface"
27 rect = get_window_rect(title)
28 if not rect:
29     print(f"Error: Could not find window '{title}'", file=sys.stderr)
30     sys.exit(1)
31 
32 window_x, window_y, window_w, window_h = rect
33 print(f"Window: x={window_x}, y={window_y}, w={window_w}, h={window_h}")
34 
35 # View menu local coordinates (under circular mode):
36 # center x = 313.7 + 23.0 = 336.7
37 # center y = 145.1 + 17.5 = 162.6
38 view_local_x = 336.7
39 view_local_y = 162.6
40 
41 # Test offset = 0
42 print("--- Testing Offset 0 ---")
43 reset_pointer()
44 print(run_clearctl(f"focus-window \"{title}\""))
45 time.sleep(0.3)
46 x0 = int(window_x + view_local_x)
47 y0 = int(window_y + view_local_y)
48 print(f"Moving to ({x0}, {y0})")
49 run_clearctl(f"pointer-move-to {x0} {y0}")
50 time.sleep(0.3)
51 print("Clicking left...")
52 run_clearctl("pointer-click left")
53 time.sleep(1.0)
54 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_view_offset_0.png", shell=True)
55 
56 # Test offset = 24
57 print("--- Testing Offset 24 ---")
58 reset_pointer()
59 print(run_clearctl(f"focus-window \"{title}\""))
60 time.sleep(0.3)
61 x24 = int(window_x + 24 + view_local_x)
62 y24 = int(window_y + 24 + view_local_y)
63 print(f"Moving to ({x24}, {y24})")
64 run_clearctl(f"pointer-move-to {x24} {y24}")
65 time.sleep(0.3)
66 print("Clicking left...")
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_view_offset_24.png", shell=True)
70 
71 print("Done.")