Skip to content

input: modifier-aware keybind resolution and macOS fixes#13053

Open
qappell wants to merge 1 commit into
ghostty-org:mainfrom
qappell:modifier-consumption
Open

input: modifier-aware keybind resolution and macOS fixes#13053
qappell wants to merge 1 commit into
ghostty-org:mainfrom
qappell:modifier-consumption

Conversation

@qappell

@qappell qappell commented Jun 20, 2026

Copy link
Copy Markdown

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+a correctly does not trigger ctrl+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 in src/config/Config.zig to 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. ghosttyCharacters now correctly derives the produced character when Command or Control is active, and MenuShortcutManager matches the unshifted character with full modifiers first before falling back to the produced character with consumed modifiers stripped. Consumed bindings bypass interpretKeyEvents to 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.

@qappell qappell requested a review from a team as a code owner June 20, 2026 16:39
@ghostty-bot ghostty-bot Bot added the input Keyboard or mouse input label Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

input Keyboard or mouse input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant