diff -r db324b2feaf3 glass/glass-mat-lib-gtk/src/com/sun/glass/ui/GlassApplication.cpp --- a/glass/glass-mat-lib-gtk/src/com/sun/glass/ui/GlassApplication.cpp Wed May 23 13:37:48 2012 +0200 +++ b/glass/glass-mat-lib-gtk/src/com/sun/glass/ui/GlassApplication.cpp Wed May 23 14:49:27 2012 +0200 @@ -201,31 +201,44 @@ /* * Class: com_sun_glass_ui_gtk_GtkApplication * Method: _runLoop - * Signature: ([Ljava/lang/String;Lcom/sun/glass/ui/Launchable;)V + * Signature: ([Ljava/lang/String;Lcom/sun/glass/ui/Launchable;Z)V */ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1runLoop - (JNIEnv * env, jobject obj, jobjectArray arguments, jobject launchable) + (JNIEnv * env, jobject obj, jobjectArray arguments, jobject launchable, jboolean embedded) { jclass jLaunchable = env->FindClass("com/sun/glass/ui/Launchable"); jmethodID jLaunchableFinishLaunching = env->GetMethodID(jLaunchable, "finishLaunching", "([Ljava/lang/String;)V"); env->CallVoidMethod(launchable, jLaunchableFinishLaunching, arguments); CHECK_JNI_EXCEPTION(env); - // GTK installs its own X error handler that conflicts with AWT. - // During drag and drop, AWT hides errors so we need to hide them - // to avoid exit()'ing. It's not clear that we don't want to hide - // X error all the time, otherwise FX will exit(). - // - // A better solution would be to coordinate with AWT and save and - // restore the X handler. + if (embedded) { + // GTK installs its own X error handler that conflicts with AWT. + // During drag and drop, AWT hides errors so we need to hide them + // to avoid exit()'ing. It's not clear that we don't want to hide + // X error all the time, otherwise FX will exit(). + // + // A better solution would be to coordinate with AWT and save and + // restore the X handler. + // - // Disable X error handling - gdk_error_trap_push(); - + // Disable X error handling +#ifndef VERBOSE + gdk_error_trap_push(); +#endif + } gtk_main(); + //// When the last JFrame closes and DISPOSE_ON_CLOSE is specified, + // Java exits with an X error. X error are hidden during the FX + // event loop and should be restored when the event loop exits. Unfortunately, + // this is too early. The fix is to never restore X errors. + // + // See RT-21408 & RT-20756 + // Restore X error handling - gdk_error_trap_pop(); +// if (embedded) { +// gdk_error_trap_pop(); +// } gdk_threads_leave(); diff -r db324b2feaf3 glass/glass-mat/src/com/sun/glass/ui/gtk/GtkApplication.java --- a/glass/glass-mat/src/com/sun/glass/ui/gtk/GtkApplication.java Wed May 23 13:37:48 2012 +0200 +++ b/glass/glass-mat/src/com/sun/glass/ui/gtk/GtkApplication.java Wed May 23 14:49:27 2012 +0200 @@ -49,14 +49,22 @@ } protected void runLoop(final String args[], final Launchable launchable) { - boolean isEventThread = AccessController + final boolean isEventThread = AccessController .doPrivileged(new PrivilegedAction() { public Boolean run() { - Boolean result = Boolean.getBoolean("javafx.embed.isEventThread"); - return result == null ? false : result.booleanValue(); + // Embedded in SWT, with shared event thread + return Boolean.getBoolean("javafx.embed.isEventThread"); } }); - + + final boolean isEmbedded = AccessController + .doPrivileged(new PrivilegedAction() { + public Boolean run() { + // Embedded in Swing + return Boolean.getBoolean("javafx.macosx.embedded"); + } + }); + if (isEventThread) { init(); setEventThread(Thread.currentThread()); @@ -71,7 +79,7 @@ Thread th = new Thread(new Runnable() { public void run() { init(); - _runLoop(args, launchable); + _runLoop(args, launchable, isEmbedded); } }, "GtkNativeMainLoopThread"); @@ -100,7 +108,7 @@ private native void _init(); - protected native void _runLoop(String[] args, Launchable launchable); + protected native void _runLoop(String[] args, Launchable launchable, boolean embedded); @Override protected native void _invokeAndWait(Runnable runnable);