input-capture: switch-to-all is swallowed only when it needs Ctrl+Alt

QA finding 4: `ProcessHotKeys` never returns `false` for a matched
`HotKeySwitch2AllPC` (`InputHook.cs:518-522`) — unlike every other hotkey
branch it falls through, so a chord that does not itself hold Ctrl+Alt
toggles ALL mode and still reaches the OS. `HotkeyMatch` grows
`swallows`, true for every hotkey except that one when its configured
chord requires neither Ctrl nor Alt; `handleKey` then queues the action
and carries on encoding the key as an ordinary keystroke, which is what
`ProcessHotKeys` returning `true` leaves to `KeyboardEvent` and
`CallNextHookEx`. Documented in docs/protocol.md §4.5 and in the feature
README, including the residual narrowing (Windows also requires the VK to
land in the switch-machine range, `:611-620`). Unreachable today: the
shortcut ships empty (`MouseWithoutBordersProperties.cs:30`) and an empty
hotkey never matches (`Common.cs:127-129`).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 02:35:51 -07:00
1 parent 09df9c09b2
commit 3626dde603
4 files changed
+43 -6

No files matched your search

+4 -1
View File
@@ -296,7 +296,10 @@ public final class EventTap: @unchecked Sendable {
if !isUp && !isRepeat, let match = matchHotkey(vk: vk, snapshot: snapshot) {
if match.routesLocal { routing.routeLocal() }
enqueue(.hotkey(match.action))
return nil
// A hotkey that Windows lets through (`InputHook.cs:518-522`) is
// still sent and still typed here, as `ProcessHotKeys` returning
// `true` leaves it to `KeyboardEvent` and `CallNextHookEx`.
if match.swallows { return nil }
}
var flags: Int32 = isUp ? KeyFlag.up : 0
+18 -3
View File
@@ -21,11 +21,15 @@ public struct HotkeyMatch: Sendable, Equatable {
/// Whether the tap must route control back to this Mac before returning
/// (contracts C2). True for the escape set only.
public var routesLocal: Bool
/// Whether the key event is eaten. True for every hotkey but one — see
/// `switchToAll` in `match(vk:…)` (`InputHook.cs:518-522`).
public var swallows: Bool
/// A match.
public init(action: HotkeyAction, routesLocal: Bool = false) {
public init(action: HotkeyAction, routesLocal: Bool = false, swallows: Bool = true) {
self.action = action
self.routesLocal = routesLocal
self.swallows = swallows
}
}
@@ -49,7 +53,8 @@ public struct HotkeyMatcher: Sendable {
}
/// Classifies one key-down. Returns `nil` when the key is an ordinary
/// keystroke; any non-`nil` result means the key is swallowed locally.
/// keystroke; a non-`nil` result means the key is a command, and its
/// `swallows` says whether it is also eaten.
///
/// Windows checks in this order and so do we; only the order makes the
/// `else if` chain in `ProcessHotKeys` behave (`InputHook.cs:516-624`). The
@@ -63,7 +68,17 @@ public struct HotkeyMatcher: Sendable {
return HotkeyMatch(action: .escapedToLocal, routesLocal: true)
}
if config.switchToAll.matches(vk: vk, modifiers: modifiers) {
return HotkeyMatch(action: .toggleSwitchToAll) // InputHook.cs:518-522
// The one hotkey `ProcessHotKeys` does not eat: its branch
// (`InputHook.cs:518-522`) falls through instead of returning
// `false`, so the key still reaches the OS unless the chord itself
// holds Ctrl+Alt and is caught by the `if (CtrlDown && altDown)`
// block below (`:585-621`). Unreachable until a hotkey editor
// exists — `Switch2AllPCShortcut` ships empty
// (`MouseWithoutBordersProperties.cs:30`) and an empty hotkey never
// matches (`Common.cs:127-129`).
return HotkeyMatch(
action: .toggleSwitchToAll,
swallows: config.switchToAll.control && config.switchToAll.option)
}
if config.toggleEasyMouse.matches(vk: vk, modifiers: modifiers) {
return HotkeyMatch(action: .toggleEasyMouse) // InputHook.cs:524-537