Repository navigation
fix(input): keep macOS menu shortcuts and Cmd-dropping encodings out of terminals - #424
Merged
Merged
Conversation
…of terminals Issue: Pressing Ctrl+Cmd+F to toggle full screen wrote ^[[102;5u (Ctrl+F with Cmd dropped) into the focused terminal; the same class of leak affected other Command chords that macOS consumes or that the terminal encoding cannot carry. Solution: SDL queues every key press before AppKit performs the matching item of the application menu SDL installs, so Architect forwarded Ctrl+Cmd+F to the ghostty-vt encoder. In legacy mode Ghostty's fixterms CSI u has no Cmd bit and emits Ctrl+F; with Kitty the full-screen press still reached the application. Exact SDL menu key equivalents are now never delivered to a terminal, and legacy encodings send nothing for Command-modified text keys, Backspace, and keypad Enter instead of a different key. A property test checks every mapped key and Command combination across legacy, modifyOtherKeys, and Kitty modes.
There was a problem hiding this comment.
🟡 Changes recommended
Key repeats bypass the menu-shortcut filter when Command is pressed while Ctrl+F is held, allowing Ctrl+Cmd+F to reach the terminal and requiring repeat filtering that preserves the original key release plus a regression test.
1 open issue
What changed in this PR
This PR follows up on #412’s keyboard encoder migration by preventing macOS menu shortcuts and Command-dropping encodings from reaching terminal applications.
Changes:
- Filters exact macOS menu shortcuts before recording terminal presses.
- Suppresses Command chords when the active encoding cannot preserve Command, while retaining explicit line-editing bindings.
- Adds regression coverage and updates user and developer documentation.
Builds and tests were not run during this review.
| File | Description |
|---|---|
src/input/mapper.zig |
Adds menu-chord matching, encoding guards, and regression tests. |
src/c.zig |
Exports SDL constants used by matching and tests. |
src/app/input_keys.zig |
Filters macOS menu presses and tests terminal delivery. |
README.md |
Documents shortcut filtering and unsupported Command chords. |
docs/development.md |
Describes Command-preservation regression coverage. |
docs/ARCHITECTURE.md |
Explains menu filtering and encoding safeguards. |
Review effort: Balanced
…hortcut Issue: Review of #424 noted that pressing Command while Ctrl+F is held makes the delivered press's repeats Ctrl+Cmd+F, which the repeat path forwarded to Kitty and modifyOtherKeys terminals despite being the full-screen shortcut. Solution: Repeats of a delivered press now pass the same macOS menu key equivalent check as presses. Filtered repeats are not forwarded, but the press stays owned, so its release still reaches the original terminal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

TLDR
On macOS, Ctrl+Cmd+F makes the window full screen. In Architect, this key press also went to the terminal and wrote the text
^[[102;5u(the code for Ctrl+F) into it. Now Architect does not send macOS menu shortcuts to the terminal. Also, when the terminal's key format cannot show the Cmd key, Architect sends nothing. It does not send a different key.Issue
SDL sends every key press to the application before AppKit runs the matching menu item. SDL installs these menu shortcuts: Hide ⌘H, Hide Others ⌥⌘H, Quit ⌘Q, Close ⌘W, Minimize ⌘M, and Toggle Full Screen ⌃⌘F. No Architect shortcut matched Ctrl+Cmd+F, so the press went to the ghostty-vt key encoder (introduced in #412):
^Fpath. The press therefore reaches Ghostty's fixterms CSI u branch, whose modifier set has no Cmd bit. The result is\x1b[102;5u, which is exactly Ctrl+F. Before fix(input): preserve terminal key modifiers and event actions #412, the same press sent^F, which shells consume silently, so the leak was not visible.\x1b[102;13u, although macOS already used it to toggle full screen.A sweep over all mapped keys with every Command combination found more legacy-mode cases where Cmd is silently dropped:
\x1b[<cp>;5u/;6u\x7f/\x1b\x7f/\x08\rSolution
input.isMacosMenuKeyEquivalentmatches the exact key and modifier sets of SDL's application menu. On macOS,TerminalKeyPresses.handlePressdrops these presses, so their repeats and releases never reach a terminal either.encodeKeyEventsends nothing for Command-modified keys whose encoding has no Cmd bit: text keys and Backspace in legacy mode without modifyOtherKeys 2, and keypad Enter outside Kitty. Encodings that do carry Cmd (Kitty, modifyOtherKeys 2, xterm-style navigation/function/Enter/Tab/Escape parameters) are unchanged. So are the explicit ⌘←/⌘→/⌘⌫ line-editing bindings.Context
Test plan