apprt/gtk: button to toggle inspector

This commit is contained in:
Mitchell Hashimoto
2023-10-20 08:47:18 -07:00
parent 199e1cae29
commit 6a50a938d6
2 changed files with 16 additions and 0 deletions

View File

@ -216,6 +216,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.reload_config", .{ .reload_config = {} }); try self.syncActionAccelerator("app.reload_config", .{ .reload_config = {} });
try self.syncActionAccelerator("app.toggle_inspector", .{ .inspector = .toggle });
try self.syncActionAccelerator("win.close", .{ .close_surface = {} }); try self.syncActionAccelerator("win.close", .{ .close_surface = {} });
try self.syncActionAccelerator("win.new_window", .{ .new_window = {} }); try self.syncActionAccelerator("win.new_window", .{ .new_window = {} });
try self.syncActionAccelerator("win.new_tab", .{ .new_tab = {} }); try self.syncActionAccelerator("win.new_tab", .{ .new_tab = {} });
@ -459,6 +460,7 @@ fn initMenu(self: *App) void {
const section = c.g_menu_new(); const section = c.g_menu_new();
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, "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

@ -149,6 +149,7 @@ fn initActions(self: *Window) void {
.{ "close", &gtkActionClose }, .{ "close", &gtkActionClose },
.{ "new_window", &gtkActionNewWindow }, .{ "new_window", &gtkActionNewWindow },
.{ "new_tab", &gtkActionNewTab }, .{ "new_tab", &gtkActionNewTab },
.{ "toggle_inspector", &gtkActionToggleInspector },
}; };
inline for (actions) |entry| { inline for (actions) |entry| {
@ -546,6 +547,19 @@ fn gtkActionNewTab(
}; };
} }
fn gtkActionToggleInspector(
_: *c.GSimpleAction,
_: *c.GVariant,
ud: ?*anyopaque,
) callconv(.C) void {
const self: *Window = @ptrCast(@alignCast(ud orelse return));
const surface = self.actionSurface() orelse return;
_ = surface.performBindingAction(.{ .inspector = .toggle }) catch |err| {
log.warn("error performing binding action error={}", .{err});
return;
};
}
/// Returns the surface to use for an action. /// Returns the surface to use for an action.
fn actionSurface(self: *Window) ?*CoreSurface { fn actionSurface(self: *Window) ?*CoreSurface {
const page_idx = c.gtk_notebook_get_current_page(self.notebook); const page_idx = c.gtk_notebook_get_current_page(self.notebook);