From ece6bbf8fdd5b09ce154d11ea510389db4633a6e Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 16 Sep 2026 02:33:58 -0700 Subject: [PATCH] input-capture: handleMouse reads the screen layout only when remote QA finding 2: `screens.layout` (a locked read) was taken before the destination branch, but only the remote branch uses it. The local branch is what runs for essentially every mouse event while this Mac keeps its own pointer, so it was paying for a lock acquisition it discarded (invariant 4: minimum work on the local path). Moved inside the `isRemote` branch, matching `handleScroll`, which already checked the destination before reading the layout. Co-Authored-By: Claude Opus 5 (1M context) --- Sources/MWBMac/EventTap.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/MWBMac/EventTap.swift b/Sources/MWBMac/EventTap.swift index b7487b7..1e2aca4 100644 --- a/Sources/MWBMac/EventTap.swift +++ b/Sources/MWBMac/EventTap.swift @@ -359,10 +359,14 @@ public final class EventTap: @unchecked Sendable { guard let message = EventTap.windowsMessage(for: type, event: event) else { return Unmanaged.passUnretained(event) } - let layout = screens.layout let isMove = message.flags == WindowsMessage.mouseMove if snapshot.destination.isRemote { + // The layout is only read here, on the branch that needs it, so the + // local path — every mouse event on a Mac that is not controlling a + // peer — pays for no lock it throws away (invariant 4), exactly as + // `handleScroll` does. + let layout = screens.layout let dx = Double(event.getIntegerValueField(.mouseEventDeltaX)) let dy = Double(event.getIntegerValueField(.mouseEventDeltaY)) let virtual = routing.advanceVirtualCursor(dx: dx, dy: dy, clampedTo: layout.primary)