From 48ec9ea660930caefe282ac017e1fb978a7104af Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:55:10 +0200 Subject: [PATCH] libdecor: prevent crash using bullt-in libdecor with GDK_BACKEND=x11 (#1029) --- libdecor/build/fl_libdecor.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libdecor/build/fl_libdecor.c b/libdecor/build/fl_libdecor.c index 702682718..4d480061a 100644 --- a/libdecor/build/fl_libdecor.c +++ b/libdecor/build/fl_libdecor.c @@ -23,6 +23,7 @@ #endif #include +#include static void *dlopen_corrected(const char *, int); #define dlopen(A, B) dlopen_corrected(A, B) #include "fl_libdecor.h" @@ -126,8 +127,21 @@ struct libdecor *fl_libdecor_new(struct wl_display *wl_display, const struct lib // no plug-in was found by dlopen(), use built-in plugin instead // defined in the source code of the built-in plugin: libdecor-cairo.c or libdecor-gtk.c extern const struct libdecor_plugin_description libdecor_plugin_description; +#if HAVE_GTK + bool gdk_caution = false; + if (getenv("GDK_BACKEND") && strcmp(getenv("GDK_BACKEND"), "x11") == 0) { + // Environment variable GDK_BACKEND=x11 makes the .constructor below fail + // for the built-in GTK plugin and then FLTK crashes (#1029). + // Temporarily unset GDK_BACKEND to prevent that. + gdk_caution = true; + unsetenv("GDK_BACKEND"); + } +#endif context->plugin = libdecor_plugin_description.constructor(context); - } +#if HAVE_GTK + if (gdk_caution) putenv("GDK_BACKEND=x11"); +#endif + } wl_display_flush(wl_display); return context;