Skip to content

Commit cbb0303

Browse files
committed
Fix coordinate conversion for Live Mouse Mode
The previous implementation used NSScreen.main for coordinate conversion, which caused clicks to drift towards the top of the screen, especially in multi-monitor setups. Changes: - Find the screen that contains the mouse cursor location - Use that specific screen's frame for accurate coordinate conversion - Add fallback logic for edge cases using the full desktop bounds This ensures clicks happen exactly where the cursor is positioned.
1 parent af73f1c commit cbb0303

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Sources/ClickIt/Lite/SimpleViewModel.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,27 @@ final class SimpleViewModel: ObservableObject {
128128
private extension NSPoint {
129129
func asCGPoint() -> CGPoint {
130130
// Convert from AppKit coordinates (bottom-left origin) to CG coordinates (top-left origin)
131-
guard let screen = NSScreen.main else { return CGPoint(x: x, y: y) }
132-
let screenHeight = screen.frame.height
133-
return CGPoint(x: x, y: screenHeight - y)
131+
// Find the screen containing this point
132+
let screens = NSScreen.screens
133+
134+
// Find which screen contains this point
135+
for screen in screens {
136+
let frame = screen.frame
137+
if frame.contains(self) {
138+
// Convert using this screen's frame
139+
let screenY = frame.origin.y
140+
let screenHeight = frame.height
141+
return CGPoint(x: x, y: screenY + screenHeight - y)
142+
}
143+
}
144+
145+
// Fallback: use the screen with the highest Y (topmost screen)
146+
// This handles the full desktop coordinate space
147+
if let maxY = screens.map({ $0.frame.maxY }).max() {
148+
return CGPoint(x: x, y: maxY - y)
149+
}
150+
151+
// Ultimate fallback
152+
return CGPoint(x: x, y: y)
134153
}
135154
}

0 commit comments

Comments
 (0)