diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java | 7 | ||||
-rw-r--r-- | src/newt/native/drm_gbm.c | 47 | ||||
-rw-r--r-- | src/newt/native/drm_gbm_legacy.c | 9 |
3 files changed, 60 insertions, 3 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java index a7fa29170..335da25ca 100644 --- a/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java +++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java @@ -35,6 +35,7 @@ import com.jogamp.common.nio.Buffers; import com.jogamp.common.util.IOUtil; import com.jogamp.nativewindow.AbstractGraphicsDevice; import com.jogamp.nativewindow.NativeWindowException; +import com.jogamp.nativewindow.NativeWindowFactory; import com.jogamp.nativewindow.util.PixelFormat; import com.jogamp.newt.Display; import com.jogamp.opengl.GLProfile; @@ -61,6 +62,11 @@ public class DisplayDriver extends DisplayImpl { if (!WindowDriver.initIDs()) { throw new NativeWindowException("Failed to initialize egl.gbm Window jmethodIDs"); } + NativeWindowFactory.addCustomShutdownHook(false /* head */, new Runnable() { + @Override + public void run() { + Shutdown0(); + } }); PNGPixelRect image = null; if( DisplayImpl.isPNGUtilAvailable() ) { @@ -171,6 +177,7 @@ public class DisplayDriver extends DisplayImpl { } private static native boolean initIDs(); + private static native void Shutdown0(); private static native void DispatchMessages0(); diff --git a/src/newt/native/drm_gbm.c b/src/newt/native/drm_gbm.c index 7fb6ad2c8..a6c9a3f9a 100644 --- a/src/newt/native/drm_gbm.c +++ b/src/newt/native/drm_gbm.c @@ -27,6 +27,8 @@ */ #include "drm_gbm.h" +#include <unistd.h> +#include <termios.h> static jmethodID sizeChangedID = NULL; static jmethodID positionChangedID = NULL; @@ -37,13 +39,58 @@ static jmethodID windowDestroyNotifyID = NULL; * Display */ +static int saved_stdin; + +static void setNullStdin() +{ + saved_stdin = dup(fileno(stdin)); + if( 0 > saved_stdin ) { + ERR_PRINT("setNullStdin dup failed: %d %s\n", saved_stdin, strerror(errno)); + return; + } + freopen("/dev/null", "r", stdin); // fake null stdin, closes stdin + DBG_PRINT("setNullStdin done\n"); +} + +static void restoreStdin() +{ + int null_stdin = dup(fileno(stdin)); // copy to close after restore + if( 0 > null_stdin ) { + ERR_PRINT("restoreStdin.1 dup failed: %d %s\n", null_stdin, strerror(errno)); + return; + } + // restore + int restored_stdin = dup2(saved_stdin, fileno(stdin)); + if( 0 > restored_stdin ) { + ERR_PRINT("restoreStdin.2 dup2 failed: %d %s\n", restored_stdin, strerror(errno)); + return; + } + saved_stdin = -1; + + // cleanup stdin before it gets executed on the console + tcdrain(restored_stdin); + tcflush(restored_stdin, TCIFLUSH); + + close(null_stdin); // close fake null stdin + close(restored_stdin); + DBG_PRINT("restoreStdin done\n"); +} + JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_initIDs (JNIEnv *env, jclass clazz) { + setNullStdin(); DBG_PRINT( "EGL_GBM.Display initIDs ok\n" ); return JNI_TRUE; } +JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_Shutdown0 + (JNIEnv *env, jclass clazz) +{ + restoreStdin(); + DBG_PRINT( "EGL_GBM.Display shutdown ok\n" ); +} + JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_DispatchMessages0 (JNIEnv *env, jclass clazz) { diff --git a/src/newt/native/drm_gbm_legacy.c b/src/newt/native/drm_gbm_legacy.c index 1aa8d5f82..cec3297a8 100644 --- a/src/newt/native/drm_gbm_legacy.c +++ b/src/newt/native/drm_gbm_legacy.c @@ -286,7 +286,9 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_NextSwapSur while (waiting_for_flip) { FD_ZERO(&fds); - FD_SET(0, &fds); +#if 0 + FD_SET(0, &fds); // STDIN_FILENO: We don't want to listen to +#endif FD_SET(drmFd, &fds); ret = select(drmFd + 1, &fds, NULL, NULL, NULL); @@ -296,9 +298,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_NextSwapSur } else if (ret == 0) { ERR_PRINT("drm.select: select timeout!\n"); return -1; +#if 0 } else if (FD_ISSET(0, &fds)) { - ERR_PRINT("drm.select: user interrupted!\n"); - return 0; + DBG_PRINT("drm.select: stdin carriage return pressed!\n"); +#endif } drmHandleEvent(drmFd, &drm_event_ctx); } |