--- a/atk-adaptor/accessible-cache.c
+++ b/atk-adaptor/accessible-cache.c
@@ -314,6 +314,9 @@ add_pending_items (gpointer data)
 
 /*---------------------------------------------------------------------------*/
 
+guint
+spi_idle_add(GSourceFunc    function, gpointer       data);
+
 static gboolean
 child_added_listener (GSignalInvocationHint * signal_hint,
                       guint n_param_values,
@@ -358,7 +361,7 @@ child_added_listener (GSignalInvocationH
           g_queue_push_tail (cache->add_traversal, child);
 
           if (cache->add_pending_idle == 0)
-            cache->add_pending_idle = g_idle_add (add_pending_items, cache);
+            cache->add_pending_idle = spi_idle_add (add_pending_items, cache);
         }
 #ifdef SPI_ATK_DEBUG
       recursion_check_unset ();
@@ -400,7 +403,7 @@ toplevel_added_listener (AtkObject * acc
       g_queue_push_tail (cache->add_traversal, child);
 
       if (cache->add_pending_idle == 0)
-        cache->add_pending_idle = g_idle_add (add_pending_items, cache);
+        cache->add_pending_idle = spi_idle_add (add_pending_items, cache);
 #ifdef SPI_ATK_DEBUG
       recursion_check_unset ();
 #endif
--- a/atk-adaptor/event.c
+++ b/atk-adaptor/event.c
@@ -42,6 +42,8 @@ static GArray *listener_ids = NULL;
 static gint atk_bridge_key_event_listener_id;
 static gint atk_bridge_focus_tracker_id;
 
+GMainContext *spi_context = NULL;
+
 /*---------------------------------------------------------------------------*/
 
 #define ITF_EVENT_OBJECT   "org.a11y.atspi.Event.Object"
@@ -72,6 +74,34 @@ switch_main_context (GMainContext *cnx)
     atspi_dbus_connection_setup_with_g_main (list->data, cnx);
 }
 
+guint
+spi_idle_add(GSourceFunc    function, gpointer       data)
+{
+  GSource *source;
+  guint id;
+
+  source = g_idle_source_new ();
+  g_source_set_callback (source, function, data, NULL);
+  id = g_source_attach (source, spi_context);
+  g_source_unref (source);
+
+  return id;
+}
+
+guint
+spi_timeout_add_seconds (gint interval, GSourceFunc function, gpointer    data)
+{
+  GSource *source;
+  guint id;
+
+  source = g_timeout_source_new_seconds (interval);
+  g_source_set_callback (source, function, data, NULL);
+  id = g_source_attach (source, spi_context);
+  g_source_unref (source);
+
+  return id;
+}
+
 static void
 set_reply (DBusPendingCall * pending, void *user_data)
 {
@@ -79,7 +109,7 @@ set_reply (DBusPendingCall * pending, vo
 
   closure->reply = dbus_pending_call_steal_reply (pending);
   dbus_pending_call_unref (pending);
-  switch_main_context (NULL);
+  switch_main_context (spi_context);
   g_main_loop_quit (closure->loop);
 }
 
@@ -88,7 +118,7 @@ timeout_reply (void *data)
 {
   SpiReentrantCallClosure *closure = data;
 
-  switch_main_context (NULL);
+  switch_main_context (spi_context);
   g_main_loop_quit (closure->loop);
   closure->timeout = -1;
   return FALSE;
@@ -108,7 +138,7 @@ send_and_allow_reentry (DBusConnection *
 
   if (!dbus_connection_send_with_reply (bus, message, &pending, 9000) || !pending)
     {
-      switch_main_context (NULL);
+      switch_main_context (spi_context);
       return NULL;
     }
   dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
@@ -126,6 +156,13 @@ send_and_allow_reentry (DBusConnection *
   return closure.reply;
 }
 
+void
+atk_bridge_set_event_context(GMainContext *cnx)
+{
+  spi_context = cnx;
+  switch_main_context(spi_context);
+}
+
 /*---------------------------------------------------------------------------*/
 
 /*
--- a/atk-adaptor/accessible-leasing.c
+++ b/atk-adaptor/accessible-leasing.c
@@ -25,6 +25,7 @@
 #include <string.h>
 
 #include "accessible-leasing.h"
+#include "event.h"
 
 #ifdef SPI_ATK_DEBUG
 #include "accessible-cache.h"
@@ -161,8 +162,8 @@ add_expiry_timeout (SpiLeasing * leasing
   /* The current time is implicitly rounded down here by ignoring the us */
   g_get_current_time (&t);
   next_expiry = elem->expiry_s - t.tv_sec;
-  leasing->expiry_func_id = g_timeout_add_seconds (next_expiry,
-                                                   expiry_func, leasing);
+  leasing->expiry_func_id = spi_timeout_add_seconds (next_expiry,
+                                                     expiry_func, leasing);
 }
 
 /*---------------------------------------------------------------------------*/
--- a/atk-adaptor/event.h
+++ b/atk-adaptor/event.h
@@ -30,4 +30,8 @@ void spi_atk_deregister_event_listeners
 void spi_atk_tidy_windows (void);
 
 gboolean spi_event_is_subtype (gchar **needle, gchar **haystack);
+
+extern GMainContext *spi_context;
+guint spi_idle_add(GSourceFunc    function, gpointer       data);
+guint spi_timeout_add_seconds (gint interval, GSourceFunc function, gpointer    data);
 #endif /* EVENT_H */
--- a/atk-adaptor/atkbridge.symbols
+++ b/atk-adaptor/atkbridge.symbols
@@ -1,2 +1,3 @@
 atk_bridge_adaptor_init
 atk_bridge_adaptor_cleanup
+atk_bridge_set_event_context
--- a/atk-adaptor/bridge.c
+++ b/atk-adaptor/bridge.c
@@ -670,7 +670,7 @@ new_connection_cb (DBusServer *server, D
 {
   dbus_connection_set_unix_user_function (con, user_check, NULL, NULL);
   dbus_connection_ref(con);
-  atspi_dbus_connection_setup_with_g_main(con, NULL);
+  atspi_dbus_connection_setup_with_g_main(con, spi_context);
   droute_intercept_dbus (con);
   droute_context_register (spi_global_app_data->droute, con);
 
@@ -904,7 +904,7 @@ spi_atk_create_socket (SpiBridge *app)
     return -1;
   }
 
-  atspi_dbus_server_setup_with_g_main(server, NULL);
+  atspi_dbus_server_setup_with_g_main(server, spi_context);
   dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL);
 
   spi_global_app_data->server = server;
--- a/atk-adaptor/atk-bridge.h
+++ b/atk-adaptor/atk-bridge.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 
 int atk_bridge_adaptor_init (int * argc, char ** argv[]);
 void atk_bridge_adaptor_cleanup (void);
+void atk_bridge_set_event_context(GMainContext *cnx);
 
 G_END_DECLS
 
