Skip to content

macos: apply key-remap to menu key equivalents#12602

Open
knu wants to merge 1 commit into
ghostty-org:mainfrom
knu:macos-key-remap-menu-equivalents
Open

macos: apply key-remap to menu key equivalents#12602
knu wants to merge 1 commit into
ghostty-org:mainfrom
knu:macos-key-remap-menu-equivalents

Conversation

@knu
Copy link
Copy Markdown
Contributor

@knu knu commented May 6, 2026

Refs #12293
Related: #3493 (duplicates: #4374, #5091), #7013
Supersedes: #12597

Apply key-remap before keybind lookup and when reporting keybind triggers for AppKit menu key equivalents.

Previously, menu shortcuts were registered from the configured trigger without considering modifier remaps. This let AppKit consume the physical shortcut before Ghostty could match the remapped keybind.

Config.keyEventIsBinding now remaps event modifiers before lookup, so remapped key equivalents match the same keybinds as normal key events.
CApi.config_trigger_ returns the physical trigger that maps back to the configured logical modifiers, and leaves triggers unset when no remapped physical shortcut can produce them.

RemapSet.unapply performs the reverse lookup and is checked with apply so ambiguous or impossible remaps do not register incorrect menu shortcuts.

Inspired by: @bo2themax (#12597 (review))

AI usage: OpenAI Codex helped investigate, implement, test, and refine this change. I reviewed and tested the resulting code.

@knu knu requested review from a team as code owners May 6, 2026 18:32
@ghostty-bot ghostty-bot Bot added the os/macos label May 6, 2026
Copy link
Copy Markdown
Member

@bo2themax bo2themax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly what I thought. I think you can check mappings and remap if needed in Config.keyEventIsBinding and CApi.config_trigger_ , it should also make the menu shortcut correct again, and you don't need to change the apprt anymore.

Refs ghostty-org#12293
Related: ghostty-org#3493 (duplicates: ghostty-org#4374, ghostty-org#5091), ghostty-org#7013
Supersedes: ghostty-org#12597

Apply `key-remap` before keybind lookup and when reporting keybind
triggers for AppKit menu key equivalents.

Previously, menu shortcuts were registered from the configured trigger
without considering modifier remaps. This let AppKit consume the
physical shortcut before Ghostty could match the remapped keybind.

`Config.keyEventIsBinding` now remaps event modifiers before lookup, so
remapped key equivalents match the same keybinds as normal key events.
`CApi.config_trigger_` returns the physical trigger that maps back to the
configured logical modifiers, and leaves triggers unset when no remapped
physical shortcut can produce them.

`RemapSet.unapply` performs the reverse lookup and is checked with
`apply` so ambiguous or impossible remaps do not register incorrect menu
shortcuts.

Inspired by: @bo2themax (ghostty-org#12597 (review))

AI usage: OpenAI Codex helped investigate, implement, test, and refine this
change. I reviewed and tested the resulting code.
@knu knu force-pushed the macos-key-remap-menu-equivalents branch from e972523 to a1f622e Compare May 7, 2026 18:03
@knu knu changed the title macos: remap menu key equivalents macos: apply key-remap to menu key equivalents May 7, 2026
@knu
Copy link
Copy Markdown
Contributor Author

knu commented May 7, 2026

@bo2themax Thanks for guiding me in this direction!

I updated the implementation to apply key-remap in Config.keyEventIsBinding and to expose remapped physical menu key equivalents through CApi.config_trigger_, without changing the AppKit/apprt event flow.

I also tested this manually on macOS with:

  • macos-option-as-alt = left
  • key-remap = left_alt=command
  • key-remap = command=left_alt

With that config, the menu item for New Window displays ⌥N, and pressing ⌥N triggers New Window, while ⌘N is sent to the terminal as ESC N.

@knu knu requested a review from bo2themax May 7, 2026 18:12
@knu
Copy link
Copy Markdown
Contributor Author

knu commented May 15, 2026

@bo2themax How about this?

@bo2themax
Copy link
Copy Markdown
Member

@bo2themax How about this?

It looks good to me in general, but we should wait for terminal maintainers to review this when they're available, since zig isn't really my profession here.

Be patient plz, you can use your local build for now with -Doptimize=ReleaseFast

@knu
Copy link
Copy Markdown
Contributor Author

knu commented May 15, 2026

@bo2themax So, can I assume that the issue you marked as “Changes requested” has been resolved? If so, I’d like to wait for other reviewers to review this as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants