[Xfce4-commits] <xfce4-session:master> Add support for starting assistive technologies.

Nick Schermer noreply at xfce.org
Thu Feb 17 21:02:01 CET 2011


Updating branch refs/heads/master
         to b2ccb203b6125cb45aaf7c3d86e9604f05f60755 (commit)
       from c23466a351635db9bd6f49870c72ee1fd16a6183 (commit)

commit b2ccb203b6125cb45aaf7c3d86e9604f05f60755
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Feb 17 20:56:43 2011 +0100

    Add support for starting assistive technologies.
    
    Xfce4-session now launches the required at-spi register
    applications and takes care of loading the Gtk modules
    if the xfconf key /general/StartAt is enabled.
    
    The at-spi applications are launched before the failsafe
    applications (panel, wm, desktop) and waits for a maximum
    of 2 seconds until the at-bridge is created.
    
    When accessibility is disabled and Gnome services are enabled
    we previously started the at-spi desktop files, this is not
    done anymore if accessibility is disabled in Xfsm.

 xfce4-session/xfsm-compat-gnome.c |   63 -----------------
 xfce4-session/xfsm-manager.c      |    9 +++
 xfce4-session/xfsm-manager.h      |    2 +
 xfce4-session/xfsm-startup.c      |  133 +++++++++++++++++++++++++++++++++++-
 4 files changed, 140 insertions(+), 67 deletions(-)

diff --git a/xfce4-session/xfsm-compat-gnome.c b/xfce4-session/xfsm-compat-gnome.c
index e9040c6..f498362 100644
--- a/xfce4-session/xfsm-compat-gnome.c
+++ b/xfce4-session/xfsm-compat-gnome.c
@@ -189,52 +189,6 @@ gnome_keyring_daemon_shutdown (void)
 }
 
 
-#ifdef HAVE_GNOME
-static void
-gnome_ast_startup (void)
-{
-  GError *error = NULL;
-  GSList *list;
-  GSList *lp;
-  gchar  *path;
-
-  list = gconf_client_get_list (gnome_conf_client, AT_STARTUP_KEY,
-                                GCONF_VALUE_STRING, &error);
-
-  if (error != NULL)
-    {
-      g_warning ("Failed to query value of " AT_STARTUP_KEY ": %s",
-                 error->message);
-      g_error_free (error);
-    }
-  else
-    {
-      for (lp = list; lp != NULL; lp = lp->next)
-        {
-          path = g_find_program_in_path ((const gchar *) lp->data);
-          if (path != NULL)
-            {
-              g_spawn_command_line_async (path, &error);
-              if (error != NULL)
-                {
-                  g_warning ("Failed to execute assistive helper %s: %s",
-                             path, error->message);
-                  g_error_free (error);
-                }
-              else
-                {
-                  /* give it some time to fire up */
-                  g_usleep (50 * 1000);
-                }
-              g_free (path);
-            }
-          g_free (lp->data);
-        }
-      g_slist_free (list);
-    }
-}
-#endif
-
 
 static void
 xfsm_compat_gnome_smproxy_startup (void)
@@ -301,23 +255,6 @@ xfsm_compat_gnome_startup (XfsmSplashScreen *splash)
     xfsm_splash_screen_next (splash, _("Starting The Gnome Keyring Daemon"));
   gnome_keyring_daemon_startup ();
 
-#ifdef HAVE_GNOME
-  /* connect to the GConf daemon */
-  gnome_conf_client = gconf_client_get_default ();
-  if (gnome_conf_client != NULL)
-    {
-      if (gconf_client_get_bool (gnome_conf_client, ACCESSIBILITY_KEY, NULL))
-        {
-          if (G_LIKELY (splash != NULL))
-            {
-              xfsm_splash_screen_next (splash, _("Starting Gnome Assistive Technologies"));
-            }
-
-          gnome_ast_startup ();
-        }
-    }
-#endif
-
   gnome_compat_started = TRUE;
 }
 
diff --git a/xfce4-session/xfsm-manager.c b/xfce4-session/xfsm-manager.c
index 07c5369..5d9b790 100644
--- a/xfce4-session/xfsm-manager.c
+++ b/xfce4-session/xfsm-manager.c
@@ -102,6 +102,8 @@ struct _XfsmManager
   gchar           *session_file;
   gchar           *checkpoint_session_name;
 
