40 |
#include "gnu_java_awt_peer_gtk_GtkToolkit.h" |
#include "gnu_java_awt_peer_gtk_GtkToolkit.h" |
41 |
#include "gthread-jni.h" |
#include "gthread-jni.h" |
42 |
#include "jcl.h" |
#include "jcl.h" |
43 |
|
#include <gdk/gdkx.h> |
|
#include <sys/time.h> |
|
44 |
|
|
45 |
#define RC_FILE ".classpath-gtkrc" |
#define RC_FILE ".classpath-gtkrc" |
46 |
|
|
156 |
|
|
157 |
gtk_init (&argc, &argv); |
gtk_init (&argc, &argv); |
158 |
|
|
159 |
|
#if SYNCHRONIZE_GDK |
160 |
|
XSynchronize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), True); |
161 |
|
#endif |
162 |
|
|
163 |
gdk_rgb_init (); |
gdk_rgb_init (); |
164 |
gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); |
gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); |
165 |
gtk_widget_set_default_visual (gdk_rgb_get_visual ()); |
gtk_widget_set_default_visual (gdk_rgb_get_visual ()); |
193 |
cp_gtk_checkbox_init_jni (); |
cp_gtk_checkbox_init_jni (); |
194 |
cp_gtk_choice_init_jni (); |
cp_gtk_choice_init_jni (); |
195 |
cp_gtk_component_init_jni (); |
cp_gtk_component_init_jni (); |
196 |
|
cp_gtk_filedialog_init_jni (); |
197 |
cp_gtk_list_init_jni (); |
cp_gtk_list_init_jni (); |
198 |
cp_gtk_menuitem_init_jni (); |
cp_gtk_menuitem_init_jni (); |
199 |
cp_gtk_scrollbar_init_jni (); |
cp_gtk_scrollbar_init_jni (); |
296 |
PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); |
PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); |
297 |
} |
} |
298 |
|
|
|
static int |
|
|
within_human_latency_tolerance(struct timeval *init) |
|
|
{ |
|
|
struct timeval curr; |
|
|
unsigned long milliseconds_elapsed; |
|
|
|
|
|
gettimeofday(&curr, NULL); |
|
|
|
|
|
milliseconds_elapsed = (((curr.tv_sec * 1000) + (curr.tv_usec / 1000)) |
|
|
- ((init->tv_sec * 1000) + (init->tv_usec / 1000))); |
|
|
|
|
|
return milliseconds_elapsed < 100; |
|
|
} |
|
|
|
|
299 |
#if GTK_MINOR_VERSION > 4 |
#if GTK_MINOR_VERSION > 4 |
300 |
static void |
static void |
301 |
glog_func (const gchar *log_domain, |
glog_func (const gchar *log_domain, |
322 |
} |
} |
323 |
#endif |
#endif |
324 |
|
|
325 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
326 |
Java_gnu_java_awt_peer_gtk_GtkToolkit_iterateNativeQueue |
Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain |
327 |
(JNIEnv *env, |
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) |
|
jobject self __attribute__((unused)), |
|
|
jobject lockedQueue, |
|
|
jboolean block) |
|
|
{ |
|
|
/* We're holding an EventQueue lock, and we're about to acquire the GDK |
|
|
* lock before dropping the EventQueue lock. This can deadlock if someone |
|
|
* holds the GDK lock and wants to acquire the EventQueue lock; however |
|
|
* all callbacks from GTK happen with the GDK lock released, so this |
|
|
* would only happen in an odd case such as some JNI helper code |
|
|
* acquiring the GDK lock and calling back into |
|
|
* EventQueue.getNextEvent(). |
|
|
*/ |
|
|
|
|
|
struct timeval init; |
|
|
gettimeofday(&init, NULL); |
|
|
|
|
|
gdk_threads_enter (); |
|
|
(*env)->MonitorExit (env, lockedQueue); |
|
|
|
|
|
if (block) |
|
|
{ |
|
|
|
|
|
/* If we're blocking-when-empty, we want a do .. while loop. */ |
|
|
do |
|
|
gtk_main_iteration (); |
|
|
while (within_human_latency_tolerance (&init) |
|
|
&& gtk_events_pending ()); |
|
|
} |
|
|
else |
|
|
{ |
|
|
/* If we're not blocking-when-empty, we want a while loop. */ |
|
|
while (within_human_latency_tolerance (&init) |
|
|
&& gtk_events_pending ()) |
|
|
gtk_main_iteration (); |
|
|
} |
|
|
|
|
|
(*env)->MonitorEnter (env, lockedQueue); |
|
|
gdk_threads_leave (); |
|
|
} |
|
|
|
|
|
JNIEXPORT void JNICALL |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_wakeNativeQueue |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) |
|
|
{ |
|
|
g_main_context_wakeup (NULL); |
|
|
} |
|
|
|
|
|
JNIEXPORT jboolean JNICALL |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_nativeQueueEmpty |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) |
|
328 |
{ |
{ |
|
jboolean empty = FALSE; |
|
|
|
|
329 |
gdk_threads_enter (); |
gdk_threads_enter (); |
330 |
|
|
331 |
empty = ! gtk_events_pending(); |
gtk_main (); |
332 |
|
|
333 |
gdk_threads_leave (); |
gdk_threads_leave (); |
|
|
|
|
return empty; |
|
334 |
} |
} |
335 |
|
|
336 |
|
|
402 |
jint *colors; |
jint *colors; |
403 |
GtkStyle *style; |
GtkStyle *style; |
404 |
|
|
405 |
|
/* FIXME: this was deadlocking so assume it is thread-safe for now; |
406 |
|
we need to replace this call with a .properties file anyway. */ |
407 |
|
#if 0 |
408 |
gdk_threads_enter (); |
gdk_threads_enter (); |
409 |
|
#endif |
410 |
|
|
411 |
colors = (*env)->GetIntArrayElements (env, jcolors, 0); |
colors = (*env)->GetIntArrayElements (env, jcolors, 0); |
412 |
|
|
441 |
|
|
442 |
(*env)->ReleaseIntArrayElements(env, jcolors, colors, 0); |
(*env)->ReleaseIntArrayElements(env, jcolors, colors, 0); |
443 |
|
|
444 |
|
#if 0 |
445 |
gdk_threads_leave (); |
gdk_threads_leave (); |
446 |
|
#endif |
447 |
} |
} |
448 |
|
|
449 |
#undef CONVERT |
#undef CONVERT |