Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const DerivedConfig = struct {
mouse_shift_capture: configpkg.MouseShiftCapture,
macos_non_native_fullscreen: configpkg.NonNativeFullscreen,
macos_option_as_alt: ?input.OptionAsAlt,
macos_option_as_alt_original: ?input.OptionAsAlt,
Copy link
Author

Choose a reason for hiding this comment

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

Happy to learn if there is a better way to store the "original" state before the user triggers the binding action. 😄

selection_clear_on_copy: bool,
selection_clear_on_typing: bool,
vt_kam_allowed: bool,
Expand Down Expand Up @@ -349,6 +350,7 @@ const DerivedConfig = struct {
.mouse_shift_capture = config.@"mouse-shift-capture",
.macos_non_native_fullscreen = config.@"macos-non-native-fullscreen",
.macos_option_as_alt = config.@"macos-option-as-alt",
.macos_option_as_alt_original = config.@"macos-option-as-alt",
.selection_clear_on_copy = config.@"selection-clear-on-copy",
.selection_clear_on_typing = config.@"selection-clear-on-typing",
.vt_kam_allowed = config.@"vt-kam-allowed",
Expand Down Expand Up @@ -5170,6 +5172,22 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
{},
),

.toggle_macos_option_as_alt => {
const current = self.config.macos_option_as_alt orelse .false;

switch (current) {
.false => {
// Toggle ON the behavior by restoring from the saved state.
self.config.macos_option_as_alt = self.config.macos_option_as_alt_original orelse .true;
},
.true, .left, .right => {
// Toggle OFF and save the current value in the surface state.
self.config.macos_option_as_alt_original = current;
self.config.macos_option_as_alt = .false;
},
}
},

.show_on_screen_keyboard => return try self.rt_app.performAction(
.{ .surface = self },
.show_on_screen_keyboard,
Expand Down
6 changes: 6 additions & 0 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6425,6 +6425,12 @@ pub const Keybinds = struct {
.{ .key = .{ .physical = .arrow_right }, .mods = .{ .alt = true } },
.{ .esc = "f" },
);
// Toggle option-as-alt similar to Terminal.app.
try self.set.put(
alloc,
.{ .key = .{ .unicode = 'o' }, .mods = .{ .super = true, .alt = true } },
.toggle_macos_option_as_alt,
);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/input/Binding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,15 @@ pub const Action = union(enum) {
/// version can be found by running `ghostty +version`.
toggle_command_palette,

/// Toggle the macos-option-as-alt behavior.
///
/// When toggled off, sets the macos-option-as-alt to false.
/// When toggled on, restores to the original configured value (true, left,
/// or right). It defauls to true if none was set.
///
/// Only available on macOS.
toggle_macos_option_as_alt,

/// Toggle the quick terminal.
///
/// The quick terminal, also known as the "Quake-style" or drop-down
Expand Down Expand Up @@ -1188,6 +1197,7 @@ pub const Action = union(enum) {
.toggle_secure_input,
.toggle_mouse_reporting,
.toggle_command_palette,
.toggle_macos_option_as_alt,
.show_on_screen_keyboard,
.reset_window_size,
.crash,
Expand Down
6 changes: 6 additions & 0 deletions src/input/command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ fn actionCommands(action: Action.Key) []const Command {
.description = "Toggle whether mouse events are reported to terminal applications.",
}},

.toggle_macos_option_as_alt => comptime &.{.{
.action = .toggle_macos_option_as_alt,
.title = "Toggle Option as Alt on macOS",
.description = "Toggle whether the macOS Option keys act as Alt",
}},

.check_for_updates => comptime &.{.{
.action = .check_for_updates,
.title = "Check for Updates",
Expand Down