--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -56,6 +56,7 @@ gboolean jaw_debug = FALSE;
 
 static gint key_dispatch_result;
 static GMainLoop* jni_main_loop;
+static GMainContext *jni_main_context;
 
 static gboolean jaw_initialized = FALSE;
 
@@ -111,6 +112,20 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   return JNI_TRUE;
 }
 
+static guint
+jni_main_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, jni_main_context);
+  g_source_unref(source);
+
+  return id;
+}
+
 JNIEXPORT void
 JNICALL Java_org_GNOME_Accessibility_AtkWrapper_loadAtkBridge()
 {
@@ -127,7 +142,9 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   if (jaw_debug)
     printf("Jaw Initialization STATUS in loadAtkBridge: %d\n", jaw_initialized);
 
-  jni_main_loop = g_main_loop_new (NULL, FALSE); /*main loop NOT running*/
+  jni_main_context = g_main_context_new();
+  jni_main_loop = g_main_loop_new (jni_main_context, FALSE); /*main loop NOT running*/
+  atk_bridge_set_event_context(jni_main_context);
   thread = g_thread_new(message, jni_loop_callback, (void *) jni_main_loop);
   if(thread == NULL)
   {
@@ -264,7 +281,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(focus_notify_handler, para);
+  jni_main_idle_add(focus_notify_handler, para);
 }
 
 static gboolean
@@ -347,7 +364,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   } 
   CallbackPara *para = alloc_callback_para(global_ac);
   para->is_toplevel = (jIsToplevel == JNI_TRUE) ? TRUE : FALSE;
-  gdk_threads_add_idle(window_open_handler, para);
+  jni_main_idle_add(window_open_handler, para);
 }
 
 static gboolean
@@ -429,7 +446,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   }
   CallbackPara *para = alloc_callback_para(global_ac);
   para->is_toplevel = (jIsToplevel == JNI_TRUE) ? TRUE : FALSE;
-  gdk_threads_add_idle(window_close_handler, para);
+  jni_main_idle_add(window_close_handler, para);
 }
 
 static gboolean
@@ -483,7 +500,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(window_minimize_handler, para);
+  jni_main_idle_add(window_minimize_handler, para);
 }
 
 static gboolean
@@ -537,7 +554,7 @@ JNIEXPORT void JNICALL Java_org_GNOME_Ac
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac );
-  gdk_threads_add_idle(window_maximize_handler, para);
+  jni_main_idle_add(window_maximize_handler, para);
 }
 
 static gboolean
@@ -592,7 +609,7 @@ JNIEXPORT void JNICALL Java_org_GNOME_Ac
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(window_restore_handler, para);
+  jni_main_idle_add(window_restore_handler, para);
 }
 
 static gboolean
@@ -645,7 +662,7 @@ JNIEXPORT void JNICALL Java_org_GNOME_Ac
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(window_activate_handler, para);
+  jni_main_idle_add(window_activate_handler, para);
 }
 
 static gboolean
@@ -700,7 +717,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(window_deactivate_handler, para);
+  jni_main_idle_add(window_deactivate_handler, para);
 }
 
 static gboolean
@@ -756,7 +773,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(window_state_change_handler, para);
+  jni_main_idle_add(window_state_change_handler, para);
 }
 
 static gchar
@@ -1098,7 +1115,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   CallbackPara *para = alloc_callback_para(global_ac);
   para->signal_id = (gint)id;
   para->args = global_args;
-  gdk_threads_add_idle(signal_emit_handler, para);
+  jni_main_idle_add(signal_emit_handler, para);
 }
 
 static gboolean
@@ -1162,7 +1179,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
   } else {
     para->state_value = FALSE;
   }
-  gdk_threads_add_idle(object_state_change_handler, para);
+  jni_main_idle_add(object_state_change_handler, para);
 }
 
 static gboolean
@@ -1225,7 +1242,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
     return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(component_added_handler, para);
+  jni_main_idle_add(component_added_handler, para);
 }
 
 static gboolean
@@ -1290,7 +1307,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
     return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(component_removed_handler, para);
+  jni_main_idle_add(component_removed_handler, para);
 }
 
 /**
@@ -1356,7 +1373,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
    return;
   }
   CallbackPara *para = alloc_callback_para(global_ac);
-  gdk_threads_add_idle(bounds_changed_handler, para);
+  jni_main_idle_add(bounds_changed_handler, para);
 }
 
 static gboolean
@@ -1474,7 +1491,7 @@ JNICALL Java_org_GNOME_Accessibility_Atk
 {
   jboolean key_consumed;
   jobject global_key_event = (*jniEnv)->NewGlobalRef(jniEnv, jAtkKeyEvent);
-  gdk_threads_add_idle(key_dispatch_handler, (gpointer)global_key_event);
+  jni_main_idle_add(key_dispatch_handler, (gpointer)global_key_event);
 
   if(jaw_debug)
     printf("key_dispatch_result saved = %d\n ", key_dispatch_result);
