diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/util/MainThread.java | 31 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java | 4 | ||||
-rw-r--r-- | src/newt/native/MacWindow.m | 44 |
3 files changed, 70 insertions, 9 deletions
diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index c7780b0d8..b1862834c 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -93,6 +93,9 @@ import jogamp.newt.NEWTJNILibLoader; */ public class MainThread { private static final String MACOSXDisplayClassName = "jogamp.newt.driver.macosx.MacDisplay"; + private static final Platform.OSType osType; + private static final boolean isMacOSX; + /** if true, use the main thread EDT, otherwise AWT's EDT */ public static final boolean HINT_USE_MAIN_THREAD; @@ -103,7 +106,9 @@ public class MainThread { NativeWindowFactory.initSingleton(true); NEWTJNILibLoader.loadNEWT(); HINT_USE_MAIN_THREAD = !NativeWindowFactory.isAWTAvailable() || - Debug.getBooleanProperty("newt.MainThread.force", true, localACC); + Debug.getBooleanProperty("newt.MainThread.force", true, localACC); + osType = Platform.getOSType(); + isMacOSX = osType == Platform.OSType.MACOS; } public static boolean useMainThread = false; @@ -132,7 +137,7 @@ public class MainThread { try { Class<?> mainClass = ReflectionUtil.getClass(mainClassName, true, getClass().getClassLoader()); if(null==mainClass) { - throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); + throw new RuntimeException(new ClassNotFoundException("MainAction couldn't find main class "+mainClassName)); } try { mainClassMain = mainClass.getDeclaredMethod("main", new Class[] { String[].class }); @@ -151,8 +156,23 @@ public class MainThread { if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin"); if ( useMainThread ) { - if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainThread fin - stop"); - System.exit(0); + if(isMacOSX) { + try { + if(DEBUG) { + System.err.println("MainAction.main(): "+Thread.currentThread()+" MainAction fin - stopNSApp.0"); + } + ReflectionUtil.callStaticMethod(MACOSXDisplayClassName, "stopNSApplication", + null, null, MainThread.class.getClassLoader()); + if(DEBUG) { + System.err.println("MainAction.main(): "+Thread.currentThread()+" MainAction fin - stopNSApp.X"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else { + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainAction fin - System.exit(0)"); + System.exit(0); + } } } } @@ -164,9 +184,6 @@ public class MainThread { useMainThread = HINT_USE_MAIN_THREAD; - final Platform.OSType osType = Platform.getOSType(); - final boolean isMacOSX = osType == Platform.OSType.MACOS; - if(DEBUG) { System.err.println("MainThread.main(): "+cur.getName()+ ", useMainThread "+ useMainThread + diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java b/src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java index 527fdac6d..2ac98f255 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java @@ -72,8 +72,12 @@ public class MacDisplay extends DisplayImpl { public static void runNSApplication() { runNSApplication0(); } + public static void stopNSApplication() { + stopNSApplication0(); + } private static native boolean initNSApplication0(); private static native void runNSApplication0(); + private static native void stopNSApplication0(); } diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 0d63b6522..e39ff0310 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -191,13 +191,50 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_macosx_MacDisplay_initNSAppli JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacDisplay_runNSApplication0 (JNIEnv *env, jclass clazz) { - // NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; DBG_PRINT( "\nrunNSApplication0.0\n"); [NSApp run]; DBG_PRINT( "\nrunNSApplication0.X\n"); - // [pool release]; + [pool release]; +} + +/* + * Class: jogamp_newt_driver_macosx_MacDisplay + * Method: stopNSApplication0 + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacDisplay_stopNSApplication0 + (JNIEnv *env, jclass clazz) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + DBG_PRINT( "\nstopNSApplication0.0 nsApp.running %d\n", (NSApp && [NSApp isRunning])); + + if(NSApp && [NSApp isRunning]) { + [NSApp performSelectorOnMainThread:@selector(stop:) withObject:nil waitUntilDone:YES]; + // [NSApp stop: nil]; + NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined + location: NSMakePoint(0,0) + modifierFlags: 0 + timestamp: 0.0 + windowNumber: 0 + context: nil + subtype: 0 + data1: 0 + data2: 0]; + DBG_PRINT( "\nstopNSApplication0.1\n"); + [NSApp postEvent: event atStart: true]; + } + /** + DBG_PRINT( "\nstopNSApplication0.2\n"); + if(NSApp && [NSApp isRunning]) { + DBG_PRINT( "\nstopNSApplication0.3\n"); + [NSApp terminate:nil]; + } */ + + DBG_PRINT( "\nstopNSApplication0.X\n"); + [pool release]; } /* @@ -443,6 +480,8 @@ NS_DURING if([mView isInFullScreenMode]) { [mView exitFullScreenModeWithOptions: NULL]; } + [mWin setContentView: nil]; + [mView release]; } NS_HANDLER NS_ENDHANDLER @@ -450,6 +489,7 @@ NS_ENDHANDLER if(NULL!=pWin) { [mWin detachFromParent: pWin]; } + [mWin orderOut: mWin]; DBG_PRINT( "windowClose.1 - %p,%d view %p,%d, parent %p\n", mWin, getRetainCount(mWin), mView, getRetainCount(mView), pWin); |