[mutter] x11-display: Unset GDK_BACKEND environment variable



commit 23526a99c7bfc48ef6e13637be93ad8783b6aacb
Author: Michel Dänzer <mdaenzer redhat com>
Date:   Wed Jul 6 17:38:55 2022 +0200

    x11-display: Unset GDK_BACKEND environment variable
    
    mutter needs GDK to use the x11 backend. It already calls
    gdk_set_allowed_backends ("x11") for this purpose; however, if
    GDK_BACKEND=wayland (or any other non-x11 backend possibly) happened to
    be in the environment, GDK would fail to initialize at all. This would
    result in mutter not registering as X11 window manager, and all X11
    clients hanging.
    
    Big thanks to Olivier Fourdan for figuring this out!
    
    v2:
    * Restore original value of GDK_BACKEND environment variable after
      initializing GDK.
    
    Bug: https://bugzilla.redhat.com/show_bug.cgi?id=2022283
    Bug: https://bugs.debian.org/1008992
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2496>

 src/x11/meta-x11-display.c | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index b424dee70e..76e0b077b0 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1009,6 +1009,7 @@ meta_x11_init_gdk_display (GError **error)
 {
   const char *xdisplay_name;
   GdkDisplay *gdk_display;
+  const char *gdk_backend_env = NULL;
   const char *gdk_gl_env = NULL;
   const char *old_no_at_bridge;
   Display *xdisplay;
@@ -1023,6 +1024,10 @@ meta_x11_init_gdk_display (GError **error)
 
   gdk_set_allowed_backends ("x11");
 
+  gdk_backend_env = g_getenv ("GDK_BACKEND");
+  /* GDK would fail to initialize with e.g. GDK_BACKEND=wayland */
+  g_unsetenv ("GDK_BACKEND");
+
   gdk_gl_env = g_getenv ("GDK_GL");
   g_setenv ("GDK_GL", "disable", TRUE);
 
@@ -1053,6 +1058,9 @@ meta_x11_init_gdk_display (GError **error)
       return FALSE;
     }
 
+  if (gdk_backend_env)
+    g_setenv("GDK_BACKEND", gdk_backend_env, TRUE);
+
   if (gdk_gl_env)
     g_setenv("GDK_GL", gdk_gl_env, TRUE);
   else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]