Skip to content

Dictation: modifier-only shortcut (⌥⌘ alone) - #29

Merged
9clg6 merged 18 commits into
mainfrom
oats-modifier-shortcut
Nov 23, 2026
Merged

9clg6 merged 18 commits into
mainfrom
oats-modifier-shortcut

Conversation

@9clg6

@9clg6 9clg6 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Why

On first real use, pressing ⌘⌥ alone in the shortcut recorder did nothing: modifier-only combos were ignored silently, and Carbon hotkeys cannot register them.

What

  • Recorder accepts two or more modifiers (at least one of ⌘ ⌥ ⌃) released with no other key; a single modifier is refused with a visible message.
  • Stored as dictation_modifiers with no dictation_key_code; existing prefs load unchanged.
  • Channel registerModifiers {modifiers, holdMs}. Native side watches NSEvent monitors and decides "nothing else happened" with the system-wide HID event counters, so a key consumed by another app's hotkey (⌘⌥D, ⌘⌥Esc) still counts. Nothing is emitted during holdMs; a clean quick tap → tapped; a clean hold → pressed at the threshold, then released; any key, mouse button or extra modifier → no event (before the threshold) or aborted (after).
  • Every dictation is bounded: 8 s without speech before the first words ends it silently; 3 minutes ends it and delivers the text.
  • Needs Accessibility: ACCESSIBILITY_REQUIRED is surfaced in the setting row; registration is retried when the app becomes active, so a grant works without relaunch.
  • An aborted press during a meeting does not cut the meeting's microphone text.

Checked

  • Tests: app 2030, core_data 168, core_domain 58; analyze clean; debug build.
  • Throwaway probe: a synthetic key consumed by a Carbon hotkey was missed by the global monitor and counted by the HID counter.

Not checked

  • The shortcut on screen with real apps (⌘⌥D, ⌘⌥Esc, ⌘⌥I in Chrome, ⌘⌥-drag in Finder).

Clement Guyon added 18 commits November 23, 2026 14:44
Why: the user asked for a two-key shortcut and pressed ⌘⌥ in the
recorder; modifier-only combos were silently ignored (Carbon cannot
register them).
What: DictationShortcut.keyCode is nullable (null = modifiers only,
stored as dictation_modifiers without dictation_key_code; old prefs load
unchanged; invalid masks fall back to ⌃⌥Espace); the channel gains
registerModifiers and the aborted event; the controller registers
through registerModifiers, reports needsAccessibility when refused and
retries on each apply; an aborted press discards the dictation it
started without any output or error, while a toggled dictation's stop
press is decided on release so an aborted chord leaves it running;
during a meeting an aborted press is abandoned (no interval saved, the
microphone text goes to the note). Réglages records ⌥⌘ chords, refuses a
single modifier with a French message, shows the Accessibility need
next to the shortcut and re-registers when the permission comes back.
Proof: the modifier-only specs (preferences, controller, channel,
recorder, accessibility) and the existing dictation/settings specs pass
(390).
Why: Carbon RegisterEventHotKey cannot register a shortcut without a key,
so ⌥⌘ needs to be watched natively.
What: registerModifiers installs global and local NSEvent monitors on
flagsChanged, keyDown and mouse downs (refused with
ACCESSIBILITY_REQUIRED unless AXIsProcessTrusted); pressed when exactly
the chosen modifiers become held by adding a key, released when one goes
up, aborted (no released) on any key or mouse button down or an extra
modifier while held; a key pressed with modifiers held taints the chord
until all are up; caps lock, fn and numeric pad flags are ignored.
Escape cancel is armed without modifiers only for these shortcuts.
Registering a keyed shortcut or unregistering removes the monitors.
Proof: flutter build macos --debug compiles and links; not run live.
Why: pressing the dictation shortcut during a meeting dropped the id of
the sentence in progress; when that sentence had already been
checkpointed, its final text was saved under a new id and the note got
two lines (seen with an aborted ⌥⌘ press in a scratch test).
What: beginDictation no longer clears the microphone phrase; the
sentence's done replaces its provisional row. The recorder hint now says
two modifiers alone are accepted.
Proof: scratch test (deleted) went from two rows to one; dictation specs
pass (119).
…dictation

Why: review of PR #29: any ⌘⌥+key opened the microphone and an aborted
press split a meeting sentence; a lost release or a forgotten toggle
could keep a dictation open forever; Accessibility granted with
Settings closed left the shortcut dead until relaunch.
What: registerModifiers passes holdMs (from holdThreshold, the single
source); the controller handles tapped (toggle start/stop) and treats
pressed as an already-confirmed hold (no threshold recount);
noSpeechTimeout (8 s, only before the first speech, ends silently) and
maxDictationDuration (3 min, ends and delivers the text so far) bound
every dictation; on app resume a shortcut refused for Accessibility is
retried, Settings open or not.
Proof: the new specs (channel, modifier-only controller, time limits,
accessibility resume) and the dictation/core/settings specs pass (463).
…event counters

Why: a key down consumed by another app's hotkey (⌘⌥D, ⌘⌥Esc) is not
delivered to a global NSEvent monitor, so a quick chord looked like a
clean tap of ours.
What: after exactly the chosen modifiers go down the press is undecided
and nothing is emitted for holdMs; a clean release before -> tapped; a
clean hold to the threshold -> pressed then released; any key, mouse
button or extra modifier -> nothing (aborted after pressed). Cleanliness
is checked against CGEventSource.counterForEventType(.hidSystemState)
for key and mouse downs, snapshotted at chord down and at pressed;
monitors stay for flagsChanged and early rejection.
Proof: throwaway probe (F19 posted with CGEvent while a Carbon hotkey
held it: hotkey fired, global monitor saw nothing, keyDown counter +1);
flutter build macos --debug links. Not run live.
@9clg6
9clg6 merged commit 7eb0f55 into main Nov 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant