gtk: backport #6877 to 1.1.2

This commit is contained in:
Jeffrey C. Ollie
2025-03-23 10:11:34 -05:00
parent 52a5069dec
commit ba2e18287d
3 changed files with 26 additions and 30 deletions

View File

@ -223,19 +223,6 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
_ = internal_os.setenv("GDK_DISABLE", value[0 .. value.len - 1 :0]); _ = internal_os.setenv("GDK_DISABLE", value[0 .. value.len - 1 :0]);
} }
if (version.runtimeAtLeast(4, 14, 0)) {
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(); c.gtk_init();
const display: *c.GdkDisplay = c.gdk_display_get_default() orelse { const display: *c.GdkDisplay = c.gdk_display_get_default() orelse {
// I'm unsure of any scenario where this happens. Because we don't // I'm unsure of any scenario where this happens. Because we don't

View File

@ -1325,14 +1325,37 @@ fn gtkRealize(area: *c.GtkGLArea, ud: ?*anyopaque) callconv(.C) void {
/// This is called when the underlying OpenGL resources must be released. /// This is called when the underlying OpenGL resources must be released.
/// This is usually due to the OpenGL area changing GDK surfaces. /// This is usually due to the OpenGL area changing GDK surfaces.
fn gtkUnrealize(area: *c.GtkGLArea, ud: ?*anyopaque) callconv(.C) void { fn gtkUnrealize(area: *c.GtkGLArea, ud: ?*anyopaque) callconv(.C) void {
_ = area;
log.debug("gl surface unrealized", .{}); log.debug("gl surface unrealized", .{});
const self = userdataSelf(ud.?); const self = userdataSelf(ud.?);
self.core_surface.renderer.displayUnrealized();
// See gtkRealize for why we do this here. // See gtkRealize for why we do this here.
c.gtk_im_context_set_client_widget(self.im_context, null); c.gtk_im_context_set_client_widget(self.im_context, null);
// There is no guarantee that our GLArea context is current
// when unrealize is emitted, so we need to make it current.
c.gtk_gl_area_make_current(area);
if (c.gtk_gl_area_get_error(area)) |err| {
// I don't know a scenario this can happen, but it means
// we probably leaked memory because displayUnrealized
// below frees resources that aren't specifically OpenGL
// related. I didn't make the OpenGL renderer handle this
// scenario because I don't know if its even possible
// under valid circumstances, so let's log.
if (err.*.message) |message| {
log.warn(
"gl_area_make_current failed in unrealize msg={s}",
.{message},
);
} else {
log.warn(
"gl_area_make_current failed in unrealize msg=(no message)",
.{},
);
}
log.warn("OpenGL resources and memory likely leaked", .{});
return;
}
self.core_surface.renderer.displayUnrealized();
} }
/// render signal /// render signal

View File

@ -2089,14 +2089,6 @@ keybind: Keybinds = .{},
/// debug builds, `false` for all others. /// debug builds, `false` for all others.
@"gtk-opengl-debug": bool = builtin.mode == .Debug, @"gtk-opengl-debug": bool = builtin.mode == .Debug,
/// 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: /// 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 /// each new `ghostty` process launched will result in a new window if there is
/// already a running process. /// already a running process.
@ -6339,12 +6331,6 @@ pub const WindowPadding = struct {
} }
}; };
/// See the `gtk-gsk-renderer` config.
pub const GtkGskRenderer = enum {
default,
opengl,
};
test "parse duration" { test "parse duration" {
inline for (Duration.units) |unit| { inline for (Duration.units) |unit| {
var buf: [16]u8 = undefined; var buf: [16]u8 = undefined;