feat(v3): macOS global shortcuts land on the labelled key (layout-aware)#5688
feat(v3): macOS global shortcuts land on the labelled key (layout-aware)#5688taliesin-ai wants to merge 1 commit into
Conversation
Carbon's RegisterEventHotKey binds to a physical virtual key code, not a character, so a letter accelerator like "Cmd+A" previously bound to the QWERTY position regardless of the active layout (the key labelled Q on AZERTY). Resolve letter accelerators against the active keyboard layout with UCKeyTranslate: scan the layout for the key that produces the requested letter unshifted and bind that key code. "Cmd+A" now lands on the key labelled A on AZERTY, QWERTZ, Dvorak and similar layouts. If the active layout cannot produce the letter (for example Cyrillic or Greek) we fall back to the ANSI/QWERTY position so registration still succeeds. Only letters are translated: they are produced unshifted on every Latin layout and never appear on the numeric keypad, so the reverse lookup is unambiguous. Digits, punctuation and named keys remain positional, because translating digits would mis-bind to the numpad on layouts whose number row is shifted. The binding is resolved at registration time; re-registering on a live layout change is a possible future enhancement. Verified the reverse lookup against the real French (AZERTY), German (QWERTZ) and Dvorak layouts. Adds unit tests and updates the docs and changelog.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughmacOS global shortcut registration now resolves letter accelerators to virtual key codes using ChangesLayout-aware macOS global shortcuts
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Follow-up to #5686. Makes macOS global shortcuts keyboard-layout aware for letter accelerators.
Problem
Carbon's
RegisterEventHotKeybinds to a physical virtual key code, not a character. SoRegister("Cmd+A")bound to the QWERTY position of A regardless of the active layout — the key labelled Q on AZERTY. (#5686 documented this as a known limitation.)Fix
Resolve letter accelerators against the active keyboard layout using
UCKeyTranslate: scan the layout for the key that produces the requested letter unshifted, and bind that key code.Cmd+Anow lands on the key labelled A on AZERTY/QWERTZ/Dvorak. If the active layout cannot produce the letter (e.g. Cyrillic/Greek), it falls back to the ANSI/QWERTY position so registration still succeeds.Only letters are translated. They are produced unshifted on every Latin layout and never appear on the numeric keypad, so the reverse lookup is unambiguous. Digits, punctuation and named keys stay positional — translating digits would mis-bind to the numpad on layouts whose number row is shifted (e.g. AZERTY's main-row
1is&unshifted, while the numpad1is1).Verification
Proved the reverse lookup against the real installed layouts:
aqzwyFrench swaps a↔q and z↔w; German swaps y↔z; Dvorak fully remaps — each matching the physical position of the labelled key. Combined with the end-to-end "registered key code fires" proof from #5686, the round trip holds: an AZERTY user pressing the key labelled A triggers
Cmd+A.Adds unit tests (
global_shortcut_darwin_test.go), updates the docs macOS tab and the changelog.gofmtclean; fullpkg/applicationtest suite passes on macOS; Windows still cross-compiles.Scope / follow-up
The binding is resolved at registration time. Switching keyboard layout while the app is running keeps existing letter shortcuts on their original physical key. Re-registering on a live layout change (observing
kTISNotifySelectedKeyboardInputSourceChanged) is a deliberate, separable follow-up — kept out of this PR to keep it tight and because it is the harder part to test.Summary by CodeRabbit
Bug Fixes
Cmd+Afollow the labeled key on layouts such as AZERTY, QWERTZ, and Dvorak.Documentation