input: modifier-aware keybind resolution and macOS fixes#13053
Open
qappell wants to merge 1 commit into
Open
Conversation
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.
This PR corrects how Ghostty matches keybinds against keypresses by accounting for modifiers that the keyboard layout consumes to produce a character. Interest in this was spurred by trying to get
ctrl+shift+=to work on Linux (discussion #7243).The core resolution logic now checks the physical key and unshifted character with raw modifiers before matching against the produced character with consumed modifiers masked out. When the produced character differs from the unshifted character only in case, the raw modifiers are retained, so
ctrl+shift+acorrectly does not triggerctrl+a. I also switched Unicode case folding from full to simple, since full case folding can expand a single codepoint to multiple. I improved the documentation insrc/config/Config.zigto explain keybinds and the new flow meticulously.While GTK exposes consumed modifiers directly on Linux, macOS lacks a direct API, so consumed modifiers are computed via a heuristic in
NSEvent.ghosttyKeyEvent.ghosttyCharactersnow correctly derives the produced character when Command or Control is active, andMenuShortcutManagermatches the unshifted character with full modifiers first before falling back to the produced character with consumed modifiers stripped. Consumed bindings bypassinterpretKeyEventsto avoid starting unfinished dead-key compositions, and a guard prevents AppKit from fuzzy-matching away a meaningful shift when matching menu equivalents. I also noticed that when a binding triggers a menu action during performKeyEquivalent, keyDown is bypassed, so I made Ghostty record the keypress separately to ensure it shows in the terminal inspector.I verified that all default keybinds work as expected on macOS Tahoe and NixOS (both using Ghostty's Nix environment) with the US English layout, and I tested functionality across several other layouts, mainly European languages, which should be okay. Custom user-defined keybinds that worked before will most likely not be affected.
I used AI (mainly Claude Opus 4.8, Google Gemini, and Google AI Mode) to search the web for documentation, help with proper Swift and Zig syntax, and catch edge cases I missed. Nearly all the logic was written by myself.