gtk: add config option to control GSK_RENDERER env var

This commit is contained in:
Jeffrey C. Ollie
2025-01-06 19:27:53 -06:00
parent 13e96c7ec8
commit 06a57842af
2 changed files with 24 additions and 3 deletions

View File

@ -209,9 +209,16 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
}
if (version.runtimeAtLeast(4, 14, 0)) {
// We need to export GSK_RENDERER to opengl because GTK uses ngl by
// default after 4.14
_ = internal_os.setenv("GSK_RENDERER", "opengl");
switch (config.@"gtk-gsk-renderer") {
.default => {},
else => |renderer| {
// Force the GSK renderer to a specific value. After GTK 4.14 the
// `ngl` renderer is used by default which causes artifacts when
// used with Ghostty so it should be avoided.
log.warn("setting GSK_RENDERER={s}", .{@tagName(renderer)});
_ = internal_os.setenv("GSK_RENDERER", @tagName(renderer));
},
}
}
c.gtk_init();

View File

@ -1984,6 +1984,14 @@ keybind: Keybinds = .{},
/// - `ReleaseFast`: `false`
@"gtk-opengl-debug": bool = build_config.slow_runtime_safety,
/// After GTK 4.14.0, we need to force the GSK renderer to OpenGL as the default
/// GSK renderer is broken on some systems. If you would like to override
/// that bekavior, set `gtk-gsk-renderer=default` and either use your system's
/// default GSK renderer, or set the GSK_RENDERER environment variable to your
/// renderer of choice before launching Ghostty. This setting has no effect when
/// using versions of GTK earlier than 4.14.0.
@"gtk-gsk-renderer": GtkGskRenderer = .opengl,
/// If `true`, the Ghostty GTK application will run in single-instance mode:
/// each new `ghostty` process launched will result in a new window if there is
/// already a running process.
@ -6167,6 +6175,12 @@ pub const WindowPadding = struct {
}
};
/// See the `gtk-gsk-renderer` config.
pub const GtkGskRenderer = enum {
default,
opengl,
};
test "parse duration" {
inline for (Duration.units) |unit| {
var buf: [16]u8 = undefined;