From 7711f6b5b695cd8a9dd54804255e7e50eca6eadb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 21 Jul 2025 09:48:43 -0700 Subject: [PATCH] apprt/gtk-ng: setup basic css resources --- src/apprt/gtk-ng/build/gresource.zig | 46 +++++++++++++++++++++++++- src/apprt/gtk-ng/class/application.zig | 7 +++- src/apprt/gtk-ng/css/style.css | 9 +++++ src/apprt/gtk-ng/ui/1.2/surface.blp | 3 ++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/apprt/gtk-ng/css/style.css diff --git a/src/apprt/gtk-ng/build/gresource.zig b/src/apprt/gtk-ng/build/gresource.zig index dd9bf7de9..4bd42a742 100644 --- a/src/apprt/gtk-ng/build/gresource.zig +++ b/src/apprt/gtk-ng/build/gresource.zig @@ -16,6 +16,9 @@ pub const app_id = "com.mitchellh.ghostty"; /// minimum adwaita version. pub const ui_path = "src/apprt/gtk-ng/ui"; +/// The path to the CSS files. +pub const css_path = "src/apprt/gtk-ng/css"; + /// The possible icon sizes we'll embed into the gresource file. /// If any size doesn't exist then it will be an error. We could /// infer this completely from available files but we wouldn't be @@ -36,6 +39,14 @@ pub const blueprints: []const Blueprint = &.{ .{ .major = 1, .minor = 5, .name = "window" }, }; +/// CSS files in css_path +pub const css = [_][]const u8{ + "style.css", + // "style-dark.css", + // "style-hc.css", + // "style-hc-dark.css", +}; + pub const Blueprint = struct { major: u16, minor: u16, @@ -45,7 +56,7 @@ pub const Blueprint = struct { /// The list of filepaths that we depend on. Used for the build /// system to have proper caching. pub const file_inputs = deps: { - const total = (icon_sizes.len * 2) + blueprints.len; + const total = (icon_sizes.len * 2) + blueprints.len + css.len; var deps: [total][]const u8 = undefined; var index: usize = 0; for (icon_sizes) |size| { @@ -62,6 +73,10 @@ pub const file_inputs = deps: { }); index += 1; } + for (css) |name| { + deps[index] = std.fmt.comptimePrint("{s}/{s}", .{ css_path, name }); + index += 1; + } break :deps deps; }; @@ -120,6 +135,7 @@ pub fn main() !void { \\ ); + try genRoot(writer); try genIcons(writer); try genUi(alloc, writer, &ui_files); @@ -173,6 +189,34 @@ fn genIcons(writer: anytype) !void { ); } +/// Generate the resources at the root prefix. +fn genRoot(writer: anytype) !void { + try writer.print( + \\ + \\ + , .{prefix}); + + const cwd = std.fs.cwd(); + inline for (css) |name| { + const source = std.fmt.comptimePrint( + "{s}/{s}", + .{ css_path, name }, + ); + try cwd.access(source, .{}); + try writer.print( + \\ {s} + \\ + , + .{ name, source }, + ); + } + + try writer.writeAll( + \\ + \\ + ); +} + /// Generate all the UI resources. This works by looking up all the /// blueprint files in `${ui_path}/{major}.{minor}/{name}.blp` and /// assuming these will be diff --git a/src/apprt/gtk-ng/class/application.zig b/src/apprt/gtk-ng/class/application.zig index 22a27c57d..b7220c375 100644 --- a/src/apprt/gtk-ng/class/application.zig +++ b/src/apprt/gtk-ng/class/application.zig @@ -484,6 +484,8 @@ pub const Application = extern struct { .set_title => Action.setTitle(target, value), + .show_gtk_inspector => Action.showGtkInspector(), + // Unimplemented but todo on gtk-ng branch .close_window, .toggle_maximize, @@ -499,7 +501,6 @@ pub const Application = extern struct { .open_config, .reload_config, .inspector, - .show_gtk_inspector, .desktop_notification, .present_terminal, .initial_size, @@ -1115,6 +1116,10 @@ const Action = struct { }, } } + + pub fn showGtkInspector() void { + gtk.Window.setInteractiveDebugging(@intFromBool(true)); + } }; /// This sets various GTK-related environment variables as necessary diff --git a/src/apprt/gtk-ng/css/style.css b/src/apprt/gtk-ng/css/style.css new file mode 100644 index 000000000..a158d790e --- /dev/null +++ b/src/apprt/gtk-ng/css/style.css @@ -0,0 +1,9 @@ +/* Application CSS that applies to the entire application. + * + * This is automatically loaded by AdwApplication: + * https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.3/styles-and-appearance.html#custom-styles + */ + +label { + color: red; +} diff --git a/src/apprt/gtk-ng/ui/1.2/surface.blp b/src/apprt/gtk-ng/ui/1.2/surface.blp index a91206803..41ab0ee1e 100644 --- a/src/apprt/gtk-ng/ui/1.2/surface.blp +++ b/src/apprt/gtk-ng/ui/1.2/surface.blp @@ -3,6 +3,9 @@ using Adw 1; template $GhosttySurface: Adw.Bin { Overlay { + focusable: false; + focus-on-click: false; + GLArea gl_area { hexpand: true; vexpand: true;