From add0fa4bbc788e0bbda94acae630654ea2987a36 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 16 Sep 2026 02:36:22 -0700 Subject: [PATCH] input-capture: work-log entry for the rework round Answers the four QA findings of 2026-09-16 by number, with what changed and why, and records that the round was build-only: no tap created, no `CGEvent` posted, no cursor moved, no permission requested. Co-Authored-By: Claude Opus 5 (1M context) --- docs/features/input-capture/README.md | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/features/input-capture/README.md b/docs/features/input-capture/README.md index 07be5c5..85e29eb 100644 --- a/docs/features/input-capture/README.md +++ b/docs/features/input-capture/README.md @@ -454,6 +454,56 @@ Windows' `WM_MOUSEHWHEEL` (§10.4 note 10), and the `kVK_Help` → `VK_INSERT` and `kVK_ANSI_KeypadClear` → `VK_NUMLOCK` choices, which map by physical position rather than by label. +### 2026-09-16 — dev (Opus), rework after the QA verdict + +Four commits, one per finding, build-only verification again: no tap was +created, no `CGEvent` posted, no cursor moved, no permission requested or +preflighted. `xcrun swift-format format -i --recursive Sources Package.swift` +then `tools/guard.sh -m 8 -t 900 -- tools/gates.sh` — green on each commit. + +1. **`EventTap.thread` is now locked.** `runLoopLock` is renamed `stateLock` + and guards `runLoopStorage` *and* `thread`, so the class comment's claim + that every cross-thread field is behind a lock is true and `stop()` really + is callable from any thread — including the contracts-C2 signal-handler + path. `start()`'s check-and-claim is one critical section rather than a + plain read of a `var`, so two concurrent starts cannot both install a tap; + the failure path clears the field under the same lock. Nothing else moved: + `machPort`, the modifier bookkeeping and the wheel remainders are still + tap-thread-only. +2. **`handleMouse` reads `screens.layout` only when the destination is + remote.** The read moved inside the `isRemote` branch — the only code that + uses it — so the local branch, which is what runs for every mouse event on + a Mac that is not controlling a peer, no longer pays for a discarded lock + acquisition (invariant 4). This is the shape `handleScroll` already had. +3. **The lock claim is now counted, not asserted.** The old "three + acquisitions at most (snapshot, virtual cursor, counters)" named two of the + four reachable lock objects and undercounted every path. Replaced by a + bullet listing all four (`EventTap.counters`, `RoutingState`'s box, + `Screens`' layout, `CaptureQueue`'s ring) and the per-event count on each + path: local key 2, local move 3 (4 with an edge candidate), remote key 3, + remote move 6 (5 when the candidate is suppressed) — with the extras + (unmapped key, matched hotkey, escape, one push per modifier transition) + spelled out. The counts are post-fix-2; the remote-move worst case is + unchanged because that path did need the layout. +4. **Switch-to-all is no longer unconditionally swallowed.** + `ProcessHotKeys` (`InputHook.cs:518-522`) is the one branch that does not + return `false` on a match, so the key reaches the OS unless the chord itself + holds Ctrl+Alt and the `if (CtrlDown && altDown)` block below catches it. + `HotkeyMatch` gains `swallows`; the `switchToAll` branch sets it from + `control && option`, and `handleKey` queues the action and then falls + through to ordinary key encoding when it is false — which mirrors + `ProcessHotKeys` returning `true` and leaving the key to `KeyboardEvent` + plus `CallNextHookEx`. Written up in docs/protocol.md §4.5 and in the + Hotkeys assumption, together with the one narrowing that remains: Windows' + actual swallow additionally requires the VK to sit in the switch-machine + range (`:611-620`), which the ⌃⌥ test approximates. Nothing reaches this + today — `Switch2AllPCShortcut` ships empty + (`MouseWithoutBordersProperties.cs:30`) and an empty hotkey never matches + (`Common.cs:127-129`) — so it is app-shell's hotkey editor that inherits it. + +`HotkeyMatch` gained a field, so the Handshakes block was updated with it. No +other promised signature changed; no other lane's files were touched. + ## QA log ### 2026-09-16 — QA (Sonnet)