+  gboolean         start_at;
+
   gboolean         compat_gnome;
   gboolean         compat_kde;
 
@@ -729,6 +731,7 @@ xfsm_manager_load (XfsmManager   *manager,
 
   manager->compat_gnome = xfconf_channel_get_bool (channel, "/compat/LaunchGNOME", FALSE);
   manager->compat_kde = xfconf_channel_get_bool (channel, "/compat/LaunchKDE", FALSE);
+  manager->start_at = xfconf_channel_get_bool (channel, "/general/StartAt", FALSE);
 
   display_name  = xfsm_gdk_display_get_fullname (gdk_display_get_default ());
 
@@ -1774,6 +1777,12 @@ xfsm_manager_get_compat_startup (XfsmManager          *manager,
 }
 
 
+gboolean
+xfsm_manager_get_start_at (XfsmManager *manager)
+{
+  return manager->start_at;
+}
+
 
 /*
  * dbus server impl
diff --git a/xfce4-session/xfsm-manager.h b/xfce4-session/xfsm-manager.h
index ffbc7ea..ba980d3 100644
--- a/xfce4-session/xfsm-manager.h
+++ b/xfce4-session/xfsm-manager.h
@@ -155,4 +155,6 @@ gboolean xfsm_manager_get_use_failsafe_mode (XfsmManager *manager);
 gboolean xfsm_manager_get_compat_startup (XfsmManager          *manager,
                                           XfsmManagerCompatType type);
 
+gboolean xfsm_manager_get_start_at (XfsmManager *manager);
+
 #endif /* !__XFSM_MANAGER_H__ */
diff --git a/xfce4-session/xfsm-startup.c b/xfce4-session/xfsm-startup.c
index ebee638..2886e20 100644
--- a/xfce4-session/xfsm-startup.c
+++ b/xfce4-session/xfsm-startup.c
@@ -45,7 +45,7 @@
 #endif
 
 #include <glib/gstdio.h>
-
+#include <gdk/gdkx.h>
 #include <libxfce4ui/libxfce4ui.h>
 
 #include <libxfsm/xfsm-util.h>
@@ -303,7 +303,8 @@ xfsm_startup_autostart_migrate (void)
 
 
 static gint
-xfsm_startup_autostart_xdg (XfsmManager *manager)
+xfsm_startup_autostart_xdg (XfsmManager *manager,
+                            gboolean     start_at_spi)
 {
   const gchar *try_exec;
   const gchar *type;
@@ -320,6 +321,8 @@ xfsm_startup_autostart_xdg (XfsmManager *manager)
   gchar      **not_show_in;
   gint         started = 0;
   gint         n, m;
+  gchar       *filename;
+  const gchar *pattern;
 
   /* migrate the old autostart location (if still present) */
   xfsm_startup_autostart_migrate ();
@@ -328,7 +331,13 @@ xfsm_startup_autostart_xdg (XfsmManager *manager)
   kde = xfsm_manager_get_compat_startup (manager, XFSM_MANAGER_COMPAT_KDE);
   gnome = xfsm_manager_get_compat_startup (manager, XFSM_MANAGER_COMPAT_GNOME);
 
-  files = xfce_resource_match (XFCE_RESOURCE_CONFIG, "autostart/*.desktop", TRUE);
+  /* pattern for only at-spi desktop files or everything */
+  if (start_at_spi)
+    pattern = "autostart/at-spi-*.desktop";
+  else
+    pattern = "autostart/*.desktop";
+
+  files = xfce_resource_match (XFCE_RESOURCE_CONFIG, pattern, TRUE);
   for (n = 0; files[n] != NULL; ++n)
     {
       rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, files[n], TRUE);
@@ -380,6 +389,14 @@ xfsm_startup_autostart_xdg (XfsmManager *manager)
                   g_strfreev (not_show_in);
                 }
             }
+
+          /* skip at-spi launchers if not in at-spi mode or don't skip
+           * them no matter what the OnlyShowIn key says if only
+           * launching at-spi */
+          filename = g_path_get_basename (files[n]);
+          if (g_str_has_prefix (filename, "at-spi-"))
+            skip = !start_at_spi;
+          g_free (filename);
         }
 
       /* check the "Type" key */
