[java-atk-wrapper] Use GTK_PATH to locate libatk-bridge.so



commit 209e429ca60fbc1ba51e56f3ba99342a25faaaa2
Author: Ke Wang <kewang sun com>
Date:   Thu May 13 12:13:57 2010 +0800

    Use GTK_PATH to locate libatk-bridge.so

 configure.in                                       |    6 +--
 jni/src/AtkWrapper.c                               |   57 ++++++++++++--------
 jni/src/Makefile.am                                |    3 +-
 wrapper/org/GNOME/Accessibility/AtkWrapper.java.in |   19 ++-----
 4 files changed, 43 insertions(+), 42 deletions(-)
---
diff --git a/configure.in b/configure.in
index 19b6690..ef9585b 100644
--- a/configure.in
+++ b/configure.in
@@ -34,10 +34,8 @@ PKG_CHECK_MODULES(JAW, [
 	gconf-2.0
 ])
 
-ATK_BRIDGE_LIB_NAME_DBUS="`pkg-config --variable=libdir gtk+-2.0`/gtk-2.0/modules/libatk-bridge.so"
-ATK_BRIDGE_LIB_NAME_CORBA="`pkg-config --variable=libdir gtk+-2.0`/gtk-2.0/modules/at-spi-corba/modules/libatk-bridge.so"
-AC_SUBST(ATK_BRIDGE_LIB_NAME_DBUS)
-AC_SUBST(ATK_BRIDGE_LIB_NAME_CORBA)
+ATK_BRIDGE_LIB_PATH="`pkg-config --variable=libdir gtk+-2.0`/gtk-2.0"
+AC_SUBST(ATK_BRIDGE_LIB_PATH)
 
 # java wrapper
 
diff --git a/jni/src/AtkWrapper.c b/jni/src/AtkWrapper.c
index 382b0c0..640b559 100644
--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -56,6 +56,8 @@ GCond *key_dispatch_cond = NULL;
 static gint key_dispatch_result = KEY_DISPATCH_NOT_DISPATCHED;
 static gboolean (*origin_g_idle_dispatch) (GSource*, GSourceFunc, gpointer);
 
