summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-09-09 15:56:44 +0200
committerSven Gothel <[email protected]>2011-09-09 15:56:44 +0200
commitde0fe22e6f08de6430cf3219bd6e31b52f7da8d1 (patch)
tree0c89b80aa53190700871c40861d35fc9d0b12513 /src/newt/classes/jogamp
parent8def3e243401a0fe8ce606de6a54381a65626f15 (diff)
NEWT: Window default pos ; FullScreen
- FullScreen - lock parent window if child - X11: more sophisticated EWMH FS usage - X11: set window 'Above' before FS and at focus - allow window WM default position at window creation - default position { -1, -1 } as hint to native WM to gather a suitable default position - wait until user-pos or WM-pos reached - reconfigureWindow* - allow -1 values for pos/size to mark no-change
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java104
-rw-r--r--src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java18
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Window.java22
3 files changed, 104 insertions, 40 deletions
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 7c8174a6f..75c3510b7 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -87,7 +87,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
protected CapabilitiesImmutable capsRequested = null;
protected CapabilitiesChooser capabilitiesChooser = null; // default null -> default
protected boolean fullscreen = false, hasFocus = false;
- protected int width = 128, height = 128, x = 0, y = 0; // client-area size/pos w/o insets
+ protected int width = 128, height = 128; // client-area size w/o insets, default: may be overwritten by user
+ protected int x = -1, y = -1; // client-area pos w/o insets, default: undefined (allow WM to choose if not set by user)
protected Insets insets = new Insets(); // insets of decoration (if top-level && decorated)
protected int nfs_width, nfs_height, nfs_x, nfs_y; // non fullscreen client-area size/pos w/o insets
@@ -257,9 +258,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")");
}
+ final boolean userPos = 0<=x && 0<=y; // user has specified a position
+
if( null != parentWindow &&
NativeSurface.LOCK_SURFACE_NOT_READY >= parentWindow.lockSurface() ) {
- throw new NativeWindowException("Parent surface lock: not ready: "+parentWindow);
+ throw new NativeWindowException("Parent surface lock: not ready: "+parentWindow);
+ }
+ if( !userPos && ( isUndecorated() || null != parentWindow ) ) {
+ // default child/undecorated window position is 0/0, if not set by user
+ x = 0; y = 0;
}
try {
if(validateParentWindowHandle()) {
@@ -267,11 +274,19 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
throw new InternalError("XXX");
}
if(canCreateNativeImpl()) {
+ final int _x = x, _y = y; // orig req pos
screen.addReference();
screenReferenceAdded = true;
createNativeImpl();
screen.addScreenModeListener(screenModeListenerImpl);
setTitleImpl(title);
+ waitForVisible(true, false);
+ if(userPos) {
+ // wait for user req position
+ waitForPosSize(_x, _y, -1, -1, false, TIMEOUT_NATIVEWINDOW);
+ } else {
+ waitForAnyPos(false, TIMEOUT_NATIVEWINDOW);
+ }
}
// always flag visible,
// allowing to retry if visible && !isNativeValid()
@@ -413,10 +428,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
* to insets and positioning a decorated window to 0/0, which would place the frame
* outside of the screen.</p>
*
- * @param x client-area position
- * @param y client-area position
- * @param width client-area size
- * @param height client-area size
+ * @param x client-area position, or <0 if unchanged
+ * @param y client-area position, or <0 if unchanged
+ * @param width client-area size, or <=0 if unchanged
+ * @param height client-area size, or <=0 if unchanged
* @param flags bitfield of change and status flags
*
* @see #sizeChanged(int,int)
@@ -1488,21 +1503,33 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
display.dispatchMessagesNative(); // status up2date
boolean wasVisible = isVisible();
- reconfigureWindowImpl(x, y, w, h,
- getReconfigureFlags( ( ( 0 != parentWindowHandle ) ? FLAG_CHANGE_PARENTING : 0 ) |
- FLAG_CHANGE_FULLSCREEN | FLAG_CHANGE_DECORATION, wasVisible) );
+ // Lock parentWindow only during reparenting (attempt)
+ final NativeWindow parentWindowLocked;
+ if( null != parentWindow ) {
+ parentWindowLocked = parentWindow;
+ if( NativeSurface.LOCK_SURFACE_NOT_READY >= parentWindowLocked.lockSurface() ) {
+ throw new NativeWindowException("Parent surface lock: not ready: "+parentWindow);
+ }
+ } else {
+ parentWindowLocked = null;
+ }
+ try {
+ reconfigureWindowImpl(x, y, w, h,
+ getReconfigureFlags( ( ( null != parentWindowLocked ) ? FLAG_CHANGE_PARENTING : 0 ) |
+ FLAG_CHANGE_FULLSCREEN | FLAG_CHANGE_DECORATION, wasVisible) );
+ } finally {
+ if(null!=parentWindowLocked) {
+ parentWindowLocked.unlockSurface();
+ }
+ }
display.dispatchMessagesNative(); // status up2date
-
+
if(wasVisible) {
- // visibility should be implicit if needed by native impl,
- // however .. this is a little fallback code
- if(!WindowImpl.this.waitForVisible(true, true, TIMEOUT_NATIVEWINDOW)) {
- setVisibleImpl(true, x, y, w, h);
- WindowImpl.this.waitForVisible(true, true, TIMEOUT_NATIVEWINDOW);
- display.dispatchMessagesNative(); // status up2date
- }
- // ensure size is set, request focus .. and done
+ setVisibleImpl(true, x, y, w, h);
+ WindowImpl.this.waitForVisible(true, false);
+ display.dispatchMessagesNative(); // status up2date
WindowImpl.this.waitForPosSize(-1, -1, w, h, false, TIMEOUT_NATIVEWINDOW);
+ display.dispatchMessagesNative(); // status up2date
requestFocusImpl(true);
display.dispatchMessagesNative(); // status up2date
@@ -2047,16 +2074,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
DisplayImpl display = (DisplayImpl) screen.getDisplay();
for(long sleep = timeOut; 0<sleep && this.visible != visible; sleep-=10 ) {
display.dispatchMessagesNative(); // status up2date
- try {
- Thread.sleep(10);
- } catch (InterruptedException ie) {}
+ try { Thread.sleep(10); } catch (InterruptedException ie) {}
sleep -=10;
}
if(this.visible != visible) {
+ final String msg = "Visibility not reached as requested within "+timeOut+"ms : requested "+visible+", is "+this.visible;
if(failFast) {
- throw new NativeWindowException("Visibility not reached as requested within "+timeOut+"ms : requested "+visible+", is "+this.visible);
+ throw new NativeWindowException(msg);
} else if (DEBUG_IMPLEMENTATION) {
- System.err.println("******* Visibility not reached as requested within "+timeOut+"ms : requested "+visible+", is "+this.visible);
+ System.err.println(msg);
}
}
return this.visible == visible;
@@ -2091,17 +2117,39 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
reached = true;
} else {
display.dispatchMessagesNative(); // status up2date
- try {
- Thread.sleep(10);
- } catch (InterruptedException ie) {}
+ try { Thread.sleep(10); } catch (InterruptedException ie) {}
+ sleep -=10;
+ }
+ }
+ if(!reached) {
+ final String msg = "Size/Pos not reached as requested within "+timeOut+"ms : requested "+x+"/"+y+" "+w+"x"+h+", is "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight();
+ if(failFast) {
+ throw new NativeWindowException(msg);
+ } else if (DEBUG_IMPLEMENTATION) {
+ System.err.println(msg);
+ }
+ }
+ return reached;
+ }
+
+ private boolean waitForAnyPos(boolean failFast, long timeOut) {
+ DisplayImpl display = (DisplayImpl) screen.getDisplay();
+ boolean reached = false;
+ for(long sleep = timeOut; !reached && 0<sleep; sleep-=10 ) {
+ if( 0<=getX() && 0<=getY() ) {
+ reached = true;
+ } else {
+ display.dispatchMessagesNative(); // status up2date
+ try { Thread.sleep(10); } catch (InterruptedException ie) {}
sleep -=10;
}
}
if(!reached) {
+ final String msg = "Any Pos not reached as requested within "+timeOut+"ms : is "+getX()+"/"+getY();
if(failFast) {
- throw new NativeWindowException("Size/Pos not reached as requested within "+timeOut+"ms : requested "+x+"/"+y+" "+w+"x"+h+", is "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight());
+ throw new NativeWindowException(msg);
} else if (DEBUG_IMPLEMENTATION) {
- System.err.println("********** Size/Pos not reached as requested within "+timeOut+"ms : requested "+x+"/"+y+" "+w+"x"+h+", is "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight());
+ System.err.println(msg);
}
}
return reached;
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
index a78014468..7dd67e62b 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
@@ -156,14 +156,18 @@ public class WindowsWindow extends WindowImpl {
final InsetsImmutable i = getInsets();
// client position -> top-level window position
- x -= i.getLeftWidth() ;
- y -= i.getTopHeight() ;
- if( 0 > x ) { x = 0; }
- if( 0 > y ) { y = 0; }
+ if(0<=x && 0<=y) {
+ x -= i.getLeftWidth() ;
+ y -= i.getTopHeight() ;
+ if( 0 > x ) { x = 0; }
+ if( 0 > y ) { y = 0; }
+ }
- // client size -> top-level window size
- width += i.getTotalWidth();
- height += i.getTotalHeight();
+ if(0<width && 0<height) {
+ // client size -> top-level window size
+ width += i.getTotalWidth();
+ height += i.getTotalHeight();
+ }
}
reconfigureWindow0( getParentWindowHandle(), getWindowHandle(), x, y, width, height, flags);
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
index 416bdbdf0..3c48ba4bf 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
@@ -34,6 +34,8 @@
package jogamp.newt.driver.x11;
import jogamp.nativewindow.x11.X11Util;
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.DisplayImpl.DisplayRunnable;
import jogamp.newt.WindowImpl;
import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
@@ -99,7 +101,7 @@ public class X11Window extends WindowImpl {
getReconfigureFlagsAsString(null, flags));
}
- if(0 == ( FLAG_IS_UNDECORATED & flags)) {
+ if(0 == ( FLAG_IS_UNDECORATED & flags) && 0<=x && 0<=y) {
final InsetsImmutable i = getInsets();
// client position -> top-level window position
@@ -119,12 +121,18 @@ public class X11Window extends WindowImpl {
}
@Override
- protected void setTitleImpl(String title) {
- setTitle0(getDisplayEDTHandle(), getWindowHandle(), title);
+ protected void setTitleImpl(final String title) {
+ runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ public Object run(long dpy) {
+ setTitle0(dpy, getWindowHandle(), title);
+ return null;
+ }
+ });
}
- protected Point getLocationOnScreenImpl(int x, int y) {
- return X11Util.GetRelativeLocation( getDisplayEDTHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y);
+ protected Point getLocationOnScreenImpl(final int x, final int y) {
+ // X11Util.GetRelativeLocation: locks display already !
+ return X11Util.GetRelativeLocation( getScreen().getDisplay().getHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y);
}
protected void updateInsetsImpl(Insets insets) {
@@ -138,6 +146,10 @@ public class X11Window extends WindowImpl {
private final long getDisplayEDTHandle() {
return ((X11Display) getScreen().getDisplay()).getEDTHandle();
}
+ private final Object runWithLockedDisplayHandle(DisplayRunnable action) {
+ return ((DisplayImpl) getScreen().getDisplay()).runWithLockedDisplayHandle(action);
+ // return runWithTempDisplayHandle(action);
+ }
protected static native boolean initIDs0();
private native long CreateWindow0(long parentWindowHandle, long display, int screen_index,