[Bug]: macOS background pixel clicks reach the app but never the custom-drawn view under them
Primary area
Cua Driver
Summary
On macOS, a background pixel click on a view with no accessibility element (a custom-drawn NSView) reaches the app but never the view. The posted events carry the right screen location, but AppKit sets their locationInWindow from the stamped window location, and the background route stamps the screen point there. The press then sits outside the window and hit testing finds no view. Every call reports route: "synthetic_events" with effect: "unverifiable".
Reproduction
-
Run a window whose content is one custom view that logs presses:
import AppKit final class Receiver: NSView { override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true } override func draw(_ dirtyRect: NSRect) { NSColor.systemTeal.setFill() bounds.fill() } override func mouseDown(with event: NSEvent) { NSLog("mouseDown locationInWindow=%@", NSStringFromPoint(event.locationInWindow)) } } let app = NSApplication.shared app.setActivationPolicy(.regular) let window = NSWindow(contentRect: NSRect(x: 200, y: 200, width: 760, height: 380), styleMask: [.titled], backing: .buffered, defer: false) window.contentView = Receiver() window.makeKeyAndOrderFront(nil) app.run()swiftc receiver.swift -o receiver && ./receiver, then bring another app to the front. -
list_windowsfor its pid, thenget_window_stateon the window. -
clickthe middle of the teal area in screenshot pixels, for example at a screenshot scale of 1:{"target": {"kind": "window", "pid": <pid>, "window_id": <window_id>}, "x": 380, "y": 222, "session": "s"}
3 of 3 clicks reproduce it.
Expected behavior
The receiver logs a mouseDown for each click, at locationInWindow (380, 190).
Actual behavior
Nothing is logged. A second probe app that also records every event reaching the app (an NSEvent local monitor) shows the clicks do arrive, with the right screen location but the screen point read as a window point:
window frame, top-left origin x -3300, y 1177, 760 by 412
press requested at window point (130, 222)
CGEvent location of the press (-3170, 1399)
NSEvent.locationInWindow (-3170, -987) (screen x, 412 minus screen y)
expected locationInWindow (130, 190)
So only a window whose top-left corner sits at the screen origin would get these clicks.
Environment
Cua Driver 0.33.3 release app, daemon from its LaunchAgent. Also a debug build of main 2b3e4e548 run in-process with cua-driver mcp --direct. macOS 27.0 (26A428), Apple silicon. The target window was on a second display to the left of the built-in one, with another app in front.
Evidence
chromium_click_route_plan receives the window-local point, discards it (let _ = (win_local_x, win_local_y);) and stamps the screen point on the move, press and release:
https://github.com/trycua/cua/blob/2b3e4e548c6d27f918f5367f84c094151aa10c8f/libs/cua-driver/rust/crates/platform-macos/src/input/mouse.rs#L482-L555
Before 681bc44807d1be81a4357f8e158f1c74a81d5a5b (2026-09-22, first released in 0.28.3) the same function stamped the window-local point, and the foreground route still does: https://github.com/trycua/cua/blob/2b3e4e548c6d27f918f5367f84c094151aa10c8f/libs/cua-driver/rust/crates/platform-macos/src/input/mouse.rs#L290-L313
Presses that reached a custom view under the point, background click, same window:
| Build | Reached the view |
|---|---|
| 0.33.3 release | 0 of 6 |
main 2b3e4e548, debug, mcp --direct |
0 of 20 |
| main with the window-local stamp restored | 23 of 23 |
Chrome is not affected: a full-window canvas page got 10 of 10 at the right point with either stamp.
Workaround and additional context
- No background workaround.
delivery_mode: "foreground"stamps the window-local point but fronts the window and moves the pointer (not tried here). - A fix that restores the window-local stamp is ready; PR to follow.
- Related: #4350 (canvas clicks delivered at the element's center) and #4207 (Tk apps that read the pointer).
Submission checks
- [x] I searched for duplicate issues and active pull requests.
- [x] This issue describes a single problem.
- [x] I removed credentials, private data, sensitive screenshots, and vulnerability details from this public report.
Thanks for the report, @FredAmartey. I've labelled it and assigned @injaneity to take a look. There is a proposed fix in #4632, which we'll review on its own.
Fixed by #5492 (cua-driver-rs v0.39.0).