@@ -433,7 +450,7 @@ xfsm_startup_autostart (XfsmManager *manager)
 {
   gint n;
 
-  n = xfsm_startup_autostart_xdg (manager);
+  n = xfsm_startup_autostart_xdg (manager, FALSE);
 
   if (n > 0)
     {
@@ -461,11 +478,119 @@ xfsm_startup_foreign (XfsmManager *manager)
 }
 
 
+static void
+xfsm_startup_at_set_gtk_modules (void)
+{
+  const gchar  *old;
+  gchar       **modules;
+  guint         i;
+  gboolean      found_gail = FALSE;
+  gboolean      found_atk_bridge = FALSE;
+  GString      *new;
+
+  old = g_getenv ("GTK_MODULES");
+  if (old != NULL && *old != '\0')
+    {
+      /* check which modules are already loaded */
+      modules = g_strsplit (old, ":", -1);
+      for (i = 0; modules[i] != NULL; i++)
+        {
+          if (strcmp (modules[i], "gail") == 0)
+            found_gail = TRUE;
+          else if (strcmp (modules[i], "atk-bridge") == 0)
+            found_atk_bridge = TRUE;
+        }
+      g_strfreev (modules);
+
+      if (!found_gail || !found_atk_bridge)
+        {
+          /* append modules to old value */
+          new = g_string_new (old);
+          if (!found_gail)
+            new = g_string_append (new, ":gail");
+          if (!found_atk_bridge)
+            new = g_string_append (new, ":atk-bridge");
+
+          g_setenv ("GTK_MODULES", new->str, TRUE);
+          g_string_free (new, TRUE);
+        }
+    }
+  else
+    {
+      g_setenv ("GTK_MODULES", "gail:atk-bridge", TRUE);
+    }
+}
+
+
+static gboolean
+xfsm_startup_at_spi_ior_set (void)
+{
+  Atom        AT_SPI_IOR;
+  GdkDisplay *display;
+  Atom        actual_type;
+  gint        actual_format;
+  guchar    *data = NULL;
+  gulong     nitems;
+  gulong     leftover;
+
+  display = gdk_display_get_default ();
+  AT_SPI_IOR = XInternAtom (GDK_DISPLAY_XDISPLAY (display), "AT_SPI_IOR", False);
+  XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
+                      XDefaultRootWindow (GDK_DISPLAY_XDISPLAY (display)),
+                      AT_SPI_IOR, 0L,
+                      (long) BUFSIZ, False,
+                      (Atom) 31, &actual_type, &actual_format,
+                      &nitems, &leftover, &data);
+
+  if (data == NULL)
+    return FALSE;
+  XFree (data);
+
+  return TRUE;
+}
+
+
+static void
+xfsm_startup_at (XfsmManager *manager)
+{
+  gint n, i;
+
+  /* start at-spi-dbus-bus and/or at-spi-registryd */
+  n = xfsm_startup_autostart_xdg (manager, TRUE);
+
+  if (n > 0)
+    {
+      if (G_LIKELY (splash_screen != NULL))
+        xfsm_splash_screen_next (splash_screen, _("Starting Assistive Technologies"));
+
+      xfsm_startup_at_set_gtk_modules ();
+
+      /* wait for 2 seconds until the at-spi registered, not very nice
+       * but required to properly start an accessible desktop */
+      for (i = 0; i < 10; i++)
+        {
+          if (xfsm_startup_at_spi_ior_set ())
+            break;
+          xfsm_verbose ("Waiting for at-spi to register...\n");
+          g_usleep (G_USEC_PER_SEC / 5);
+        }
+    }
+  else
+    {
+      g_warning ("No assistive technology service provider was started!");
+    }
+}
+
+
 void
 xfsm_startup_begin (XfsmManager *manager)
 {
   if (xfsm_manager_get_use_failsafe_mode (manager))
     {
+      /* start assistive technology before anything else */
+      if (xfsm_manager_get_start_at (manager))
+        xfsm_startup_at (manager);
+
       xfsm_startup_failsafe (manager);
       xfsm_startup_autostart (manager);
       xfsm_manager_signal_startup_done (manager);



More information about the Xfce4-commits mailing list