apprt/gtk: about window

This commit is contained in:
Mitchell Hashimoto
2023-09-18 15:16:35 -07:00
parent bf665b7c63
commit f3662354e5
3 changed files with 37 additions and 2 deletions

View File

@ -206,7 +206,11 @@ pub fn build(b: *std.Build) !void {
const exe_options = b.addOptions();
exe_options.addOption(std.SemanticVersion, "app_version", version);
exe_options.addOption([]const u8, "app_version_string", b.fmt("{}", .{version}));
exe_options.addOption([:0]const u8, "app_version_string", try std.fmt.allocPrintZ(
b.allocator,
"{}",
.{version},
));
exe_options.addOption(bool, "tracy_enabled", tracy);
exe_options.addOption(bool, "flatpak", flatpak);
exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime);

View File

@ -448,7 +448,13 @@ fn initMenu(self: *App) void {
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "Close Window", "win.close");
c.g_menu_append(section, "Quit Ghostty", "app.quit");
}
{
const section = c.g_menu_new();
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "About Ghostty", "win.about");
}
// {

View File

@ -3,6 +3,7 @@ const Window = @This();
const std = @import("std");
const builtin = @import("builtin");
const build_config = @import("../../build_config.zig");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const configpkg = @import("../../config.zig");
@ -162,6 +163,7 @@ pub fn init(self: *Window, app: *App) !void {
/// here. The string name binds them.
fn initActions(self: *Window) void {
const actions = .{
.{ "about", &gtkActionAbout },
.{ "close", &gtkActionClose },
.{ "new_window", &gtkActionNewWindow },
.{ "new_tab", &gtkActionNewTab },
@ -486,6 +488,29 @@ fn getNotebookPageIndex(page: *c.GtkNotebookPage) c_int {
return c.g_value_get_int(&value);
}
fn gtkActionAbout(
_: *c.GSimpleAction,
_: *c.GVariant,
ud: ?*anyopaque,
) callconv(.C) void {
const self: *Window = @ptrCast(@alignCast(ud orelse return));
c.gtk_show_about_dialog(
self.window,
"program-name",
"Ghostty",
"logo-icon-name",
"com.mitchellh.ghostty",
"title",
"About Ghostty",
"version",
build_config.version_string.ptr,
"website",
"https://github.com/mitchellh/ghostty",
@as(?*anyopaque, null),
);
}
fn gtkActionClose(
_: *c.GSimpleAction,
_: *c.GVariant,