From de9a419a315d16edee2c5da74bbf7ea1f89bef30 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 9 Sep 2011 17:53:25 +0200 Subject: NEWT/Window: CreateWindow - Wait for user req. position: Fix about window-decoration/insets size --- src/newt/classes/jogamp/newt/WindowImpl.java | 28 ++++++++++++++++++++-------- src/newt/native/WindowsWindow.c | 4 +++- src/newt/native/X11Window.c | 4 +++- 3 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src/newt') diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 75c3510b7..6c71e6082 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -274,18 +274,22 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer throw new InternalError("XXX"); } if(canCreateNativeImpl()) { - final int _x = x, _y = y; // orig req pos + 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); + if(waitForVisible(true, false)) { + if(userPos) { + // fix req position about window decoration + _x = Math.max(_x, insets.getLeftWidth()); + _y = Math.max(_y, insets.getTopHeight()); + // wait for user req position + waitForPosSize(_x, _y, -1, -1, false, TIMEOUT_NATIVEWINDOW); + } else { + waitForAnyPos(false, TIMEOUT_NATIVEWINDOW); + } } } // always flag visible, @@ -387,8 +391,16 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer /** * The native implementation must set the native windowHandle.
* + *

* The implementation should invoke the referenced java state callbacks - * to notify this Java object of state changes. + * to notify this Java object of state changes.

+ * + *

+ * In case the implementation supports a deterministic size/pos mechanism, + * i.e. is able to determine the correct size/pos, + * it shall invalidate such values via the callbacks allowing the caller + * to wait until the values are reached - notified by the WM.
+ * This is currently implemented for X11 and Windows.

* * @see #windowDestroyNotify() * @see #focusChanged(boolean) diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 1cb0f2036..6990bcb83 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1388,9 +1388,11 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_CreateWind BOOL userPos = 0<=x && 0<=y ; ShowWindow(window, SW_SHOW); - (*env)->CallVoidMethod(env, wud->jinstance, visibleChangedID, JNI_TRUE); + // send insets before visibility, allowing java code a proper sync point! insets = UpdateInsets(env, wud->jinstance, window); + (*env)->CallVoidMethod(env, wud->jinstance, visibleChangedID, JNI_TRUE); + if(!userPos) { GetWindowRect(window, &rc); x = rc.left + insets->left; // client coords diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 39e8f9476..90b16a5c3 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -1618,9 +1618,11 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 XMapWindow(dpy, window); XIfEvent( dpy, &event, WaitForMapNotify, (XPointer) window ); // wait to get proper insets values - (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_TRUE); + // send insets before visibility, allowing java code a proper sync point! NewtWindows_updateInsets(env, jwindow, dpy, window, &left, &right, &top, &bottom); + (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_TRUE); + if(!userPos) { // get position from WM int dest_x, dest_y; -- cgit v1.2.3