aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java9
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java27
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java42
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java5
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java14
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Window.java8
6 files changed, 77 insertions, 28 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java
index a052f6f97..82562636b 100755
--- a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java
+++ b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java
@@ -36,6 +36,7 @@ import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import javax.media.nativewindow.WindowClosingProtocol;
import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
@@ -64,7 +65,7 @@ import com.jogamp.newt.opengl.GLWindow;
* </p>
*
* <p>
- * Example of an applet tag using GearsES2 in an undecorated, translucent and always-on-top window:
+ * Example of an applet tag using GearsES2 in an undecorated, translucent, closeable and always-on-top window:
* <pre>
&lt;applet width=1 height=1&gt;
&lt;param name="java_arguments" value="-Dsun.java2d.noddraw=true"&gt;
@@ -73,6 +74,7 @@ import com.jogamp.newt.opengl.GLWindow;
&lt;param name="gl_swap_interval" value="1"&gt;
&lt;param name="gl_undecorated" value="true"&gt;
&lt;param name="gl_alwaysontop" value="true"&gt;
+ &lt;param name="gl_closeable" value="true"&gt;
&lt;param name="gl_alpha" value="1"&gt;
&lt;param name="gl_multisamplebuffer" value="0"&gt;
&lt;param name="gl_opaque" value="false"&gt;
@@ -115,6 +117,7 @@ public class JOGLNewtApplet1Run extends Applet {
boolean glTrace=false;
boolean glUndecorated=false;
boolean glAlwaysOnTop=false;
+ boolean glCloseable=false;
boolean glOpaque=true;
int glAlphaBits=0;
int glNumMultisampleBuffer=0;
@@ -128,6 +131,7 @@ public class JOGLNewtApplet1Run extends Applet {
glTrace = JOGLNewtAppletBase.str2Bool(getParameter("gl_trace"), glTrace);
glUndecorated = JOGLNewtAppletBase.str2Bool(getParameter("gl_undecorated"), glUndecorated);
glAlwaysOnTop = JOGLNewtAppletBase.str2Bool(getParameter("gl_alwaysontop"), glAlwaysOnTop);
+ glCloseable = JOGLNewtAppletBase.str2Bool(getParameter("gl_closeable"), glCloseable);
glOpaque = JOGLNewtAppletBase.str2Bool(getParameter("gl_opaque"), glOpaque);
glAlphaBits = JOGLNewtAppletBase.str2Int(getParameter("gl_alpha"), glAlphaBits);
glNumMultisampleBuffer = JOGLNewtAppletBase.str2Int(getParameter("gl_multisamplebuffer"), glNumMultisampleBuffer);
@@ -157,6 +161,7 @@ public class JOGLNewtApplet1Run extends Applet {
System.err.println("glTrace: "+glTrace);
System.err.println("glUndecorated: "+glUndecorated);
System.err.println("glAlwaysOnTop: "+glAlwaysOnTop);
+ System.err.println("glCloseable: "+glCloseable);
System.err.println("glOpaque: "+glOpaque);
System.err.println("glAlphaBits: "+glAlphaBits);
System.err.println("glNumMultisampleBuffer: "+glNumMultisampleBuffer);
@@ -166,6 +171,7 @@ public class JOGLNewtApplet1Run extends Applet {
base = new JOGLNewtAppletBase(glEventListenerClazzName,
glSwapInterval,
glNoDefaultKeyListener,
+ glCloseable,
glDebug,
glTrace);
@@ -181,6 +187,7 @@ public class JOGLNewtApplet1Run extends Applet {
glWindow.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
glWindow.setUndecorated(glUndecorated);
glWindow.setAlwaysOnTop(glAlwaysOnTop);
+ glWindow.setDefaultCloseOperation(glCloseable ? WindowClosingProtocol.DISPOSE_ON_CLOSE : WindowClosingProtocol.DO_NOTHING_ON_CLOSE);
container.setLayout(new BorderLayout());
if(appletDebugTestBorder) {
container.add(new Button("North"), BorderLayout.NORTH);
diff --git a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java
index 67da50210..9ffc24372 100755
--- a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java
+++ b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java
@@ -32,6 +32,7 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.WindowClosingProtocol;
import javax.media.opengl.FPSCounter;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
@@ -43,8 +44,10 @@ import jogamp.newt.Debug;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.event.WindowListener;
+import com.jogamp.newt.event.WindowUpdateEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.Animator;
@@ -58,6 +61,7 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
String glEventListenerClazzName;
int glSwapInterval;
boolean noDefaultKeyListener;
+ boolean glClosable;
boolean glDebug;
boolean glTrace;
@@ -70,12 +74,14 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
public JOGLNewtAppletBase(String glEventListenerClazzName,
int glSwapInterval,
boolean noDefaultKeyListener,
+ boolean glClosable,
boolean glDebug,
boolean glTrace) {
this.glEventListenerClazzName=glEventListenerClazzName;
this.glSwapInterval=glSwapInterval;
this.noDefaultKeyListener = noDefaultKeyListener;
+ this.glClosable = glClosable;
this.glDebug = glDebug;
this.glTrace = glTrace;
}
@@ -152,9 +158,25 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
init(Thread.currentThread().getThreadGroup(), glWindow);
}
- public void init(ThreadGroup tg, GLWindow glWindow) {
+ public void init(ThreadGroup tg, final GLWindow glWindow) {
isValid = false;
this.glWindow = glWindow;
+ this.glWindow.addWindowListener(new WindowAdapter() {
+ // Closing action: back to parent!
+ @Override
+ public void windowDestroyNotify(WindowEvent e) {
+ if( WindowClosingProtocol.DO_NOTHING_ON_CLOSE == glWindow.getDefaultCloseOperation() ) {
+ if(null == glWindow.getParent()) {
+ // we may be called directly by the native EDT
+ new Thread(new Runnable() {
+ public void run() {
+ // try { Thread.sleep(10); } catch (InterruptedException e) { }
+ glWindow.reparentWindow(awtParent);
+ }
+ }).start();
+ }
+ }
+ } } );
glEventListener = createInstance(glEventListenerClazzName);
if(null == glEventListener) {
@@ -277,6 +299,9 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
glWindow.reparentWindow(awtParent);
} else {
glWindow.reparentWindow(null);
+ if(glClosable) {
+ glWindow.setDefaultCloseOperation(WindowClosingProtocol.DISPOSE_ON_CLOSE);
+ }
}
}
}
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 3d465e45c..5e393f7c5 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -66,6 +66,7 @@ import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.SurfaceUpdatedListener;
+import javax.media.nativewindow.WindowClosingProtocol;
import javax.media.nativewindow.util.DimensionImmutable;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.InsetsImmutable;
@@ -428,12 +429,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
* The implementation should invoke the referenced java state callbacks
* to notify this Java object of state changes.</p>
*
- * @see #windowDestroyNotify()
+ * @see #windowDestroyNotify(boolean)
* @see #focusChanged(boolean, boolean)
* @see #visibleChanged(boolean, boolean)
* @see #sizeChanged(int,int)
* @see #positionChanged(boolean,int, int)
- * @see #windowDestroyNotify()
+ * @see #windowDestroyNotify(boolean)
*/
protected abstract void createNativeImpl();
@@ -908,16 +909,18 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
System.err.println("Window.destroy() END "+getThreadName()/*+", "+WindowImpl.this*/);
}
} finally {
+ // update states before release window lock
+ setWindowHandle(0);
+ visible = false;
+ fullscreen = false;
+ hasFocus = false;
+ parentWindowHandle = 0;
+
windowLock.unlock();
}
if(animatorPaused) {
lifecycleHook.resumeRenderingAction();
}
- setWindowHandle(0);
- visible = false;
- fullscreen = false;
- hasFocus = false;
- parentWindowHandle = 0;
// these refs shall be kept alive - resurrection via setVisible(true)
/**
@@ -1525,8 +1528,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
/**
* If set to true, the default value, this NEWT Window implementation will
- * handle the destruction (ie {@link #destroy()} call) within {@link #windowDestroyNotify()} implementation.<br>
- * If set to false, it's up to the caller/owner to handle destruction within {@link #windowDestroyNotify()}.
+ * handle the destruction (ie {@link #destroy()} call) within {@link #windowDestroyNotify(boolean)} implementation.<br>
+ * If set to false, it's up to the caller/owner to handle destruction within {@link #windowDestroyNotify(boolean)}.
*/
public void setHandleDestroyNotify(boolean b) {
handleDestroyNotify = b;
@@ -2498,21 +2501,34 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
- protected void windowDestroyNotify() {
+ /**
+ * Triggered by implementation's WM events or programmatically
+ *
+ * @param force if true, overrides {@link #setDefaultCloseOperation(int)} with {@link WindowClosingProtocol#DISPOSE_ON_CLOSE}
+ * and hence force destruction. Otherwise is follows the user settings.
+ * @return true if this window is no more valid and hence has been destroyed, otherwise false.
+ */
+ protected boolean windowDestroyNotify(boolean force) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.windowDestroyNotify START "+getThreadName());
+ System.err.println("Window.windowDestroyNotify(force: "+force+") START "+getThreadName()+": "+this);
+ }
+ if(force) {
+ setDefaultCloseOperation(WindowClosingProtocol.DISPOSE_ON_CLOSE);
}
// send synced destroy notifications
enqueueWindowEvent(true, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
- if(handleDestroyNotify && DISPOSE_ON_CLOSE == defaultCloseOperation) {
+ if(handleDestroyNotify && DISPOSE_ON_CLOSE == getDefaultCloseOperation()) {
destroy();
}
+
+ final boolean destroyed = !isNativeValid();
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.windowDestroyeNotify END "+getThreadName());
+ System.err.println("Window.windowDestroyNotify(force: "+force+") END "+getThreadName()+": destroyed "+destroyed+", "+this);
}
+ return destroyed;
}
public void windowRepaint(int x, int y, int width, int height) {
diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java
index 4547db831..63d5f7003 100644
--- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java
+++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java
@@ -329,8 +329,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 {
if(0!=surfaceHandle && androidFormat != aFormat ) {
// re-create
Log.d(MD.TAG, "surfaceChanged (destroy old)");
- windowDestroyNotify();
- if(isNativeValid()) {
+ if(!windowDestroyNotify(true)) {
destroy();
}
surfaceHandle = 0;
@@ -371,7 +370,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 {
public void surfaceDestroyed(SurfaceHolder holder) {
Log.d(MD.TAG, "surfaceDestroyed");
- windowDestroyNotify();
+ windowDestroyNotify(true); // actually too late .. however ..
}
public void surfaceRedrawNeeded(SurfaceHolder holder) {
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
index c926d44ee..b45c60e69 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
@@ -77,19 +77,19 @@ public class MacWindow extends WindowImpl implements SurfaceChangeable, DriverCl
protected void closeNativeImpl() {
try {
if(DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.CloseAction "+Thread.currentThread().getName()); }
- if (getWindowHandle() != 0) {
- close0(getWindowHandle());
+ final long handle = getWindowHandle();
+ setWindowHandle(0);
+ surfaceHandle = 0;
+ sscSurfaceHandle = 0;
+ isOffscreenInstance = false;
+ if (0 != handle) {
+ close0(handle);
}
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
Exception e = new Exception("Warning: closeNative failed - "+Thread.currentThread().getName(), t);
e.printStackTrace();
}
- } finally {
- setWindowHandle(0);
- surfaceHandle = 0;
- sscSurfaceHandle = 0;
- isOffscreenInstance = false;
}
}
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
index 703b18272..143b94a57 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
@@ -117,8 +117,10 @@ public class X11Window extends WindowImpl {
// client position -> top-level window position
x -= i.getLeftWidth() ;
y -= i.getTopHeight() ;
- }
- reconfigureWindow0( getDisplayEDTHandle(), getScreenIndex(), getParentWindowHandle(), getWindowHandle(),
+ }
+ final X11Display display = (X11Display) getScreen().getDisplay();
+ reconfigureWindow0( getDisplayEDTHandle(), getScreenIndex(),
+ getParentWindowHandle(), getWindowHandle(), display.getWindowDeleteAtom(),
x, y, width, height, flags);
return true;
@@ -243,7 +245,7 @@ public class X11Window extends WindowImpl {
int x, int y, int width, int height, boolean autoPosition, int flags);
private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
- int x, int y, int width, int height, int flags);
+ long windowDeleteAtom, int x, int y, int width, int height, int flags);
private native void requestFocus0(long display, long windowHandle, boolean force);
private static native void setTitle0(long display, long windowHandle, String title);