hex/src/caps_lock_dictation
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Dax 728c3e3241
labs: caps lock dictation (macOS) (#1502)
* labs: caps lock dictation toggles hands-free dictation

A new macOS Shortcuts lab (labs.caps_lock_dictation, off by default) makes a physical Caps Lock press start a hands-free dictation and the next press finish it. Every press clears the system Caps Lock state so typing stays lowercase, and the key's LED shows Hex's state: solid while recording, blinking while a job transcribes or processes, off when done, cancelled, or failed. Turning the lab off or quitting clears the light and stops forcing the lock off.

Detection comes from the raw HID tracker's Caps Lock usage and the event tap's AlphaShift flag, deduplicated by arrival time. A dedicated worker owns all IOKit work (LED element writes, IOHIDSetModifierLockState, the blink timer) so neither the event tap nor the audio thread touches IOKit. The feature feeds a small light model alongside the HUD's one-consumer event channel rather than taking it over.

The Labs page mac-labs and mac-labs-link goldens are regenerated.

* suppression: group tap switches for caps lock cleanly

run_event_tap took eight arguments after the Caps Lock cancel flag, which clippy rejects. Group the three callback-visible switches into TapFlags instead of suppressing the lint.

* labs: harden caps lock dictation after review

Accept a press only when the HID Caps Lock key-down and its AlphaShift edge agree within a bounded window, so a remapped Control/Escape press never toggles and the lock-reset edge is ignored. Carry the HID press timestamp to the listener and forward presses before any IOKit work.

Keep the LED model on the listener and publish the pattern through an atomic the worker reads. The worker recreates its LED manager on the bounded refresh with an LED-page matching dictionary, so later keyboards join, and stale elements are not re-enumerated on every blink.

Only submission adds a light job and stage events for older or unknown jobs change nothing. Send JobCancelled for canceled worker jobs. Make Caps Lock starts stand down over pending double-tap gestures, and add the Hold-mode Escape exception to AGENTS.md and the docs.

* caps lock: fix macOS clippy findings

Drop the unused AtomicU64 import and borrow the capture host mutably for recording_since, which takes &mut self.

* caps lock: keep the worker handle live through shutdown

Read the JoinHandle when disabling so a timed-out worker detaches explicitly instead of triggering dead_code, and the listener never joins indefinitely.

* caps lock: match device times and own LED retains

Use IOHIDValueGetTimeStamp, scaled through the shared HID clock helper, as the press time and boundary. Match a HID press and an AlphaShift edge in either arrival order by absolute timestamp difference, keep unmatched evidence until a match, and mark Hex's own reset edges so they never enter the gate.

Give each cached LED element an owning Drop that releases exactly one device and one element retain, so multiple elements cannot over-release and clear() cannot leak. Log a missing IOHIDSystem connection, seed the tap's AlphaShift state when the lab turns on, and document the confirmation-window limit.

* caps lock: guard Annotate and fix LED keys

Skip a Caps Lock start while Annotate records while still allowing a running Caps Lock capture to finish. Use the real IOHIDKeys.h element keys (UsagePage/Usage) for the LED matching dictionary. Mark reset edges explicitly in the docs, seed/clear the AlphaShift state after a successful reset so RESETTING cannot swallow a real on-edge, and document the built-in-keyboard and light-race limits.

* caps lock: carry failure notices through the LED model and goldens

* caps lock: hand the HUD its own copy of each indicator event
2026-11-07 15:54:34 -05:00
..
macos.rs labs: caps lock dictation (macOS) (#1502) 2026-11-07 15:54:34 -05:00