[at-spi2-core/wip/carlosg/x11-session-checks: 2/3] Do not rely on getenv("DISPLAY")!=NULL to assume it is a X11 environment



commit 3bb820723334a5903d0705801b04025bed055292
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon May 6 16:12:00 2019 +0200

    Do not rely on getenv("DISPLAY")!=NULL to assume it is a X11 environment
    
    Change/add checks around the AT_SPI_BUS root window property handling so it
    is only done if the session is a real X11 one.
    
    These checks used to work on wayland sessions, as there still is a X server
    to poke, it's strange to use as a side channel but that's about it. However
    in the future mutter will start Xwayland on demand, the DISPLAY environment
    variable will definitely exist so checking for it is definitely not
    sufficient, and opening the display will unintendedly spawn Xwayland.
    
    It is debatable that this should happen in Wayland sessions at all, so let
    the org.a11y.Bus fallbacks take over.

 atspi/atspi-misc.c        |  2 +-
 bus/at-spi-bus-launcher.c | 54 ++++++++++++++++++++++++-----------------------
 2 files changed, 29 insertions(+), 27 deletions(-)
---
diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c
index f0c8fdc..8d70849 100644
--- a/atspi/atspi-misc.c
+++ b/atspi/atspi-misc.c
@@ -1601,7 +1601,7 @@ atspi_get_a11y_bus (void)
   if (address_env != NULL && *address_env != 0)
     address = g_strdup (address_env);
 #ifdef HAVE_X11
-  if (!address)
+  if (!address && g_strcmp0 (g_getenv ("XDG_SESSION_TYPE"), "x11") == 0)
     address = get_accessibility_bus_address_x11 ();
 #endif
   if (!address)
diff --git a/bus/at-spi-bus-launcher.c b/bus/at-spi-bus-launcher.c
index f00dc9a..98f4114 100644
--- a/bus/at-spi-bus-launcher.c
+++ b/bus/at-spi-bus-launcher.c
@@ -466,20 +466,21 @@ ensure_a11y_bus (A11yBusLauncher *app)
 #endif
 
 #ifdef HAVE_X11
-  {
-    Display *display = XOpenDisplay (NULL);
-    if (display)
-      {
-        Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
-        XChangeProperty (display,
-                         XDefaultRootWindow (display),
-                         bus_address_atom,
-                         XA_STRING, 8, PropModeReplace,
-                         (guchar *) app->a11y_bus_address, strlen (app->a11y_bus_address));
-        XFlush (display);
-        XCloseDisplay (display);
-      }
-  }
+  if (g_strcmp0 (g_getenv ("XDG_SESSION_TYPE"), "x11") == 0)
+    {
+      Display *display = XOpenDisplay (NULL);
+      if (display)
+        {
+          Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
+          XChangeProperty (display,
+                           XDefaultRootWindow (display),
+                           bus_address_atom,
+                           XA_STRING, 8, PropModeReplace,
+                           (guchar *) app->a11y_bus_address, strlen (app->a11y_bus_address));
+          XFlush (display);
+          XCloseDisplay (display);
+        }
+    }
 #endif
 
   return TRUE;
@@ -884,19 +885,20 @@ main (int    argc,
    * we don't want early login processes to pick up the stale address.
    */
 #ifdef HAVE_X11
-  {
-    Display *display = XOpenDisplay (NULL);
-    if (display)
-      {
-        Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
-        XDeleteProperty (display,
-                         XDefaultRootWindow (display),
-                         bus_address_atom);
+  if (g_strcmp0 (g_getenv ("XDG_SESSION_TYPE"), "x11") == 0)
+    {
+      Display *display = XOpenDisplay (NULL);
+      if (display)
+        {
+          Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
+          XDeleteProperty (display,
+                           XDefaultRootWindow (display),
+                           bus_address_atom);
 
-        XFlush (display);
-        XCloseDisplay (display);
-      }
-  }
+          XFlush (display);
+          XCloseDisplay (display);
+        }
+    }
 #endif
 
   if (_global_app->a11y_launch_error_message)


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