Keybind features: System-global keybindings and target-all-terminal keybindings #2299
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 introduces two distinct but related features:
System-global keybindings. These are notated with the prefix
global:
. These keybindings will work globally on the system, regardless of what application is focused. This currently only works for macOS and requires accessibility privileges. More on this UX later.Target-all-terminal keybindings. These are notated with the prefix
all:
. These keybindings target all running terminal surfaces (windows, tabs, splits) in the Ghostty process. This can be used for example to implementincrease_font_size
across the entire application:keybind = all:cmd+plus=increase_font_size:1
. This works on macOS and Linux.The documentation on the various edge cases and details about these new features is immense. Please see
src/config/Config.zig
since I think this will answer most questions. If there are any improvements to docs I can make please suggest them.macOS Accessibility Privilege
The
global:
keybind feature requires the accessibility privilege on macOS. Ghostty will automatically request this whenever the configuration contains anyglobal:
key binds. If there are noglobal:
bindings presenting the configuration, Ghostty will not request or use the accessibility privilege.Note that if a user has already denied it, macOS will not pop up the request prompt again. There is currently no UX to detect this but that's something I'd love to see improved in the future. Detection is trivial, but the UX around the detection requires much more thought.
You can see a demo of this in the video below.
Demo: System-Global Keybinds
We use
keybind = global:cmd+period=new_window
to create a keybind that creates and focuses a new Ghostty window regardless of what application is in focus. This can mimic a "quick terminal" type feature:CleanShot.2024-09-24.at.18.45.11.mp4
Demo: Target-all-terminal Binding
We use
keybind = all:cmd+j=text:hello
to write text in all terminals.CleanShot.2024-09-24.at.18.47.04.mp4