mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
Merge pull request #104 from mitchellh/linux-keys
Use proper Linux default keybindings for already configured keys
This commit is contained in:
264
src/config.zig
264
src/config.zig
@ -182,22 +182,16 @@ pub const Config = struct {
|
|||||||
// Add our default keybindings
|
// Add our default keybindings
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .c, .mods = .{ .super = true } },
|
.{ .key = .c, .mods = ctrlOrSuper(.{}) },
|
||||||
.{ .copy_to_clipboard = {} },
|
.{ .copy_to_clipboard = {} },
|
||||||
);
|
);
|
||||||
|
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .v, .mods = .{ .super = true } },
|
.{ .key = .v, .mods = ctrlOrSuper(.{}) },
|
||||||
.{ .paste_from_clipboard = {} },
|
.{ .paste_from_clipboard = {} },
|
||||||
);
|
);
|
||||||
|
|
||||||
try result.keybind.set.put(
|
// Some control keys
|
||||||
alloc,
|
|
||||||
.{ .key = .k, .mods = .{ .super = true } },
|
|
||||||
.{ .clear_screen = {} },
|
|
||||||
);
|
|
||||||
|
|
||||||
try result.keybind.set.put(alloc, .{ .key = .up }, .{ .cursor_key = .{
|
try result.keybind.set.put(alloc, .{ .key = .up }, .{ .cursor_key = .{
|
||||||
.normal = "\x1b[A",
|
.normal = "\x1b[A",
|
||||||
.application = "\x1bOA",
|
.application = "\x1bOA",
|
||||||
@ -249,17 +243,17 @@ pub const Config = struct {
|
|||||||
// Fonts
|
// Fonts
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .equal, .mods = .{ .super = true } },
|
.{ .key = .equal, .mods = ctrlOrSuper(.{}) },
|
||||||
.{ .increase_font_size = 1 },
|
.{ .increase_font_size = 1 },
|
||||||
);
|
);
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .minus, .mods = .{ .super = true } },
|
.{ .key = .minus, .mods = ctrlOrSuper(.{}) },
|
||||||
.{ .decrease_font_size = 1 },
|
.{ .decrease_font_size = 1 },
|
||||||
);
|
);
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .zero, .mods = .{ .super = true } },
|
.{ .key = .zero, .mods = ctrlOrSuper(.{}) },
|
||||||
.{ .reset_font_size = {} },
|
.{ .reset_font_size = {} },
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -271,100 +265,204 @@ pub const Config = struct {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Windowing
|
// Windowing
|
||||||
try result.keybind.set.put(
|
if (comptime !builtin.target.isDarwin()) {
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .n, .mods = .{ .super = true } },
|
alloc,
|
||||||
.{ .new_window = {} },
|
.{ .key = .n, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
);
|
.{ .new_window = {} },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .w, .mods = .{ .super = true } },
|
alloc,
|
||||||
.{ .close_surface = {} },
|
.{ .key = .w, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
);
|
.{ .close_surface = {} },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .w, .mods = .{ .super = true, .shift = true } },
|
alloc,
|
||||||
.{ .close_window = {} },
|
.{ .key = .f4, .mods = .{ .alt = true } },
|
||||||
);
|
.{ .close_window = {} },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .t, .mods = .{ .super = true } },
|
alloc,
|
||||||
.{ .new_tab = {} },
|
.{ .key = .t, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
);
|
.{ .new_tab = {} },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .left_bracket, .mods = .{ .super = true, .shift = true } },
|
alloc,
|
||||||
.{ .previous_tab = {} },
|
.{ .key = .left, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
);
|
.{ .previous_tab = {} },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .right_bracket, .mods = .{ .super = true, .shift = true } },
|
alloc,
|
||||||
.{ .next_tab = {} },
|
.{ .key = .right, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
);
|
.{ .next_tab = {} },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .d, .mods = .{ .super = true } },
|
alloc,
|
||||||
.{ .new_split = .right },
|
.{ .key = .d, .mods = .{ .ctrl = true } },
|
||||||
);
|
.{ .new_split = .right },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .d, .mods = .{ .super = true, .shift = true } },
|
alloc,
|
||||||
.{ .new_split = .down },
|
.{ .key = .d, .mods = .{ .ctrl = true, .shift = true } },
|
||||||
);
|
.{ .new_split = .down },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .left_bracket, .mods = .{ .super = true } },
|
alloc,
|
||||||
.{ .goto_split = .previous },
|
.{ .key = .left_bracket, .mods = .{ .ctrl = true } },
|
||||||
);
|
.{ .goto_split = .previous },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .right_bracket, .mods = .{ .super = true } },
|
alloc,
|
||||||
.{ .goto_split = .next },
|
.{ .key = .right_bracket, .mods = .{ .ctrl = true } },
|
||||||
);
|
.{ .goto_split = .next },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .up, .mods = .{ .super = true, .alt = true } },
|
alloc,
|
||||||
.{ .goto_split = .top },
|
.{ .key = .up, .mods = .{ .ctrl = true, .alt = true } },
|
||||||
);
|
.{ .goto_split = .top },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .down, .mods = .{ .super = true, .alt = true } },
|
alloc,
|
||||||
.{ .goto_split = .bottom },
|
.{ .key = .down, .mods = .{ .ctrl = true, .alt = true } },
|
||||||
);
|
.{ .goto_split = .bottom },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .left, .mods = .{ .super = true, .alt = true } },
|
alloc,
|
||||||
.{ .goto_split = .left },
|
.{ .key = .left, .mods = .{ .ctrl = true, .alt = true } },
|
||||||
);
|
.{ .goto_split = .left },
|
||||||
try result.keybind.set.put(
|
);
|
||||||
alloc,
|
try result.keybind.set.put(
|
||||||
.{ .key = .right, .mods = .{ .super = true, .alt = true } },
|
alloc,
|
||||||
.{ .goto_split = .right },
|
.{ .key = .right, .mods = .{ .ctrl = true, .alt = true } },
|
||||||
);
|
.{ .goto_split = .right },
|
||||||
|
);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
// Cmd+N for goto tab N
|
// Cmd+N for goto tab N
|
||||||
const start = @enumToInt(inputpkg.Key.one);
|
const start = @enumToInt(inputpkg.Key.one);
|
||||||
const end = @enumToInt(inputpkg.Key.nine);
|
const end = @enumToInt(inputpkg.Key.nine);
|
||||||
var i: usize = start;
|
var i: usize = start;
|
||||||
while (i <= end) : (i += 1) {
|
while (i <= end) : (i += 1) {
|
||||||
|
// On macOS we default to super but everywhere else
|
||||||
|
// is alt.
|
||||||
|
const mods: inputpkg.Mods = if (builtin.target.isDarwin())
|
||||||
|
.{ .super = true }
|
||||||
|
else
|
||||||
|
.{ .alt = true };
|
||||||
|
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = @intToEnum(inputpkg.Key, i), .mods = .{ .super = true } },
|
.{ .key = @intToEnum(inputpkg.Key, i), .mods = mods },
|
||||||
.{ .goto_tab = (i - start) + 1 },
|
.{ .goto_tab = (i - start) + 1 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mac-specific keyboard bindings.
|
||||||
if (comptime builtin.target.isDarwin()) {
|
if (comptime builtin.target.isDarwin()) {
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
alloc,
|
alloc,
|
||||||
.{ .key = .q, .mods = .{ .super = true } },
|
.{ .key = .q, .mods = .{ .super = true } },
|
||||||
.{ .quit = {} },
|
.{ .quit = {} },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .k, .mods = .{ .super = true } },
|
||||||
|
.{ .clear_screen = {} },
|
||||||
|
);
|
||||||
|
|
||||||
|
// Mac windowing
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .n, .mods = .{ .super = true } },
|
||||||
|
.{ .new_window = {} },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .w, .mods = .{ .super = true } },
|
||||||
|
.{ .close_surface = {} },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .w, .mods = .{ .super = true, .shift = true } },
|
||||||
|
.{ .close_window = {} },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .t, .mods = .{ .super = true } },
|
||||||
|
.{ .new_tab = {} },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .left_bracket, .mods = .{ .super = true, .shift = true } },
|
||||||
|
.{ .previous_tab = {} },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .right_bracket, .mods = .{ .super = true, .shift = true } },
|
||||||
|
.{ .next_tab = {} },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .d, .mods = .{ .super = true } },
|
||||||
|
.{ .new_split = .right },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .d, .mods = .{ .super = true, .shift = true } },
|
||||||
|
.{ .new_split = .down },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .left_bracket, .mods = .{ .super = true } },
|
||||||
|
.{ .goto_split = .previous },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .right_bracket, .mods = .{ .super = true } },
|
||||||
|
.{ .goto_split = .next },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .up, .mods = .{ .super = true, .alt = true } },
|
||||||
|
.{ .goto_split = .top },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .down, .mods = .{ .super = true, .alt = true } },
|
||||||
|
.{ .goto_split = .bottom },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .left, .mods = .{ .super = true, .alt = true } },
|
||||||
|
.{ .goto_split = .left },
|
||||||
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .right, .mods = .{ .super = true, .alt = true } },
|
||||||
|
.{ .goto_split = .right },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This sets either "ctrl" or "super" to true (but not both)
|
||||||
|
/// on mods depending on if the build target is Mac or not. On
|
||||||
|
/// Mac, we default to super (i.e. super+c for copy) and on
|
||||||
|
/// non-Mac we default to ctrl (i.e. ctrl+c for copy).
|
||||||
|
fn ctrlOrSuper(mods: inputpkg.Mods) inputpkg.Mods {
|
||||||
|
var copy = mods;
|
||||||
|
if (comptime builtin.target.isDarwin()) {
|
||||||
|
copy.super = true;
|
||||||
|
} else {
|
||||||
|
copy.ctrl = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
/// Load the configuration from the default file locations. Currently,
|
/// Load the configuration from the default file locations. Currently,
|
||||||
/// this loads from $XDG_CONFIG_HOME/ghostty/config.
|
/// this loads from $XDG_CONFIG_HOME/ghostty/config.
|
||||||
pub fn loadDefaultFiles(self: *Config, alloc: Allocator) !void {
|
pub fn loadDefaultFiles(self: *Config, alloc: Allocator) !void {
|
||||||
|
Reference in New Issue
Block a user