apprt/gtk-ng: setup basic css resources

This commit is contained in:
Mitchell Hashimoto
2025-07-21 09:48:43 -07:00
parent 55a384e165
commit 7711f6b5b6
4 changed files with 63 additions and 2 deletions

View File

@ -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(
\\ <gresource prefix="{s}">
\\
, .{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(
\\ <file compressed="true" alias="{s}">{s}</file>
\\
,
.{ name, source },
);
}
try writer.writeAll(
\\ </gresource>
\\
);
}
/// 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

View File

@ -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

View File

@ -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;
}

View File

@ -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;