aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-10-21 04:24:06 +0200
committerSven Gothel <[email protected]>2010-10-21 04:24:06 +0200
commit18bf27fa86da1f26fd085565f501736816d2f2e9 (patch)
treeca44458e4bb00b7969b77473ad93cd826c5ca6a7 /src/newt/classes/com/jogamp
parent6da90f18da639f942bce9dec7fdd9a6c43e22145 (diff)
NEWT: Fix / Stabilize Fullscreen/Decoration/Reparenting Mode Changes
- setSizeImpl/setPositionImpl/reparent -> reconfigureWindowImpl - setVisible(boolean) is state checked (500ms) for better reliability on resource creation. Guarantees valid surface. - reparentWindow: start pos of child -> top is current position on screen - reparentWindow: Recheck success (setVisible), if failed fall back to recreate, which gets rid of a lost child windows (1/20) .. - reparentWindow: if size failed, reconfigure for size again - add toggle decoration - unify nfs_ size/pos state - WindowsWindow.c/X11Window.c: Unify size/pos settings - X11Window.c: - NewtWindows_setFullscreen: use 'root of screen' instead of 'default root of display' - Adding SubstructureNotifyMask incl event semantics - Parse ReparentNotify (debugging of reparenting) Misc: - Add native getLocationOnScreen() impl to avoid possible AWT deadlock - setSize/setPosition/setFullScreen -> EDT - More documentation on expected native implementation semantics
Diffstat (limited to 'src/newt/classes/com/jogamp')
-rw-r--r--src/newt/classes/com/jogamp/newt/Window.java3
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java22
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/WindowImpl.java574
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java52
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java50
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java55
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java39
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java47
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java70
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java74
10 files changed, 607 insertions, 379 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 4bdcd67a4..7e1a55b21 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -48,6 +48,9 @@ public interface Window extends NativeWindow {
public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent");
public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window");
+ /** A 500ms timeout while waiting for a native action response, ie {@link #setVisible(boolean)}. */
+ public static final long TIMEOUT_NATIVEWINDOW = 500;
+
//
// Lifecycle
//
diff --git a/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java b/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java
index 95c326ce4..f3c7b8415 100644
--- a/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java
@@ -86,7 +86,9 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable {
return surfaceHandle;
}
- protected void setVisibleImpl(boolean visible) {
+ protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
+ sizeChanged(width, height, false);
+ visibleChanged(visible);
}
protected void requestFocusImpl(boolean reparented) {
@@ -94,27 +96,19 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable {
public void setSize(int width, int height) {
if(!visible) {
- this.width = width;
- this.height = height;
+ sizeChanged(width, height, false);
}
}
- protected void setSizeImpl(int width, int height) {
- shouldNotCallThis();
- }
-
public void setPosition(int x, int y) {
// nop
}
- protected void setPositionImpl(int x, int y) {
- shouldNotCallThis();
- }
-
public boolean setFullscreen(boolean fullscreen) {
// nop
return false;
}
- protected void reconfigureWindowImpl(int x, int y, int width, int height) {
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, boolean parentChange, int fullScreenChange, int decorationChange) {
shouldNotCallThis();
+ return false;
}
public Point getLocationOnScreen(Point storage) {
@@ -125,5 +119,9 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable {
}
return new Point(0,0);
}
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
+ }
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
index a0879a634..631c1b1c0 100644
--- a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
+++ b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
@@ -171,12 +171,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
protected Capabilities caps;
protected boolean fullscreen, visible, hasFocus;
protected int width, height, x, y;
-
- // non fullscreen dimensions ..
- protected int nfs_width, nfs_height, nfs_x, nfs_y;
+ protected int nfs_width, nfs_height, nfs_x, nfs_y; // non fullscreen dimensions ..
protected String title = "Newt Window";
protected boolean undecorated = false;
+ private boolean handleDestroyNotify = true;
private final void destroyScreen() {
screenReferenced = false;
@@ -194,9 +193,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
private boolean createNative() {
- if( null==screen || 0!=windowHandle || !visible ) {
- return 0 != windowHandle ;
- }
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")");
}
@@ -211,7 +207,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
screen.addReference();
}
createNativeImpl();
- setVisibleImpl(true);
+ setVisibleImpl(true, x, y, width, height);
}
} finally {
if(null!=parentWindow) {
@@ -271,22 +267,68 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// Window: Native implementation
//
+ /**
+ * The native implementation must set the native windowHandle.<br>
+ *
+ * The implementation should invoke the referenced java state callbacks
+ * to notify this Java object of state changes.
+ *
+ * @see #windowDestroyNotify()
+ * @see #focusChanged(boolean)
+ * @see #visibleChanged(boolean)
+ * @see #sizeChanged(int,int)
+ * @see #positionChanged(int,int)
+ * @see #windowDestroyNotify()
+ */
protected abstract void createNativeImpl();
protected abstract void closeNativeImpl();
- protected abstract void requestFocusImpl(boolean reparented);
-
- protected abstract void setVisibleImpl(boolean visible);
-
- protected abstract void setSizeImpl(int width, int height);
+ /**
+ * The native implementation must invoke {@link #focusChanged(boolean)}
+ * to change the focus state, if <code>force == false</code>.
+ * This may happen asynchronous within {@link #TIMEOUT_NATIVEWINDOW}.
+ *
+ * @param force if true, bypass {@link #focusChanged(boolean)} and force focus request
+ */
+ protected abstract void requestFocusImpl(boolean force);
- protected abstract void setPositionImpl(int x, int y);
+ /**
+ * The native implementation must invoke {@link #visibleChanged(boolean)}
+ * to change the visibility state. This may happen asynchronous within
+ * {@link #TIMEOUT_NATIVEWINDOW}.
+ */
+ protected abstract void setVisibleImpl(boolean visible, int x, int y, int width, int height);
- protected abstract void reconfigureWindowImpl(int x, int y, int width, int height);
+ /**
+ * The native implementation should invoke the referenced java state callbacks
+ * to notify this Java object of state changes.
+ *
+ * @param x -1 if no position change requested, otherwise greater than zero
+ * @param y -1 if no position change requested, otherwise greater than zero
+ * @param width -1 if no size change requested, otherwise greater than zero
+ * @param height -1 if no size change requested, otherwise greater than zero
+ * @param parentChange true if reparenting requested, otherwise false
+ * @param fullScreenChange 0 if unchanged, -1 fullscreen off, 1 fullscreen on
+ * @param decorationChange 0 if unchanged, -1 undecorated, 1 decorated
+ *
+ * @see #sizeChanged(int,int)
+ * @see #positionChanged(int,int)
+ */
+ protected abstract boolean reconfigureWindowImpl(int x, int y, int width, int height,
+ boolean parentChange, int fullScreenChange, int decorationChange);
protected void setTitleImpl(String title) {}
+ /**
+ * Return screen coordinates of the given coordinates
+ * or null, in which case a NativeWindow traversal shall being used
+ * as demonstrated in {@link #getLocationOnScreen(javax.media.nativewindow.util.Point)}.
+ *
+ * @return if not null, the screen location of the given coordinates
+ */
+ protected abstract Point getLocationOnScreenImpl(int x, int y);
+
//----------------------------------------------------------------------
// NativeSurface
//
@@ -371,12 +413,31 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
public Point getLocationOnScreen(Point storage) {
+ if(isNativeValid()) {
+ Point d;
+ windowLock.lock();
+ try {
+ d = getLocationOnScreenImpl(0, 0);
+ } finally {
+ windowLock.unlock();
+ }
+ if(null!=d) {
+ if(null!=storage) {
+ storage.translate(d.getX(),d.getY());
+ return storage;
+ }
+ return d;
+ }
+ // fall through intended ..
+ }
+
if(null!=storage) {
storage.translate(getX(),getY());
} else {
storage = new Point(getX(),getY());
}
if(null!=parentWindow) {
+ // traverse through parent list ..
parentWindow.getLocationOnScreen(storage);
}
return storage;
@@ -398,27 +459,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return screen;
}
- public void setVisible(boolean visible) {
- if(isValid()) {
- if( 0==windowHandle && visible && 0>=width*height ) {
- // fast-path: not realized yet, make visible, but zero size
- return;
- }
- VisibleAction va = new VisibleAction(visible);
- runOnEDTIfAvail(true, va);
- if( va.getChanged() ) {
- sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
- }
-
- }
- }
-
class VisibleAction implements Runnable {
boolean visible;
boolean nativeWindowCreated;
boolean madeVisible;
- public VisibleAction(boolean visible) {
+ public VisibleAction (boolean visible) {
this.visible = visible;
this.nativeWindowCreated = false;
this.madeVisible = false;
@@ -446,14 +492,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
if(0==windowHandle && visible) {
- WindowImpl.this.visible = visible;
if( 0<width*height ) {
nativeWindowCreated = createNative();
+ WindowImpl.this.waitForVisible(visible, true);
+ madeVisible = visible;
}
} else if(WindowImpl.this.visible != visible) {
- WindowImpl.this.visible = visible;
if(0 != windowHandle) {
- setVisibleImpl(visible);
+ setVisibleImpl(visible, x, y, width, height);
+ WindowImpl.this.waitForVisible(visible, true);
madeVisible = visible;
}
}
@@ -481,58 +528,78 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
- public void setSize(int width, int height) {
- int visibleAction = 0; // 1 invisible, 2 visible
- windowLock.lock();
- try{
- if ( !fullscreen && ( width != this.width || this.height != height ) ) {
- if(DEBUG_IMPLEMENTATION) {
- String msg = new String("Window setSize: START "+this.width+"x"+this.height+" -> "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible "+visible);
- System.err.println(msg);
- }
- nfs_width=width;
- nfs_height=height;
- if ( 0 != windowHandle && 0>=width*height && visible ) {
- visibleAction=1; // invisible
- this.width = 0;
- this.height = 0;
- } else if ( 0 == windowHandle && 0<width*height && visible ) {
- visibleAction = 2; // visible
- this.width = width;
- this.height = height;
- } else if ( 0 != windowHandle ) {
- // this width/height will be set by windowChanged, called by the native implementation
- setSizeImpl(width, height);
- } else {
- this.width = width;
- this.height = height;
- }
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window setSize: END "+this.width+"x"+this.height+", visibleAction "+visibleAction);
- }
+ public void setVisible(boolean visible) {
+ if(isValid()) {
+ if( 0==windowHandle && visible && 0>=width*height ) {
+ // fast-path: not realized yet, make visible, but zero size
+ return;
}
- } finally {
- windowLock.unlock();
+ VisibleAction visibleAction = new VisibleAction(visible);
+ runOnEDTIfAvail(true, visibleAction);
+ if( visibleAction.getChanged() ) {
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
+ }
+ }
+ }
+
+ class SetSizeActionImpl implements Runnable {
+ int visibleAction = 0; // 1 invisible, 2 visible (create)
+ int width, height;
+
+ public int getVisibleAction() {
+ return visibleAction;
}
- if(visibleAction>0) {
- setVisible( ( 1 == visibleAction ) ? false : true );
+ public SetSizeActionImpl(int w, int h) {
+ width = w;
+ height = h;
+ }
+ public void run() {
+ windowLock.lock();
+ try {
+ if ( !fullscreen && ( width != WindowImpl.this.width || WindowImpl.this.height != height ) ) {
+ if(DEBUG_IMPLEMENTATION) {
+ String msg = new String("Window setSize: START "+WindowImpl.this.width+"x"+WindowImpl.this.height+" -> "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible "+visible);
+ System.err.println(msg);
+ }
+ if ( 0 != windowHandle && 0>=width*height && visible ) {
+ visibleAction=1; // invisible
+ WindowImpl.this.width = 0;
+ WindowImpl.this.height = 0;
+ } else if ( 0 == windowHandle && 0<width*height && visible ) {
+ visibleAction = 2; // visible (create)
+ WindowImpl.this.width = width;
+ WindowImpl.this.height = height;
+ } else if ( 0 != windowHandle ) {
+ // this width/height will be set by windowChanged, called by the native implementation
+ reconfigureWindowImpl(x, y, width, height, false, 0, 0);
+ } else {
+ WindowImpl.this.width = width;
+ WindowImpl.this.height = height;
+ }
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("Window setSize: END "+WindowImpl.this.width+"x"+WindowImpl.this.height+", visibleAction "+visibleAction);
+ }
+ }
+ } finally {
+ windowLock.unlock();
+ }
}
}
- public void destroy(boolean unrecoverable) {
- if( isValid() ) {
- if(DEBUG_IMPLEMENTATION) {
- String msg = new String("Window.destroy(unrecoverable: "+unrecoverable+") START "+getThreadName()/*+", "+this*/);
- System.err.println(msg);
- //Exception ee = new Exception(msg);
- //ee.printStackTrace();
+ public void setSize(int width, int height) {
+ if(isValid()) {
+ SetSizeActionImpl setSizeAction = new SetSizeActionImpl(width, height);
+ runOnEDTIfAvail(true, setSizeAction);
+ switch(setSizeAction.getVisibleAction()) {
+ case 1: setVisible(false); break;
+ case 2: setVisible(true); break;
}
- runOnEDTIfAvail(true, new DestroyAction(unrecoverable));
}
}
class DestroyAction implements Runnable {
boolean unrecoverable;
+
public DestroyAction(boolean unrecoverable) {
this.unrecoverable = unrecoverable;
}
@@ -592,6 +659,19 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
+ public void destroy(boolean unrecoverable) {
+ if( isValid() ) {
+ if(DEBUG_IMPLEMENTATION) {
+ String msg = new String("Window.destroy(unrecoverable: "+unrecoverable+") START "+getThreadName()/*+", "+this*/);
+ System.err.println(msg);
+ //Exception ee = new Exception(msg);
+ //ee.printStackTrace();
+ }
+ DestroyAction destroyAction = new DestroyAction(unrecoverable);
+ runOnEDTIfAvail(true, destroyAction);
+ }
+ }
+
/**
* <p>
* render all native window information invalid,
@@ -618,7 +698,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
*/
protected void invalidate(boolean unrecoverable) {
windowLock.lock();
- try{
+ try {
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
String msg = new String("!!! Window Invalidate(unrecoverable: "+unrecoverable+") "+getThreadName());
System.err.println(msg);
@@ -667,6 +747,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
boolean wasVisible;
boolean displayChanged = false;
+ // mirror pos/size so native change notification can get overwritten
+ int x = WindowImpl.this.x;
+ int y = WindowImpl.this.y;
+ int width = WindowImpl.this.width;
+ int height = WindowImpl.this.height;
+
windowLock.lock();
try {
wasVisible = isVisible();
@@ -679,10 +765,22 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
long newParentWindowHandle = 0 ;
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+", visible "+wasVisible+", old parentWindow: "+Display.hashCode(parentWindow)+", new parentWindow: "+Display.hashCode(newParentWindow)+", forceDestroyCreate "+forceDestroyCreate+", DEBUG_TEST_REPARENT_INCOMPATIBLE "+DEBUG_TEST_REPARENT_INCOMPATIBLE);
+ System.err.println("Window.reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+", visible "+wasVisible+", old parentWindow: "+Display.hashCode(parentWindow)+", new parentWindow: "+Display.hashCode(newParentWindow)+", forceDestroyCreate "+forceDestroyCreate+", DEBUG_TEST_REPARENT_INCOMPATIBLE "+DEBUG_TEST_REPARENT_INCOMPATIBLE+" "+x+"/"+y+" "+width+"x"+height);
}
if(null!=newParentWindow) {
+ // reset position to 0/0 within parent space
+ x = 0;
+ y = 0;
+
+ // refit if size is bigger than parent
+ if( width > newParentWindow.getWidth() ) {
+ width = newParentWindow.getWidth();
+ }
+ if( height > newParentWindow.getHeight() ) {
+ height = newParentWindow.getHeight();
+ }
+
// Case: Child Window
newParentWindowHandle = getNativeWindowHandle(newParentWindow);
if(0 == newParentWindowHandle) {
@@ -740,6 +838,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
reparentAction = ACTION_UNCHANGED;
}
} else {
+ if( null != parentWindow ) {
+ // child -> top
+ // put client to current parent+child position
+ Point p = getLocationOnScreen(null);
+ x = p.getX();
+ y = p.getY();
+ }
+
// Case: Top Window
if( 0 == getParentWindowHandle() ) {
// Already Top Window
@@ -789,45 +895,59 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
if( ACTION_NATIVE_REPARENTING == reparentAction ) {
- if(0!=parentWindowHandle) {
- // reset position to 0/0 within parent space
- // FIXME .. cache position ?
- x = 0;
- y = 0;
- }
DisplayImpl display = (DisplayImpl) screen.getDisplay();
- display.dispatchMessages(); // status up2date
+ display.dispatchMessagesNative(); // status up2date
if(wasVisible) {
- visible = false;
- setVisibleImpl(false);
- display.dispatchMessages(); // status up2date
+ setVisibleImpl(false, x, y, width, height);
+ WindowImpl.this.waitForVisible(false, true);
}
// Lock parentWindow only during reparenting (attempt)
NativeWindow parentWindowLocked = null;
if( null != parentWindow ) {
parentWindowLocked = parentWindow;
- if(NativeSurface.LOCK_SURFACE_NOT_READY >= parentWindowLocked.lockSurface() ) {
+ if( NativeSurface.LOCK_SURFACE_NOT_READY >= parentWindowLocked.lockSurface() ) {
throw new NativeWindowException("Parent surface lock: not ready: "+parentWindow);
}
}
boolean ok = false;
try {
- ok = reparentWindowImpl();
+ // write back mirrored values, to be able to detect satisfaction
+ WindowImpl.this.x = x;
+ WindowImpl.this.y = y;
+ WindowImpl.this.width = width;
+ WindowImpl.this.height = height;
+ ok = reconfigureWindowImpl(x, y, width, height, true, 0, isUndecorated()?-1:1);
} finally {
if(null!=parentWindowLocked) {
parentWindowLocked.unlockSurface();
}
}
+ // set visible again, and revalidate 'ok',
+ // since it has been experience that in some cases the reparented window gets hidden
+ if(ok) {
+ display.dispatchMessagesNative(); // status up2date
+ if(wasVisible) {
+ setVisibleImpl(true, x, y, width, height);
+ ok = WindowImpl.this.waitForVisible(true, false);
+ display.dispatchMessagesNative(); // status up2date
+ if( WindowImpl.this.x != x ||
+ WindowImpl.this.y != y ||
+ WindowImpl.this.width != width ||
+ WindowImpl.this.height != height )
+ {
+ // reset pos/size .. due to some native impl flakyness
+ reconfigureWindowImpl(x, y, width, height, false, 0, 0);
+ display.dispatchMessagesNative(); // status up2date
+ }
+ }
+ }
+
if(ok) {
- display.dispatchMessages(); // status up2date
if(wasVisible) {
- visible = true;
- setVisibleImpl(true);
- display.dispatchMessages(); // status up2date
requestFocusImpl(true);
- display.dispatchMessages(); // status up2date
+ display.dispatchMessagesNative(); // status up2date
}
} else {
// native reparent failed -> try creation
@@ -839,15 +959,22 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
+ // write back mirrored values, ensuring persitence
+ // and not relying on native messaging
+ WindowImpl.this.x = x;
+ WindowImpl.this.y = y;
+ WindowImpl.this.width = width;
+ WindowImpl.this.height = height;
+
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.reparentWindow: END ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+ Display.hashCode(parentWindow));
+ System.err.println("Window.reparentWindow: END ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+ Display.hashCode(parentWindow)+" "+x+"/"+y+" "+width+"x"+height);
}
} finally {
windowLock.unlock();
}
if( ACTION_NATIVE_CREATION == reparentAction && wasVisible ) {
- // This may run on the the Display/Screen connection,
+ // This may run on the Display/Screen connection,
// hence a new EDT task
runOnEDTIfAvail(true, reparentActionRecreate);
}
@@ -884,24 +1011,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
ReparentActionImpl reparentAction = new ReparentActionImpl(newParent, forceDestroyCreate);
runOnEDTIfAvail(true, reparentAction);
reparentActionStrategy = reparentAction.getStrategy();
- boolean sizeSignaled=false;
- if(null!=newParent) {
- // refit if size is bigger than parent
- int w = getWidth();
- int h = getHeight();
- if(w>newParent.getWidth()) {
- w=newParent.getWidth();
- sizeSignaled=true;
- }
- if(h>newParent.getHeight()) {
- h=newParent.getHeight();
- sizeSignaled=true;
- }
- if(sizeSignaled) {
- setSize(w, h);
- }
- }
- if( !sizeSignaled && isVisible() ) {
+ if( isVisible() ) {
sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
}
} finally {
@@ -935,22 +1045,70 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
- public void setUndecorated(boolean value) {
- if(!fullscreen && this.undecorated != value) {
- undecorated = value;
- if( 0 != windowHandle ) {
- reconfigureWindowImpl(x, y, width, height);
- requestFocus();
+ class DecorationActionImpl implements Runnable {
+ boolean undecorated;
+
+ public DecorationActionImpl(boolean undecorated) {
+ this.undecorated = undecorated;
+ }
+
+ public void run() {
+ windowLock.lock();
+ try {
+ if(!fullscreen && isNativeValid() && WindowImpl.this.undecorated != undecorated) {
+ WindowImpl.this.undecorated = undecorated;
+ // mirror pos/size so native change notification can get overwritten
+ int x = WindowImpl.this.x;
+ int y = WindowImpl.this.y;
+ int width = WindowImpl.this.width;
+ int height = WindowImpl.this.height;
+
+ if( 0 != windowHandle ) {
+ DisplayImpl display = (DisplayImpl) screen.getDisplay();
+ display.dispatchMessagesNative(); // status up2date
+ boolean wasVisible = isVisible();
+ setVisibleImpl(false, x, y, width, height);
+ WindowImpl.this.waitForVisible(false, true);
+ display.dispatchMessagesNative(); // status up2date
+ reconfigureWindowImpl(x, y, width, height, false, 0, undecorated?-1:1);
+ display.dispatchMessagesNative(); // status up2date
+ if(wasVisible) {
+ setVisibleImpl(true, x, y, width, height);
+ WindowImpl.this.waitForVisible(true, true);
+ display.dispatchMessagesNative(); // status up2date
+ if( WindowImpl.this.x != x ||
+ WindowImpl.this.y != y ||
+ WindowImpl.this.width != width ||
+ WindowImpl.this.height != height )
+ {
+ // reset pos/size .. due to some native impl flakyness
+ reconfigureWindowImpl(x, y, width, height, false, 0, 0);
+ display.dispatchMessagesNative(); // status up2date
+ }
+ requestFocusImpl(true);
+ display.dispatchMessagesNative(); // status up2date
+ }
+ }
+ }
+ } finally {
+ windowLock.unlock();
}
}
}
+ public void setUndecorated(boolean value) {
+ if(isValid()) {
+ DecorationActionImpl decorationAction = new DecorationActionImpl(value);
+ runOnEDTIfAvail(true, decorationAction);
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
+ }
+ }
+
public boolean isUndecorated() {
return 0 != parentWindowHandle || undecorated || fullscreen ;
}
public void requestFocus() {
- // enqueueRequestFocus(false); // FIXME: or shall we wait ?
enqueueRequestFocus(true);
}
@@ -1083,12 +1241,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
class RequestFocusAction implements Runnable {
public void run() {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("Window.RequestFocusAction: ("+getThreadName()+"): "+hasFocus+" -> true - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle));
+ }
WindowImpl.this.requestFocusImpl(false);
}
}
RequestFocusAction requestFocusAction = new RequestFocusAction();
- public void enqueueRequestFocus(boolean wait) {
+ protected void enqueueRequestFocus(boolean wait) {
runOnEDTIfAvail(wait, requestFocusAction);
}
@@ -1117,67 +1278,100 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
protected FocusRunnable focusAction = null;
- private boolean handleDestroyNotify = true;
+ class SetPositionActionImpl implements Runnable {
+ int x, y;
- public void setPosition(int x, int y) {
- windowLock.lock();
- try{
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle));
- }
- if ( this.x != x || this.y != y ) {
- if(!fullscreen) {
- nfs_x=x;
- nfs_y=y;
- if(0!=windowHandle) {
- // this x/y will be set by windowChanged, called by X11
- setPositionImpl(x, y);
- } else {
- this.x = x;
- this.y = y;
+ public SetPositionActionImpl(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+ public void run() {
+ windowLock.lock();
+ try {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("Window setPosition: "+WindowImpl.this.x+"/"+WindowImpl.this.y+" -> "+x+"/"+y+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle));
+ }
+ if ( WindowImpl.this.x != x || WindowImpl.this.y != y ) {
+ if(!fullscreen) {
+ if(0!=windowHandle) {
+ // this.x/this.y will be set by windowChanged, called by the native implementation
+ reconfigureWindowImpl(x, y, -1, -1, false, 0, 0);
+ } else {
+ WindowImpl.this.x = x;
+ WindowImpl.this.y = y;
+ }
}
}
+ } finally {
+ windowLock.unlock();
}
- } finally {
- windowLock.unlock();
}
}
- public boolean setFullscreen(boolean fullscreen) {
- boolean action = false;
- windowLock.lock();
- try{
- if(0!=windowHandle && this.fullscreen!=fullscreen) {
- int x,y,w,h;
- if(fullscreen) {
- x = 0; y = 0;
- w = screen.getWidth();
- h = screen.getHeight();
- } else {
- if(0!=parentWindowHandle) {
- x=0;
- y=0;
+ public void setPosition(int x, int y) {
+ if(isValid()) {
+ SetPositionActionImpl setPositionAction = new SetPositionActionImpl(x, y);
+ runOnEDTIfAvail(true, setPositionAction);
+ }
+ }
+
+ class FullScreenActionImpl implements Runnable {
+ boolean fullscreen;
+
+ public FullScreenActionImpl (boolean fullscreen) {
+ this.fullscreen = fullscreen;
+ }
+
+ public void run() {
+ windowLock.lock();
+ try {
+ if(isNativeValid() && WindowImpl.this.fullscreen != fullscreen) {
+ int x,y,w,h;
+ WindowImpl.this.fullscreen = fullscreen;
+ if(fullscreen) {
+ x = 0; y = 0;
+ w = screen.getWidth();
+ h = screen.getHeight();
+ nfs_width = width;
+ nfs_height = height;
+ nfs_x = x;
+ nfs_y = y;
} else {
x = nfs_x;
y = nfs_y;
+ w = nfs_width;
+ h = nfs_height;
+ }
+ if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
+ System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()+", "+screen);
+ }
+
+ DisplayImpl display = (DisplayImpl) screen.getDisplay();
+ display.dispatchMessagesNative(); // status up2date
+ boolean wasVisible = isVisible();
+ setVisibleImpl(false, x, y, width, height);
+ WindowImpl.this.waitForVisible(false, true);
+ display.dispatchMessagesNative(); // status up2date
+ reconfigureWindowImpl(x, y, w, h, getParentWindowHandle()!=0, fullscreen?1:-1, isUndecorated()?-1:1);
+ display.dispatchMessagesNative(); // status up2date
+ if(wasVisible) {
+ setVisibleImpl(true, x, y, width, height);
+ WindowImpl.this.waitForVisible(true, true);
+ display.dispatchMessagesNative(); // status up2date
+ requestFocusImpl(true);
+ display.dispatchMessagesNative(); // status up2date
}
- w = nfs_width;
- h = nfs_height;
- }
- if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
- System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()+", "+screen);
}
- this.fullscreen = fullscreen;
- reconfigureWindowImpl(x, y, w, h);
- action = true;
+ } finally {
+ windowLock.unlock();
}
- } finally {
- windowLock.unlock();
}
- if(action) {
- requestFocus();
- }
- if( isVisible() ) {
+ }
+
+ public boolean setFullscreen(boolean fullscreen) {
+ if(isValid()) {
+ FullScreenActionImpl fullScreenAction = new FullScreenActionImpl(fullscreen);
+ runOnEDTIfAvail(true, fullScreenAction);
sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
}
return this.fullscreen;
@@ -1654,7 +1848,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
*/
protected void focusChanged(boolean focusGained) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.focusChanged: ("+getThreadName()+"): "+focusGained+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle));
+ System.err.println("Window.focusChanged: ("+getThreadName()+"): "+this.hasFocus+" -> "+focusGained+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle));
}
hasFocus = focusGained;
if (focusGained) {
@@ -1667,23 +1861,36 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
protected void visibleChanged(boolean visible) {
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window.visibleChanged ("+getThreadName()+"): "+this.visible+" -> "+visible+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle));
- // Exception e = new Exception("Window.visibleChanged ("+getThreadName()+"): "+this.visible+" -> "+visible+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle));
- // e.printStackTrace();
}
this.visible = visible ;
}
- protected void sizeChanged(int newWidth, int newHeight) {
- if(width != newWidth || height != newHeight) {
+ private boolean waitForVisible(boolean visible, boolean failFast) {
+ DisplayImpl display = (DisplayImpl) screen.getDisplay();
+ for(long sleep = TIMEOUT_NATIVEWINDOW; 0<sleep && this.visible != visible; sleep-=10 ) {
+ display.dispatchMessagesNative(); // status up2date
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException ie) {}
+ sleep -=10;
+ }
+ if(this.visible != visible) {
+ if(failFast) {
+ throw new NativeWindowException("Visibility not reached as requested within "+TIMEOUT_NATIVEWINDOW+"ms : requested "+visible+", is "+this.visible);
+ } else if (DEBUG_IMPLEMENTATION) {
+ System.err.println("******* Visibility not reached as requested within "+TIMEOUT_NATIVEWINDOW+"ms : requested "+visible+", is "+this.visible);
+ }
+ }
+ return this.visible == visible;
+ }
+
+ protected void sizeChanged(int newWidth, int newHeight, boolean force) {
+ if(force || width != newWidth || height != newHeight) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.sizeChanged: ("+getThreadName()+"): "+width+"x"+height+" -> "+newWidth+"x"+newHeight+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle));
+ System.err.println("Window.sizeChanged: ("+getThreadName()+"): force "+force+", "+width+"x"+height+" -> "+newWidth+"x"+newHeight+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle));
}
width = newWidth;
height = newHeight;
- if(!fullscreen) {
- nfs_width=width;
- nfs_height=height;
- }
if(isNativeValid()) {
sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
}
@@ -1697,10 +1904,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
x = newX;
y = newY;
- if(!fullscreen) {
- nfs_x=x;
- nfs_y=y;
- }
sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
}
}
@@ -1731,6 +1934,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
public void windowRepaint(int x, int y, int width, int height) {
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window.windowRepaint "+getThreadName()+" - "+x+"/"+y+" "+width+"x"+height);
+ // Exception ee = new Exception("Window.windowRepaint: "+" - "+x+"/"+y+" "+width+"x"+height);
+ // ee.printStackTrace();
}
if(0>width) {
width=this.width;
@@ -1746,11 +1951,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
- protected boolean reparentWindowImpl() {
- // default implementation, no native reparenting support
- return false;
- }
-
protected int getWindowLockRecursionCount() {
return windowLock.getRecursionCount();
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
index 5abff047f..edd851451 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
@@ -46,6 +46,7 @@ import com.jogamp.newt.impl.WindowImpl;
import java.awt.Insets;
import javax.media.nativewindow.*;
import javax.media.nativewindow.awt.*;
+import javax.media.nativewindow.util.Point;
/** An implementation of the Newt Window class built using the
AWT. This is provided for convenience of porting to platforms
@@ -74,8 +75,6 @@ public class AWTWindow extends WindowImpl {
private Container container = null;
private Frame frame = null; // same instance as container, just for impl. convenience
private AWTCanvas canvas;
- // non fullscreen dimensions ..
- private int nfs_width, nfs_height, nfs_x, nfs_y;
protected void requestFocusImpl(boolean reparented) {
runOnEDT(true, new Runnable() {
@@ -176,13 +175,14 @@ public class AWTWindow extends WindowImpl {
return res;
}
- protected void setVisibleImpl(final boolean visible) {
+ protected void setVisibleImpl(final boolean visible, int x, int y, int width, int height) {
runOnEDT(true, new Runnable() {
public void run() {
container.setVisible(visible);
}
});
+ reconfigureWindowImpl(x, y, width, height, false, 0, 0);
config = canvas.getAWTGraphicsConfiguration();
if (config == null) {
@@ -190,6 +190,7 @@ public class AWTWindow extends WindowImpl {
}
updateDeviceData();
+ visibleChanged(visible);
}
private void updateDeviceData() {
@@ -203,19 +204,6 @@ public class AWTWindow extends WindowImpl {
((AWTScreen)getScreen()).setScreenSize(w, h);
}
- protected void setSizeImpl(final int width, final int height) {
- if(null!=container) {
- /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */
- runOnEDT(false, new Runnable() {
- public void run() {
- Insets insets = container.getInsets();
- container.setSize(width + insets.left + insets.right,
- height + insets.top + insets.bottom);
- }
- });
- }
- }
-
public javax.media.nativewindow.util.Insets getInsets() {
final int insets[] = new int[] { 0, 0, 0, 0 };
runOnEDT(true, new Runnable() {
@@ -230,21 +218,11 @@ public class AWTWindow extends WindowImpl {
return new javax.media.nativewindow.util.Insets(insets[0],insets[1],insets[2],insets[3]);
}
- protected void setPositionImpl(final int x, final int y) {
- if(null!=container) {
- runOnEDT(true, new Runnable() {
- public void run() {
- container.setLocation(x, y);
- }
- });
- }
- }
-
- protected void reconfigureWindowImpl(final int x, final int y, final int width, final int height) {
+ protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final boolean parentChange, final int fullScreenChange, final int decorationChange) {
/** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */
runOnEDT(false, new Runnable() {
public void run() {
- if(null!=frame) {
+ if(decorationChange!=0 && null!=frame) {
if(!container.isDisplayable()) {
frame.setUndecorated(isUndecorated());
} else {
@@ -253,12 +231,26 @@ public class AWTWindow extends WindowImpl {
}
}
}
- container.setLocation(x, y);
- container.setSize(width, height);
+ int _x=(x>=0)?x:AWTWindow.this.x;
+ int _y=(x>=0)?y:AWTWindow.this.y;
+ int _w=(width>0)?width:AWTWindow.this.width;
+ int _h=(height>0)?height:AWTWindow.this.height;
+
+ container.setLocation(_x, _y);
+ Insets insets = container.getInsets();
+ container.setSize(_w + insets.left + insets.right,
+ _h + insets.top + insets.bottom);
}
});
+ return true;
}
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ java.awt.Point ap = canvas.getLocationOnScreen();
+ ap.translate(x, y);
+ return new Point((int)(ap.getX()+0.5),(int)(ap.getY()+0.5));
+ }
+
public Object getWrappedWindow() {
return canvas;
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
index 040fa15a9..749be8506 100644
--- a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
@@ -34,6 +34,7 @@
package com.jogamp.newt.impl.intel.gdl;
import javax.media.nativewindow.*;
+import javax.media.nativewindow.util.Point;
public class Window extends com.jogamp.newt.impl.WindowImpl {
static {
@@ -77,42 +78,40 @@ public class Window extends com.jogamp.newt.impl.WindowImpl {
}
}
- protected void setVisibleImpl(boolean visible) {
+ protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
+ reconfigureWindowImpl(x, y, width, height, false, 0, 0);
if(visible) {
((Display)getScreen().getDisplay()).setFocus(this);
}
+ this.visibleChanged(visible);
}
- protected void setSizeImpl(int width, int height) {
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, boolean parentChange, int fullScreenChange, int decorationChange) {
Screen screen = (Screen) getScreen();
- if((x+width)>screen.getWidth()) {
- width=screen.getWidth()-x;
- }
- if((y+height)>screen.getHeight()) {
- height=screen.getHeight()-y;
- }
- if(0!=surfaceHandle) {
- SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height);
- }
- }
- protected void setPositionImpl(int x, int y) {
- Screen screen = (Screen) getScreen();
- if((x+width)>screen.getWidth()) {
- x=screen.getWidth()-width;
+ int _x=(x>=0)?x:this.x;
+ int _y=(x>=0)?y:this.y;
+ int _w=(width>0)?width:this.width;
+ int _h=(height>0)?height:this.height;
+
+ if(_w>screen.getWidth()) {
+ _w=screen.getWidth();
}
- if((y+height)>screen.getHeight()) {
- y=screen.getHeight()-height;
+ if(_h>screen.getHeight()) {
+ _h=screen.getHeight();
}
- if(0!=surfaceHandle) {
- SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height);
+ if((_x+_w)>screen.getWidth()) {
+ _x=screen.getWidth()-_w;
+ }
+ if((_y+_h)>screen.getHeight()) {
+ _y=screen.getHeight()-_h;
}
- }
- protected void reconfigureWindowImpl(int x, int y, int width, int height) {
if(0!=surfaceHandle) {
- SetBounds0(surfaceHandle, getScreen().getWidth(), getScreen().getHeight(), x, y, width, height);
+ SetBounds0(surfaceHandle, getScreen().getWidth(), getScreen().getHeight(), _x, _y, _w, _h);
}
+
+ return true;
}
protected void requestFocusImpl(boolean reparented) {
@@ -123,6 +122,10 @@ public class Window extends com.jogamp.newt.impl.WindowImpl {
return surfaceHandle;
}
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
+ }
+
//----------------------------------------------------------------------
// Internals only
//
@@ -140,5 +143,4 @@ public class Window extends com.jogamp.newt.impl.WindowImpl {
}
private long surfaceHandle;
- private int nfs_width, nfs_height, nfs_x, nfs_y;
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
index 15cadb05f..59b41c2aa 100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
@@ -40,6 +40,7 @@ import com.jogamp.common.util.locks.RecursiveLock;
import com.jogamp.newt.event.*;
import com.jogamp.newt.impl.*;
import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.Point;
public class MacWindow extends WindowImpl {
@@ -194,11 +195,11 @@ public class MacWindow extends WindowImpl {
nsViewLock.unlock();
}
- protected void setVisibleImpl(final boolean visible) {
+ protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
nsViewLock.lock();
try {
if (visible) {
- createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen());
+ createWindow(false, x, y, width, height, isFullscreen());
if (getWindowHandle() != 0) {
makeKeyAndOrderFront0(getWindowHandle());
}
@@ -207,6 +208,7 @@ public class MacWindow extends WindowImpl {
orderOut0(getWindowHandle());
}
}
+ visibleChanged(visible);
} finally {
nsViewLock.unlock();
}
@@ -232,39 +234,38 @@ public class MacWindow extends WindowImpl {
}
}
- protected void setSizeImpl(int width, int height) {
- // this width/height will be set by sizeChanged, called by OSX
- nsViewLock.lock();
- try {
- setContentSize0(getWindowHandle(), width, height);
- } finally {
- nsViewLock.unlock();
- }
- }
-
- protected void setPositionImpl(int x, int y) {
- // this x/y will be set by positionChanged, called by OSX
- nsViewLock.lock();
- try {
- setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), x, y);
- } finally {
- nsViewLock.unlock();
- }
- }
-
- protected void reconfigureWindowImpl(int x, int y, int width, int height) {
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, boolean parentChange, int fullScreenChange, int decorationChange) {
nsViewLock.lock();
try {
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
- System.err.println("MacWindow reconfig: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height);
+ System.err.println("MacWindow reconfig: parentChange "+parentChange+", fullScreenChange "+fullScreenChange+", decorationChange "+decorationChange+" "+x+"/"+y+" "+width+"x"+height);
}
- createWindow(true, x, y, width, height, fullscreen);
- if (getWindowHandle() != 0) {
- makeKeyAndOrderFront0(getWindowHandle());
+ int _x=(x>=0)?x:this.x;
+ int _y=(x>=0)?y:this.y;
+ int _w=(width>0)?width:this.width;
+ int _h=(height>0)?height:this.height;
+
+ if(decorationChange!=0 || parentChange || fullScreenChange!=0) {
+ createWindow(true, _x, _y, _w, _h, fullScreenChange>0);
+ if (getWindowHandle() != 0) {
+ makeKeyAndOrderFront0(getWindowHandle());
+ }
+ } else {
+ if(x>=0 || y>=0) {
+ setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), _x, _y);
+ }
+ if(width>0 || height>0) {
+ setContentSize0(getWindowHandle(), _w, _h);
+ }
}
} finally {
nsViewLock.unlock();
}
+ return true;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return null;
}
private void insetsChanged(int left, int top, int right, int bottom) {
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
index 9f5e7b7c1..ad903731b 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
@@ -37,6 +37,7 @@ import com.jogamp.opengl.impl.egl.*;
import javax.media.nativewindow.*;
import javax.media.opengl.GLCapabilities;
import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.util.Point;
public class Window extends com.jogamp.newt.impl.WindowImpl {
static {
@@ -70,7 +71,10 @@ public class Window extends com.jogamp.newt.impl.WindowImpl {
}
}
- protected void setVisibleImpl(boolean visible) { }
+ protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
+ reconfigureWindowImpl(x, y, width, height, false, 0, 0);
+ visibleChanged(visible);
+ }
protected void requestFocusImpl(boolean reparented) { }
@@ -84,16 +88,37 @@ public class Window extends com.jogamp.newt.impl.WindowImpl {
}
}
- protected void setPositionImpl(int x, int y) {
- // n/a in BroadcomEGL
- System.err.println("BCEGL Window.setPositionImpl n/a in BroadcomEGL");
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height,
+ boolean parentChange, int fullScreenChange, int decorationChange) {
+ if(0!=getWindowHandle()) {
+ if(0!=fullScreenChange) {
+ if( fullScreenChange > 0 ) {
+ // n/a in BroadcomEGL
+ System.err.println("setFullscreen n/a in BroadcomEGL");
+ return false;
+ }
+ }
+ }
+ if(width>0 || height>0) {
+ if(0!=getWindowHandle()) {
+ // n/a in BroadcomEGL
+ System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window");
+ } else {
+ this.width=(width>0)?width:this.width;
+ this.height=(height>0)?height:this.height;
+ }
+ }
+ if(x>=0 || y>=0) {
+ System.err.println("BCEGL Window.setPositionImpl n/a in BroadcomEGL");
+ }
+ return true;
}
- protected void reconfigureWindowImpl(int x, int y, int width, int height) {
- // n/a in BroadcomEGL
- System.err.println("setFullscreen n/a in BroadcomEGL");
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
}
+
public boolean surfaceSwap() {
SwapWindow(getDisplayHandle(), getWindowHandle());
return true;
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
index 6930741b8..f0bc8587b 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
@@ -41,11 +41,10 @@ import javax.media.nativewindow.*;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.util.Point;
public class KDWindow extends WindowImpl {
private static final String WINDOW_CLASS_NAME = "NewtWindow";
- // non fullscreen dimensions ..
- private int nfs_width, nfs_height, nfs_x, nfs_y;
static {
KDDisplay.initSingleton();
@@ -85,30 +84,40 @@ public class KDWindow extends WindowImpl {
}
}
- protected void setVisibleImpl(boolean visible) {
+ protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
setVisible0(eglWindowHandle, visible);
+ reconfigureWindowImpl(x, y, width, height, false, 0, 0);
+ visibleChanged(visible);
}
protected void requestFocusImpl(boolean reparented) { }
- protected void setSizeImpl(int width, int height) {
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height,
+ boolean parentChange, int fullScreenChange, int decorationChange) {
if(0!=eglWindowHandle) {
- setSize0(eglWindowHandle, width, height);
+ if(0!=fullScreenChange) {
+ boolean fs = fullScreenChange > 0;
+ setFullScreen0(eglWindowHandle, fs);
+ if(fs) {
+ return true;
+ }
+ }
+ // int _x=(x>=0)?x:this.x;
+ // int _y=(x>=0)?y:this.y;
+ int _w=(width>0)?width:this.width;
+ int _h=(height>0)?height:this.height;
+ if(width>0 || height>0) {
+ setSize0(eglWindowHandle, _w, _h);
+ }
+ if(x>=0 || y>=0) {
+ System.err.println("setPosition n/a in KD");
+ }
}
+ return true;
}
- protected void setPositionImpl(int x, int y) {
- // n/a in KD
- System.err.println("setPosition n/a in KD");
- }
-
- protected void reconfigureWindowImpl(int x, int y, int width, int height) {
- if(0!=eglWindowHandle) {
- setFullScreen0(eglWindowHandle, fullscreen);
- if(!fullscreen) {
- setSize0(eglWindowHandle, width, height);
- }
- }
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
}
//----------------------------------------------------------------------
@@ -127,11 +136,11 @@ public class KDWindow extends WindowImpl {
windowUserData=userData;
}
- protected void sizeChanged(int newWidth, int newHeight) {
+ protected void sizeChanged(int newWidth, int newHeight, boolean force) {
if(fullscreen) {
((KDScreen)getScreen()).setScreenSize(width, height);
}
- super.sizeChanged(newWidth, newHeight);
+ super.sizeChanged(newWidth, newHeight, force);
}
private long eglWindowHandle;
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
index 3ade599da..daa09b034 100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
@@ -37,6 +37,7 @@ package com.jogamp.newt.impl.windows;
import javax.media.nativewindow.*;
import com.jogamp.newt.impl.WindowImpl;
import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.Point;
public class WindowsWindow extends WindowImpl {
@@ -142,31 +143,20 @@ public class WindowsWindow extends WindowImpl {
super.windowDestroyed();
}
- protected void setVisibleImpl(boolean visible) {
- setVisible0(getWindowHandle(), visible);
+ protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
+ setVisible0(getWindowHandle(), visible, (getParentWindowHandle()==0)?true:false, x, y, width, height);
+ visibleChanged(visible);
}
- protected void setSizeImpl(int width, int height) {
- // this width/height will be set by sizeChanged, called by Windows
- setSize0(getParentWindowHandle(), getWindowHandle(), x, y, width, height);
- }
-
- protected void setPositionImpl(int x, int y) {
- // this x/y will be set by positionChanged, called by Windows
- setPosition0(getParentWindowHandle(), getWindowHandle(), x , y /*, width, height*/);
- }
-
- protected void reconfigureWindowImpl(int x, int y, int width, int height) {
- reconfigureWindow0(fullscreen?0:getParentWindowHandle(), getWindowHandle(), x, y, width, height, isUndecorated());
- }
-
- protected boolean reparentWindowImpl() {
- reparentWindow0(fullscreen?0:getParentWindowHandle(), getWindowHandle(), x, y, width, height, isUndecorated());
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height,
+ boolean parentChange, int fullScreenChange, int decorationChange) {
+ reconfigureWindow0( (fullScreenChange>0)?0:getParentWindowHandle(),
+ getWindowHandle(), x, y, width, height, isVisible(), parentChange, fullScreenChange, decorationChange);
return true;
}
- protected void requestFocusImpl(boolean reparented) {
- requestFocus0(getWindowHandle(), reparented);
+ protected void requestFocusImpl(boolean force) {
+ requestFocus0(getWindowHandle(), force);
}
protected void setTitleImpl(final String title) {
@@ -177,34 +167,42 @@ public class WindowsWindow extends WindowImpl {
return (Insets)insets.clone();
}
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return (Point) getRelativeLocation0( getWindowHandle(), 0 /*root win*/, x, y);
+ }
+
//----------------------------------------------------------------------
// Internals only
//
protected static native boolean initIDs0();
- private native long CreateWindow0(long parentWindowHandle,
+ private native long CreateWindow0(long parentWindowHandle,
int wndClassAtom, String wndName,
long hInstance, long visualID,
boolean isUndecorated,
int x, int y, int width, int height);
- private native void DestroyWindow0(long windowHandle);
- private native long GetDC0(long windowHandle);
- private native void ReleaseDC0(long windowHandle, long hdc);
- private native long MonitorFromWindow0(long windowHandle);
- private static native void setVisible0(long windowHandle, boolean visible);
- private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height);
- private static native void setPosition0(long parentWindowHandle, long windowHandle, int x, int y /*, int width, int height*/);
- private native void reconfigureWindow0(long parentWindowHandle, long windowHandle,
- int x, int y, int width, int height, boolean isUndecorated);
- private native void reparentWindow0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated);
+ private native void DestroyWindow0(long windowHandle);
+ private native long GetDC0(long windowHandle);
+ private native void ReleaseDC0(long windowHandle, long hdc);
+ private native long MonitorFromWindow0(long windowHandle);
+ private native void setVisible0(long windowHandle, boolean visible, boolean top, int x, int y, int width, int height);
+ private native void reconfigureWindow0(long parentWindowHandle, long windowHandle,
+ int x, int y, int width, int height, boolean isVisible,
+ boolean parentChange, int fullScreenChange, int decorationChange);
private static native void setTitle0(long windowHandle, String title);
- private native void requestFocus0(long windowHandle, boolean reparented);
+ private native void requestFocus0(long windowHandle, boolean force);
+ private native Object getRelativeLocation0(long src_win, long dest_win, int src_x, int src_y);
private void insetsChanged(int left, int top, int right, int bottom) {
if (left != -1 && top != -1 && right != -1 && bottom != -1) {
- insets.left = left;
- insets.top = top;
- insets.right = right;
- insets.bottom = bottom;
+ if (left != insets.left || top != insets.top || right != insets.right || bottom != insets.bottom) {
+ insets.left = left;
+ insets.top = top;
+ insets.right = right;
+ insets.bottom = bottom;
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("Window.insetsChanged: "+insets);
+ }
+ }
}
}
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
index 3b3cd07ae..53b222189 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
@@ -38,6 +38,7 @@ import com.jogamp.newt.event.*;
import com.jogamp.newt.impl.WindowImpl;
import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
+import javax.media.nativewindow.util.Point;
public class X11Window extends WindowImpl {
private static final String WINDOW_CLASS_NAME = "NewtWindow";
@@ -62,10 +63,11 @@ public class X11Window extends WindowImpl {
display.getHandle(), screen.getIndex(), visualID,
display.getJavaObjectAtom(), display.getWindowDeleteAtom(),
x, y, width, height, isUndecorated());
- if (w == 0 || w!=getWindowHandle()) {
+ if (w == 0) {
throw new NativeWindowException("Error creating window: "+w);
}
- windowHandleClose = getWindowHandle();
+ setWindowHandle(w);
+ windowHandleClose = w;
}
protected void closeNativeImpl() {
@@ -90,62 +92,60 @@ public class X11Window extends WindowImpl {
super.windowDestroyed();
}
- protected void setVisibleImpl(boolean visible) {
- setVisible0(getDisplayHandle(), getWindowHandle(), visible);
+ protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
+ setVisible0(getDisplayHandle(), getWindowHandle(), visible, x, y, width, height);
}
- protected void setSizeImpl(int width, int height) {
- // this width/height will be set by windowChanged, called by X11
- setSize0(getDisplayHandle(), getWindowHandle(), width, height);
- }
-
- protected void setPositionImpl(int x, int y) {
- setPosition0(getParentWindowHandle(), getDisplayHandle(), getWindowHandle(), x, y);
- }
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height,
+ boolean parentChange, int fullScreenChange, int decorationChange) {
+ reparentHandle=0;
+ reparentCount=0;
+ long reqNewParentHandle = ( fullScreenChange > 0 ) ? 0 : getParentWindowHandle() ;
- protected void reconfigureWindowImpl(int x, int y, int width, int height) {
- reconfigureWindow0(fullscreen?0:getParentWindowHandle(), getDisplayHandle(), getScreenIndex(), getWindowHandle(),
- x, y, width, height, isUndecorated(), isVisible(), isFullscreen());
- }
+ reconfigureWindow0( getDisplayHandle(), getScreenIndex(), reqNewParentHandle, getWindowHandle(),
+ x, y, width, height, isVisible(), parentChange, fullScreenChange, decorationChange);
- protected boolean reparentWindowImpl() {
- if(0!=getWindowHandle()) {
- reparentWindow0(fullscreen?0:getParentWindowHandle(), getDisplayHandle(), getScreenIndex(), getWindowHandle(),
- x, y, isUndecorated(), isVisible());
- }
return true;
}
- protected void requestFocusImpl(boolean reparented) {
- requestFocus0(getDisplayHandle(), getWindowHandle(), reparented);
+ protected void requestFocusImpl(boolean force) {
+ requestFocus0(getDisplayHandle(), getWindowHandle(), force);
}
protected void setTitleImpl(String title) {
setTitle0(getDisplayHandle(), getWindowHandle(), title);
}
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return (Point) getRelativeLocation0( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y);
+ }
+
//----------------------------------------------------------------------
// Internals only
//
protected static native boolean initIDs0();
- private native long CreateWindow0(long parentWindowHandle, long display, int screen_index,
+ private native long CreateWindow0(long parentWindowHandle, long display, int screen_index,
long visualID, long javaObjectAtom, long windowDeleteAtom,
int x, int y, int width, int height, boolean undecorated);
- private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
- private native void setVisible0(long display, long windowHandle, boolean visible);
- private native void setSize0(long display, long windowHandle, int width, int height);
- private native void reconfigureWindow0(long parentWindowHandle, long display, int screen_index, long windowHandle,
- int x, int y, int width, int height, boolean undecorated, boolean isVisible, boolean fullscreen);
- private native void setTitle0(long display, long windowHandle, String title);
- private native void requestFocus0(long display, long windowHandle, boolean reparented);
- private native void setPosition0(long parentWindowHandle, long display, long windowHandle, int x, int y);
- private native void reparentWindow0(long parentWindowHandle, long display, int screen_index, long windowHandle,
- int x, int y, boolean undecorated, boolean isVisible);
-
- private void windowCreated(long windowHandle) {
- setWindowHandle(windowHandle);
+ private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
+ private native void setVisible0(long display, long windowHandle, boolean visible, int x, int y, int width, int height);
+ private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
+ int x, int y, int width, int height, boolean isVisible,
+ boolean parentChange, int fullScreenChange, int decorationChange);
+ private native void setTitle0(long display, long windowHandle, String title);
+ private native void requestFocus0(long display, long windowHandle, boolean force);
+ private native Object getRelativeLocation0(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y);
+
+ private void windowReparented(long gotParentHandle) {
+ reparentHandle = gotParentHandle;
+ reparentCount++;
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("******** new parent ("+reparentCount+"): " + toHexString(reparentHandle) );
+ }
}
private long windowHandleClose;
+ private volatile long reparentHandle;
+ private volatile int reparentCount;
}