From f309d4191e7bec5266c3ecbeb2d7fac80010932e Mon Sep 17 00:00:00 2001 From: Christian Kugler Date: Sun, 29 Sep 2024 13:24:04 +0200 Subject: [PATCH] Use helper function to set correct env variables GTK4 version 4.16 split the environment variable `GDK_DEBUG` into `GDK_DEBUG` and `GDK_DISABLE`. This is being done by using the helper function `atLeast` to handle certain versions accordingly. `GSK_RENDERER` also only needs to be set in later GTK versions (>=1.14.0). --- src/apprt/gtk/App.zig | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 58c6c80a0..64125575b 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -28,6 +28,7 @@ const Window = @import("Window.zig"); const ConfigErrorsWindow = @import("ConfigErrorsWindow.zig"); const ClipboardConfirmationWindow = @import("ClipboardConfirmationWindow.zig"); const c = @import("c.zig").c; +const version = @import("version.zig"); const inspector = @import("inspector.zig"); const key = @import("key.zig"); const x11 = @import("x11.zig"); @@ -85,17 +86,24 @@ quit_timer: union(enum) { pub fn init(core_app: *CoreApp, opts: Options) !App { _ = opts; - // We need to export GDK_DEBUG to run on Wayland after GTK 4.14. - // Older versions of GTK do not support these values so it is safe - // to always set this. Forwards versions are uncertain so we'll have to - // reassess... - // - // Upstream issue: https://gitlab.gnome.org/GNOME/gtk/-/issues/6589 - _ = internal_os.setenv("GDK_DEBUG", "opengl,gl-disable-gles"); - // From gtk 4.16, GDK_DEBUG is split into GDK_DEBUG and GDK_DISABLE - _ = internal_os.setenv("GDK_DISABLE", "gles-api"); - // We need to export GSK_RENDERER to opengl because GTK uses ngl by default after 4.14 - _ = internal_os.setenv("GSK_RENDERER", "opengl"); + if (version.atLeast(4, 16, 0)) { + // From gtk 4.16, GDK_DEBUG is split into GDK_DEBUG and GDK_DISABLE + _ = internal_os.setenv("GDK_DISABLE", "gles-api"); + _ = internal_os.setenv("GDK_DEBUG", "opengl"); + } else if (version.atLeast(4, 14, 0)) { + // We need to export GDK_DEBUG to run on Wayland after GTK 4.14. + // Older versions of GTK do not support these values so it is safe + // to always set this. Forwards versions are uncertain so we'll have to + // reassess... + // + // Upstream issue: https://gitlab.gnome.org/GNOME/gtk/-/issues/6589 + _ = internal_os.setenv("GDK_DEBUG", "opengl,gl-disable-gles"); + } + + if (version.atLeast(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"); + } // Load our configuration var config = try Config.load(core_app.alloc);