+static GModule* module_atk_bridge = NULL;
+
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *javaVM, void *reserve) {
 	globalJvm = javaVM;
 	return JNI_VERSION_1_2;
@@ -101,30 +103,11 @@ static gboolean
 jaw_load_atk_bridge (gpointer p)
 {
 	g_mutex_lock(atk_bridge_mutex);
-
-	if (!g_module_supported()) {
-		return NULL;
-	}
-
-	gboolean use_corba = gconf_client_get_bool(
-			gconf_client_get_default(),
-			"/desktop/gnome/interface/at-spi-corba",
-			NULL);
-
-	GModule *module;
-	if (use_corba)
-		module = g_module_open(ATK_BRIDGE_LIB_NAME_CORBA, G_MODULE_BIND_LAZY);
-	else
-		module = g_module_open(ATK_BRIDGE_LIB_NAME_DBUS, G_MODULE_BIND_LAZY);
-
-	if (!module) {
-		return NULL;
-	}
 	
 	GVoidFunc dl_init;
-	if (!g_module_symbol( module, "gnome_accessibility_module_init", (gpointer*)&dl_init)) {
-		g_module_close(module);
-		return NULL;
+	if (!g_module_symbol( module_atk_bridge, "gnome_accessibility_module_init", (gpointer*)&dl_init)) {
+		g_module_close(module_atk_bridge);
+		return FALSE;
 	}
 
 	(dl_init)();
@@ -146,7 +129,7 @@ gpointer jni_main_loop(gpointer data) {
 	return NULL;
 }
 
-JNIEXPORT void JNICALL Java_org_GNOME_Accessibility_AtkWrapper_initNativeLibrary(JNIEnv *jniEnv, jclass jClass) {
+JNIEXPORT jboolean JNICALL Java_org_GNOME_Accessibility_AtkWrapper_initNativeLibrary(JNIEnv *jniEnv, jclass jClass) {
 	g_type_init();
 
 	// Hook up g_idle_dispatch
@@ -176,6 +159,32 @@ JNIEXPORT void JNICALL Java_org_GNOME_Accessibility_AtkWrapper_initNativeLibrary
 		g_thread_init(NULL);
 	}
 
+	if (!g_module_supported()) {
+		return JNI_FALSE;
+	}
+
+	const gchar* gtk_module_path = g_getenv("GTK_PATH");
+	if (!gtk_module_path) {
+		gtk_module_path = ATK_BRIDGE_LIB_PATH;
+	}
+
+	if (jaw_debug) {
+		printf("GTK_PATH=%s\n", gtk_module_path);
+	}
+
+	const gchar* atk_bridge_file = g_strconcat(gtk_module_path,
+			"/modules/libatk-bridge.so", NULL);
+
+	if (jaw_debug) {
+		printf("We are going to load %s\n", atk_bridge_file);
+	}
+
+	module_atk_bridge = g_module_open(atk_bridge_file, G_MODULE_BIND_LAZY);
+
+	if (!module_atk_bridge) {
+		return JNI_FALSE;
+	}
+
 	jaw_impl_init_mutex();
 
 	atk_bridge_mutex = g_mutex_new();
@@ -187,6 +196,8 @@ JNIEXPORT void JNICALL Java_org_GNOME_Accessibility_AtkWrapper_initNativeLibrary
 	// Dummy idle function for jaw_idle_dispatch to get
 	// the address of gdk_threads_dispatch
 	gdk_threads_add_idle(jaw_dummy_idle_func, NULL);
+
+	return JNI_TRUE;
 }
 
 JNIEXPORT void JNICALL Java_org_GNOME_Accessibility_AtkWrapper_loadAtkBridge(JNIEnv *jniEnv, jclass jClass) {
diff --git a/jni/src/Makefile.am b/jni/src/Makefile.am
index 17c2a9c..3ca6896 100644
--- a/jni/src/Makefile.am
+++ b/jni/src/Makefile.am
@@ -24,8 +24,7 @@ noinst_HEADERS = jawimpl.h \
 
 libatk_wrapper_la_CPPFLAGS = $(JNI_INCLUDES)\
 			     $(JAW_CFLAGS)\
-			     -DATK_BRIDGE_LIB_NAME_DBUS=\"$(ATK_BRIDGE_LIB_NAME_DBUS)\"\
-			     -DATK_BRIDGE_LIB_NAME_CORBA=\"$(ATK_BRIDGE_LIB_NAME_CORBA)\"
+			     -DATK_BRIDGE_LIB_PATH=\"$(ATK_BRIDGE_LIB_PATH)\"
 
 libatk_wrapper_la_LDFLAGS = -version-info $(LIB_ATK_WRAPPER_LT_VERSION)
 
diff --git a/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in b/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in
index 34132cb..e02fbac 100644
--- a/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in
+++ b/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in
@@ -29,23 +29,16 @@ public class AtkWrapper {
 	static boolean accessibilityEnabled = false;
 	static {
 		try {
-			Process p = Runtime.getRuntime().exec("@XPROP@ -root");
+			Process p = Runtime.getRuntime().exec ("gconftool-2 -g /desktop/gnome/interface/accessibility");
 			BufferedReader b = new BufferedReader (
 					new InputStreamReader (p.getInputStream ()));
-			String result;
-			accessibilityEnabled = false;
-			while ((result = b.readLine()) != null) {
-				if (result.indexOf ("AT_SPI_IOR") >= 0) {
+			String result = b.readLine();
+			if (result != null && result.equals ("true")) {
+				System.loadLibrary("atk-wrapper");
+				if ( AtkWrapper.initNativeLibrary() ) {
 					accessibilityEnabled = true;
-					break;
 				}
 			}
-
-			if (accessibilityEnabled) {
-				System.loadLibrary("atk-wrapper");
-				AtkWrapper.initNativeLibrary();
-			}
-			
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -497,7 +490,7 @@ public class AtkWrapper {
 		}
 	}
 
-	public native static void initNativeLibrary();
+	public native static boolean initNativeLibrary();
 	public native static void loadAtkBridge();
 
 	public native static void focusNotify(javax.accessibility.AccessibleContext ac);



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