mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00

A common issue for US-centric users of a terminal is that the "option" key on macOS is not treated as the "alt" key in the terminal. ## Background macOS does not have an "alt" key, but instead has an "option" key. The "option" key is used for a variety of purposes, but the troublesome behavior for some (and expected/desired behavior for others) is that it is used to input special characters. For example, on a US standard layout, `option-b` inputs `∫`. This is not a typically desired character when using a terminal and most users will instead expect that `option-b` maps to `alt-b` for keybinding purposes with whatever shell, TUI, editor, etc. they're using. On non-US layouts, the "option" key is a critical modifier key for inputting certain characters in the same way "shift" is a critical modifier key for inputting certain characters on US layouts. We previously tried to change the default for `macos-option-as-alt` to `left` (so that the left option key behaves as alt) because I had the wrong assumption that international users always used the right option key with terminals or were used to this. But very quickly beta users with different layouts (such as German, I believe) noted that this is not the case and broke their idiomatic input behavior. This behavior was therefore reverted. ## Solution This confusing behavior happened frequently enough that I decided to implement the more complex behavior in this commit. The new behavior is that when a US layout is active, `macos-option-as-alt` defaults to true if it is unset. When a non-US layout is active, `macos-option-as-alt` defaults to false if it is unset. This happens live as users change their keyboard layout. **An important goal of Ghostty is to have zero-config defaults** that satisfy the majority of users. Fiddling with configurations is -- for most -- an annoying task and software that works well enough out of the box is delightful. Based on surveying beta users, I believe this commit will result in less configuration for the majority of users. ## Other Terminals This behavior is unique amongst terminals as far as I know. Terminal.app, Kitty, iTerm2, Alacritty (I stopped checking there) all default to the default macOS behavior (option is option and special characters are inputted). All of the aforementioned terminals have a setting to change this behavior, identical to Ghostty (or, Ghostty identical to them perhaps since they all predate Ghostty). I couldn't find any history where users requested the behavior of defaulting this to something else for US based keyboards. That's interesting since this has come up so frequently during the Ghostty beta!
40 lines
1.4 KiB
Zig
40 lines
1.4 KiB
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
|
|
const mouse = @import("input/mouse.zig");
|
|
const key = @import("input/key.zig");
|
|
const keyboard = @import("input/keyboard.zig");
|
|
|
|
pub const function_keys = @import("input/function_keys.zig");
|
|
pub const keycodes = @import("input/keycodes.zig");
|
|
pub const kitty = @import("input/kitty.zig");
|
|
|
|
pub const ctrlOrSuper = key.ctrlOrSuper;
|
|
pub const Action = key.Action;
|
|
pub const Binding = @import("input/Binding.zig");
|
|
pub const Link = @import("input/Link.zig");
|
|
pub const Key = key.Key;
|
|
pub const KeyboardLayout = keyboard.Layout;
|
|
pub const KeyEncoder = @import("input/KeyEncoder.zig");
|
|
pub const KeyEvent = key.KeyEvent;
|
|
pub const InspectorMode = Binding.Action.InspectorMode;
|
|
pub const Mods = key.Mods;
|
|
pub const MouseButton = mouse.Button;
|
|
pub const MouseButtonState = mouse.ButtonState;
|
|
pub const MousePressureStage = mouse.PressureStage;
|
|
pub const ScrollMods = mouse.ScrollMods;
|
|
pub const SplitFocusDirection = Binding.Action.SplitFocusDirection;
|
|
pub const SplitResizeDirection = Binding.Action.SplitResizeDirection;
|
|
pub const Trigger = Binding.Trigger;
|
|
|
|
// Keymap is only available on macOS right now. We could implement it
|
|
// in theory for XKB too on Linux but we don't need it right now.
|
|
pub const Keymap = switch (builtin.os.tag) {
|
|
.macos => @import("input/KeymapDarwin.zig"),
|
|
else => @import("input/KeymapNoop.zig"),
|
|
};
|
|
|
|
test {
|
|
std.testing.refAllDecls(@This());
|
|
}
|