/[classpath]/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
ViewVC logotype

Diff of /classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7.2.8 by gnu_andrew, Tue Aug 2 20:12:40 2005 UTC revision 1.7.2.9 by gnu_andrew, Sat Sep 10 15:32:01 2005 UTC
# Line 40  exception statement from your version. * Line 40  exception statement from your version. *
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    
# Line 157  Java_gnu_java_awt_peer_gtk_GtkToolkit_gt Line 156  Java_gnu_java_awt_peer_gtk_GtkToolkit_gt
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 ());
# Line 190  Java_gnu_java_awt_peer_gtk_GtkToolkit_gt Line 193  Java_gnu_java_awt_peer_gtk_GtkToolkit_gt
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 ();
# Line 292  dpi_changed_cb (GtkSettings  *settings, Line 296  dpi_changed_cb (GtkSettings  *settings,
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,
# Line 332  glog_func (const gchar *log_domain, Line 322  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    
# Line 466  Java_gnu_java_awt_peer_gtk_GtkToolkit_lo Line 402  Java_gnu_java_awt_peer_gtk_GtkToolkit_lo
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    
# Line 501  Java_gnu_java_awt_peer_gtk_GtkToolkit_lo Line 441  Java_gnu_java_awt_peer_gtk_GtkToolkit_lo
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

Legend:
Removed from v.1.7.2.8  
changed lines
  Added in v.1.7.2.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26