git.lucas.co / cce-system-interface
system settings
git clone https://git.lucas.co/cce-system-interface.git

scratch/click_add.py (2.9K)

 1 from PIL import Image
 2 import subprocess
 3 import time
 4 
 5 # Load the cropped image
 6 img = Image.open("/home/lsgalante/.gemini/antigravity/brain/e9f42138-61bb-4037-ac7e-0b1d2091db1c/crop_keybindings.png")
 7 width, height = img.size
 8 print(f"Crop size: {width}x{height}")
 9 
10 # Find blue button pixels.
11 # The button background color is blue, e.g. RGB around [41, 76, 101] or similar.
12 # Let's search for pixels where B > R + 15 and B > G + 10, and not too dark or light.
13 blue_pixels = []
14 for y in range(height):
15     for x in range(width):
16         r, g, b = img.getpixel((x, y))[:3]
17         if b > r + 15 and b > g + 10 and 30 < b < 180:
18             blue_pixels.append((x, y))
19 
20 if blue_pixels:
21     print(f"Found {len(blue_pixels)} blue pixels.")
22     min_x = min(p[0] for p in blue_pixels)
23     max_x = max(p[0] for p in blue_pixels)
24     min_y = min(p[1] for p in blue_pixels)
25     max_y = max(p[1] for p in blue_pixels)
26     
27     print(f"Blue bounding box: X=[{min_x}, {max_x}], Y=[{min_y}, {max_y}]")
28     
29     target_pt = ((min_x + max_x) // 2, (min_y + max_y) // 2)
30     print(f"Target center in crop: {target_pt}")
31     
32     # Calculate screen coordinates (in physical pixels)
33     # Remember crop starts at: wx = 185 * 2 = 370
34     # wy_crop_start = wy + wh // 2 = 27 * 2 + 1069 = 1123
35     screen_x_physical = 370 + target_pt[0]
36     screen_y_physical = 1123 + target_pt[1]
37     
38     # wlrctl pointer move takes coordinates in logical pixels!
39     # Wait, let's divide physical pixels by 2.0 to get logical pixels.
40     logical_x = int(screen_x_physical / 2.0)
41     logical_y = int(screen_y_physical / 2.0)
42     print(f"Clicking at screen logical coords: ({logical_x}, {logical_y})")
43     
44     # Reset cursor to top-left
45     subprocess.run("env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 wlrctl pointer move -3000 -3000", shell=True)
46     time.sleep(0.1)
47     # Move to logical coordinates
48     subprocess.run(f"env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 wlrctl pointer move {logical_x} {logical_y}", shell=True)
49     time.sleep(0.2)
50     # Click
51     subprocess.run("env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 wlrctl pointer click left", shell=True)
52     time.sleep(0.8)
53     
54     # Take new screenshot
55     screenshot_path = "/home/lsgalante/.gemini/antigravity/brain/e9f42138-61bb-4037-ac7e-0b1d2091db1c/screenshot_after_click.png"
56     subprocess.run(f"env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 grim {screenshot_path}", shell=True)
57     
58     # Crop again to verify
59     img_new = Image.open(screenshot_path)
60     wx, wy, ww, wh = 185 * 2, 27 * 2, 641 * 2, 1069 * 2
61     crop_box = (wx, wy + wh // 2, wx + ww // 2, wy + wh)
62     cropped_new = img_new.crop(crop_box)
63     cropped_new.save("/home/lsgalante/.gemini/antigravity/brain/e9f42138-61bb-4037-ac7e-0b1d2091db1c/crop_keybindings_after.png")
64     print("Verification crop saved to crop_keybindings_after.png")
65 else:
66     print("Could not find blue pixels for Add Keybind button.")