Add 'Open Config' menu to the GTK runtime and synchronize config-related keybindings across platforms.

This commit is contained in:
Jeffrey C. Ollie
2024-01-04 23:29:33 -06:00
parent 6c529c92f2
commit 698954031a
2 changed files with 22 additions and 11 deletions

View File

@ -293,6 +293,7 @@ fn updateConfigErrors(self: *App) !void {
fn syncActionAccelerators(self: *App) !void { fn syncActionAccelerators(self: *App) !void {
try self.syncActionAccelerator("app.quit", .{ .quit = {} }); try self.syncActionAccelerator("app.quit", .{ .quit = {} });
try self.syncActionAccelerator("app.open_config", .{ .open_config = {} });
try self.syncActionAccelerator("app.reload_config", .{ .reload_config = {} }); try self.syncActionAccelerator("app.reload_config", .{ .reload_config = {} });
try self.syncActionAccelerator("app.toggle_inspector", .{ .inspector = .toggle }); try self.syncActionAccelerator("app.toggle_inspector", .{ .inspector = .toggle });
try self.syncActionAccelerator("win.close", .{ .close_surface = {} }); try self.syncActionAccelerator("win.close", .{ .close_surface = {} });
@ -479,6 +480,17 @@ fn gtkActivate(app: *c.GtkApplication, ud: ?*anyopaque) callconv(.C) void {
}, .{ .forever = {} }); }, .{ .forever = {} });
} }
fn gtkActionOpenConfig(
_: *c.GSimpleAction,
_: *c.GVariant,
ud: ?*anyopaque,
) callconv(.C) void {
const self: *App = @ptrCast(@alignCast(ud orelse return));
_ = self.core_app.mailbox.push(.{
.open_config = {},
}, .{ .forever = {} });
}
fn gtkActionReloadConfig( fn gtkActionReloadConfig(
_: *c.GSimpleAction, _: *c.GSimpleAction,
_: *c.GVariant, _: *c.GVariant,
@ -507,6 +519,7 @@ fn gtkActionQuit(
fn initActions(self: *App) void { fn initActions(self: *App) void {
const actions = .{ const actions = .{
.{ "quit", &gtkActionQuit }, .{ "quit", &gtkActionQuit },
.{ "open_config", &gtkActionOpenConfig },
.{ "reload_config", &gtkActionReloadConfig }, .{ "reload_config", &gtkActionReloadConfig },
}; };
@ -545,6 +558,7 @@ fn initMenu(self: *App) void {
defer c.g_object_unref(section); defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section))); c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "Terminal Inspector", "win.toggle_inspector"); c.g_menu_append(section, "Terminal Inspector", "win.toggle_inspector");
c.g_menu_append(section, "Open Configuration", "app.open_config");
c.g_menu_append(section, "Reload Configuration", "app.reload_config"); c.g_menu_append(section, "Reload Configuration", "app.reload_config");
c.g_menu_append(section, "About Ghostty", "win.about"); c.g_menu_append(section, "About Ghostty", "win.about");
} }

View File

@ -946,11 +946,18 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
const alloc = result._arena.?.allocator(); const alloc = result._arena.?.allocator();
// Add our default keybindings // Add our default keybindings
// keybinds for opening and reloading config
try result.keybind.set.put( try result.keybind.set.put(
alloc, alloc,
.{ .key = .space, .mods = .{ .super = true, .alt = true, .ctrl = true } }, .{ .key = .comma, .mods = inputpkg.ctrlOrSuper(.{ .shift = true }) },
.{ .reload_config = {} }, .{ .reload_config = {} },
); );
try result.keybind.set.put(
alloc,
.{ .key = .comma, .mods = inputpkg.ctrlOrSuper(.{}) },
.{ .open_config = {} },
);
{ {
// On macOS we default to super but Linux ctrl+shift since // On macOS we default to super but Linux ctrl+shift since
@ -1210,16 +1217,6 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
.{ .key = .q, .mods = .{ .super = true } }, .{ .key = .q, .mods = .{ .super = true } },
.{ .quit = {} }, .{ .quit = {} },
); );
try result.keybind.set.put(
alloc,
.{ .key = .comma, .mods = .{ .super = true, .shift = true } },
.{ .reload_config = {} },
);
try result.keybind.set.put(
alloc,
.{ .key = .comma, .mods = .{ .super = true } },
.{ .open_config = {} },
);
try result.keybind.set.put( try result.keybind.set.put(
alloc, alloc,
.{ .key = .k, .mods = .{ .super = true } }, .{ .key = .k, .mods = .{ .super = true } },