Index: gtk/gtkmain.c
===================================================================
--- gtk/gtkmain.c	(revision 21172)
+++ gtk/gtkmain.c	(working copy)
@@ -648,6 +648,29 @@
 #endif  
 }
 
+static gchar*
+get_display_name (void)
+{
+    gchar *canonical_display_name = NULL;
+    const gchar *display_env = NULL;
+
+    display_env = g_getenv ("DISPLAY");
+    if (!display_env || !display_env[0])
+      canonical_display_name = ":0";
+    else
+      {
+        gchar *display_p, *screen_p;
+        canonical_display_name = g_strdup (display_env);
+        display_p = strrchr (canonical_display_name, ':');
+        screen_p = strrchr (canonical_display_name, '.');
+        if (screen_p && display_p && (screen_p > display_p))
+          {
+            *screen_p = '\0';
+          }
+      }
+    return canonical_display_name;
+}
+
 static void
 do_post_parse_initialization (int    *argc,
 			      char ***argv)
@@ -693,6 +716,43 @@
    */
   gtk_initialized = TRUE;
 
+  /* If AT_SPI_IOR is set, add gail and atk-bridge to the module list
+   */ 
+  if ((!gtk_modules_string) || !g_strrstr (gtk_modules_string->str, "gail"))
+    {
+      guchar *data = NULL;
+      GdkDisplay *display = NULL;
+      GdkScreen *screen = NULL;
+      GdkWindow *window = NULL;
+      GdkAtom actual_type;
+      GdkAtom AT_SPI_IOR;
+      gint actual_format;
+      gint actual_length;
+      gchar *display_name = NULL;
+
+      display_name = get_display_name ();
+      display = gdk_display_open (display_name);
+      g_free (display_name);
+
+      AT_SPI_IOR = gdk_atom_intern ("AT_SPI_IOR", FALSE);
+      screen = gdk_display_get_default_screen (display);
+      window = gdk_screen_get_root_window (screen);
+      gdk_property_get (window, AT_SPI_IOR,
+                        GDK_NONE, 0,
+                        (long)BUFSIZ, FALSE,
+                        &actual_type, &actual_format,
+                        &actual_length, &data);
+
+      if (data)
+        {
+          if (!gtk_modules_string)
+            gtk_modules_string = g_string_new (NULL);
+          g_string_append (gtk_modules_string, "gail:atk-bridge");
+          g_free (data);
+        }
+    }
+
+
   /* load gtk modules */
   if (gtk_modules_string)
     {
