@@ -104,42 +104,6 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
104
104
c .gtk_get_micro_version (),
105
105
});
106
106
107
- // Disabling Vulkan can improve startup times by hundreds of
108
- // milliseconds on some systems. We don't use Vulkan so we can just
109
- // disable it.
110
- if (version .runtimeAtLeast (4 , 16 , 0 )) {
111
- // From gtk 4.16, GDK_DEBUG is split into GDK_DEBUG and GDK_DISABLE.
112
- // For the remainder of "why" see the 4.14 comment below.
113
- _ = internal_os .setenv ("GDK_DISABLE" , "gles-api,vulkan" );
114
- _ = internal_os .setenv ("GDK_DEBUG" , "opengl,gl-no-fractional" );
115
- } else if (version .runtimeAtLeast (4 , 14 , 0 )) {
116
- // We need to export GDK_DEBUG to run on Wayland after GTK 4.14.
117
- // Older versions of GTK do not support these values so it is safe
118
- // to always set this. Forwards versions are uncertain so we'll have to
119
- // reassess...
120
- //
121
- // Upstream issue: https://gitlab.gnome.org/GNOME/gtk/-/issues/6589
122
- //
123
- // Specific details about values:
124
- // - "opengl" - output OpenGL debug information
125
- // - "gl-disable-gles" - disable GLES, Ghostty can't use GLES
126
- // - "vulkan-disable" - disable Vulkan, Ghostty can't use Vulkan
127
- // and initializing a Vulkan context was causing a longer delay
128
- // on some systems.
129
- _ = internal_os .setenv ("GDK_DEBUG" , "opengl,gl-disable-gles,vulkan-disable,gl-no-fractional" );
130
- } else {
131
- // Versions prior to 4.14 are a bit of an unknown for Ghostty. It
132
- // is an environment that isn't tested well and we don't have a
133
- // good understanding of what we may need to do.
134
- _ = internal_os .setenv ("GDK_DEBUG" , "vulkan-disable" );
135
- }
136
-
137
- if (version .runtimeAtLeast (4 , 14 , 0 )) {
138
- // We need to export GSK_RENDERER to opengl because GTK uses ngl by
139
- // default after 4.14
140
- _ = internal_os .setenv ("GSK_RENDERER" , "opengl" );
141
- }
142
-
143
107
// Load our configuration
144
108
var config = try Config .load (core_app .alloc );
145
109
errdefer config .deinit ();
@@ -161,6 +125,104 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
161
125
}
162
126
}
163
127
128
+ var gdk_debug : struct {
129
+ /// output OpenGL debug information
130
+ opengl : bool = false ,
131
+ /// disable GLES, Ghostty can't use GLES
132
+ @"gl-disable-gles" : bool = false ,
133
+ @"gl-no-fractional" : bool = false ,
134
+ /// Disabling Vulkan can improve startup times by hundreds of
135
+ /// milliseconds on some systems. We don't use Vulkan so we can just
136
+ /// disable it.
137
+ @"vulkan-disable" : bool = false ,
138
+ } = .{
139
+ .opengl = config .@"gtk-opengl-debug" ,
140
+ };
141
+
142
+ var gdk_disable : struct {
143
+ @"gles-api" : bool = false ,
144
+ /// Disabling Vulkan can improve startup times by hundreds of
145
+ /// milliseconds on some systems. We don't use Vulkan so we can just
146
+ /// disable it.
147
+ vulkan : bool = false ,
148
+ } = .{};
149
+
150
+ environment : {
151
+ if (version .runtimeAtLeast (4 , 16 , 0 )) {
152
+ // From gtk 4.16, GDK_DEBUG is split into GDK_DEBUG and GDK_DISABLE.
153
+ // For the remainder of "why" see the 4.14 comment below.
154
+ gdk_disable .@"gles-api" = true ;
155
+ gdk_disable .vulkan = true ;
156
+ gdk_debug .@"gl-no-fractional" = true ;
157
+ break :environment ;
158
+ }
159
+ if (version .runtimeAtLeast (4 , 14 , 0 )) {
160
+ // We need to export GDK_DEBUG to run on Wayland after GTK 4.14.
161
+ // Older versions of GTK do not support these values so it is safe
162
+ // to always set this. Forwards versions are uncertain so we'll have
163
+ // to reassess...
164
+ //
165
+ // Upstream issue: https://gitlab.gnome.org/GNOME/gtk/-/issues/6589
166
+ gdk_debug .@"gl-disable-gles" = true ;
167
+ gdk_debug .@"gl-no-fractional" = true ;
168
+ gdk_debug .@"vulkan-disable" = true ;
169
+ break :environment ;
170
+ }
171
+ // Versions prior to 4.14 are a bit of an unknown for Ghostty. It
172
+ // is an environment that isn't tested well and we don't have a
173
+ // good understanding of what we may need to do.
174
+ gdk_debug .@"vulkan-disable" = true ;
175
+ }
176
+
177
+ {
178
+ var buf : [128 ]u8 = undefined ;
179
+ var fmt = std .io .fixedBufferStream (& buf );
180
+ const writer = fmt .writer ();
181
+ var first : bool = true ;
182
+ inline for (@typeInfo (@TypeOf (gdk_debug )).Struct .fields ) | field | {
183
+ if (@field (gdk_debug , field .name )) {
184
+ if (! first ) try writer .writeAll ("," );
185
+ try writer .writeAll (field .name );
186
+ first = false ;
187
+ }
188
+ }
189
+ try writer .writeByte (0 );
190
+ const value = fmt .getWritten ();
191
+ log .warn ("setting GDK_DEBUG={s}" , .{value [0 .. value .len - 1 ]});
192
+ _ = internal_os .setenv ("GDK_DEBUG" , value [0 .. value .len - 1 :0 ]);
193
+ }
194
+
195
+ {
196
+ var buf : [128 ]u8 = undefined ;
197
+ var fmt = std .io .fixedBufferStream (& buf );
198
+ const writer = fmt .writer ();
199
+ var first : bool = true ;
200
+ inline for (@typeInfo (@TypeOf (gdk_disable )).Struct .fields ) | field | {
201
+ if (@field (gdk_disable , field .name )) {
202
+ if (! first ) try writer .writeAll ("," );
203
+ try writer .writeAll (field .name );
204
+ first = false ;
205
+ }
206
+ }
207
+ try writer .writeByte (0 );
208
+ const value = fmt .getWritten ();
209
+ log .warn ("setting GDK_DISABLE={s}" , .{value [0 .. value .len - 1 ]});
210
+ _ = internal_os .setenv ("GDK_DISABLE" , value [0 .. value .len - 1 :0 ]);
211
+ }
212
+
213
+ if (version .runtimeAtLeast (4 , 14 , 0 )) {
214
+ switch (config .@"gtk-gsk-renderer" ) {
215
+ .default = > {},
216
+ else = > | renderer | {
217
+ // Force the GSK renderer to a specific value. After GTK 4.14 the
218
+ // `ngl` renderer is used by default which causes artifacts when
219
+ // used with Ghostty so it should be avoided.
220
+ log .warn ("setting GSK_RENDERER={s}" , .{@tagName (renderer )});
221
+ _ = internal_os .setenv ("GSK_RENDERER" , @tagName (renderer ));
222
+ },
223
+ }
224
+ }
225
+
164
226
c .gtk_init ();
165
227
const display : * c.GdkDisplay = c .gdk_display_get_default () orelse {
166
228
// I'm unsure of any scenario where this happens. Because we don't
0 commit comments