diff options
author | Sven Gothel <[email protected]> | 2011-09-15 05:43:29 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-15 05:43:29 +0200 |
commit | 0b753d75c36af7dd5bb0864f02b934a51991e658 (patch) | |
tree | 7e353240786a49e0f1f592d95bba74fe65774ab8 /src | |
parent | 1b7844b9422472aa1c5089ed8c4918eb6ebcfd23 (diff) |
NEWT X11/Windows: Fix AlwaysOnTop (startup and change)
Diffstat (limited to 'src')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java | 8 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/x11/X11Window.java | 17 | ||||
-rw-r--r-- | src/newt/native/WindowsWindow.c | 46 | ||||
-rw-r--r-- | src/newt/native/X11Window.c | 32 |
4 files changed, 56 insertions, 47 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java index 7dd67e62b..9c80f0f85 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java @@ -104,8 +104,10 @@ public class WindowsWindow extends WindowImpl { if (config == null) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + final int flags = getReconfigureFlags(0, true) & + ( FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED ) ; setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(), - getParentWindowHandle(), 0, isUndecorated(), x, y, width, height)); + getParentWindowHandle(), x, y, width, height, flags)); if (getWindowHandle() == 0) { throw new NativeWindowException("Error creating window"); } @@ -201,8 +203,8 @@ public class WindowsWindow extends WindowImpl { protected static native long getNewtWndProc0(); private native long CreateWindow0(long hInstance, String wndClassName, String wndName, - long parentWindowHandle, long visualID, boolean isUndecorated, - int x, int y, int width, int height); + long parentWindowHandle, + int x, int y, int width, int height, int flags); private native long MonitorFromWindow0(long windowHandle); private native void reconfigureWindow0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, int flags); diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java index 3c48ba4bf..08db72acd 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java +++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java @@ -66,16 +66,17 @@ public class X11Window extends WindowImpl { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; - long visualID = x11config.getVisualID(); - long w = CreateWindow0(getParentWindowHandle(), + final long visualID = x11config.getVisualID(); + final int flags = getReconfigureFlags(0, true) & + ( FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED ) ; + setWindowHandle(CreateWindow0(getParentWindowHandle(), display.getEDTHandle(), screen.getIndex(), visualID, display.getJavaObjectAtom(), display.getWindowDeleteAtom(), - x, y, width, height, isUndecorated()); - if (w == 0) { - throw new NativeWindowException("Error creating window: "+w); + x, y, width, height, flags)); + windowHandleClose = getWindowHandle(); + if (0 == windowHandleClose) { + throw new NativeWindowException("Error creating window"); } - setWindowHandle(w); - windowHandleClose = w; } protected void closeNativeImpl() { @@ -154,7 +155,7 @@ public class X11Window extends WindowImpl { protected static native boolean initIDs0(); 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); + int x, int y, int width, int height, 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); diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 6990bcb83..43a5e8459 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1284,14 +1284,14 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_getNewtWnd return (jlong) (intptr_t) wndProc; } -static void NewtWindow_setVisiblePosSize(HWND hwnd, BOOL top, BOOL visible, +static void NewtWindow_setVisiblePosSize(HWND hwnd, BOOL atop, BOOL visible, int x, int y, int width, int height) { UINT flags; BOOL bRes; - DBG_PRINT("*** WindowsWindow: NewtWindow_setVisiblePosSize %d/%d %dx%d, top %d, visible %d\n", - x, y, width, height, top, visible); + DBG_PRINT("*** WindowsWindow: NewtWindow_setVisiblePosSize %d/%d %dx%d, atop %d, visible %d\n", + x, y, width, height, atop, visible); if(visible) { flags = SWP_SHOWWINDOW; @@ -1305,7 +1305,14 @@ static void NewtWindow_setVisiblePosSize(HWND hwnd, BOOL top, BOOL visible, flags |= SWP_NOSIZE; } - SetWindowPos(hwnd, top ? HWND_TOPMOST : HWND_TOP, x, y, width, height, flags); + if(atop) { + SetWindowPos(hwnd, HWND_TOP, x, y, width, height, flags); + SetWindowPos(hwnd, HWND_TOPMOST, x, y, width, height, flags); + } else { + SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, width, height, flags); + SetWindowPos(hwnd, HWND_TOP, x, y, width, height, flags); + } + // SetWindowPos(hwnd, atop ? HWND_TOPMOST : HWND_TOP, x, y, width, height, flags); InvalidateRect(hwnd, NULL, TRUE); UpdateWindow(hwnd); @@ -1318,8 +1325,8 @@ static void NewtWindow_setVisiblePosSize(HWND hwnd, BOOL top, BOOL visible, JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_CreateWindow0 (JNIEnv *env, jobject obj, jlong hInstance, jstring jWndClassName, jstring jWndName, - jlong parent, jlong visualID, jboolean bIsUndecorated, - jint jx, jint jy, jint defaultWidth, jint defaultHeight) + jlong parent, + jint jx, jint jy, jint defaultWidth, jint defaultHeight, jint flags) { HWND parentWindow = (HWND) (intptr_t) parent; const TCHAR* wndClassName = NULL; @@ -1338,14 +1345,13 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_CreateWind wndName = (*env)->GetStringUTFChars(env, jWndName, NULL); #endif - - if(NULL!=parentWindow) { + if( NULL!=parentWindow ) { if (!IsWindow(parentWindow)) { DBG_PRINT("*** WindowsWindow: CreateWindow failure: Passed parentWindow %p is invalid\n", parentWindow); return 0; } windowStyle |= WS_CHILD ; - } else if (bIsUndecorated) { + } else if ( TST_FLAG_IS_UNDECORATED(flags) ) { windowStyle |= WS_POPUP | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; } else { windowStyle |= WS_OVERLAPPEDWINDOW; @@ -1356,16 +1362,15 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_CreateWind } } - (void) visualID; // FIXME: use the visualID .. - window = CreateWindow(wndClassName, wndName, windowStyle, _x, _y, width, height, parentWindow, NULL, (HINSTANCE) (intptr_t) hInstance, NULL); - DBG_PRINT("*** WindowsWindow: CreateWindow thread 0x%X, parent %p, window %p, %d/%d %dx%d\n", - (int)GetCurrentThreadId(), parentWindow, window, x, y, width, height); + DBG_PRINT("*** WindowsWindow: CreateWindow thread 0x%X, parent %p, window %p, %d/%d %dx%d, undeco %d, alwaysOnTop %d\n", + (int)GetCurrentThreadId(), parentWindow, window, x, y, width, height, + TST_FLAG_IS_UNDECORATED(flags), TST_FLAG_IS_ALWAYSONTOP(flags)); if (NULL == window) { int lastError = (int) GetLastError(); @@ -1410,8 +1415,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_CreateWind // mark pos as undef, which cases java to wait for WM reported pos (*env)->CallVoidMethod(env, wud->jinstance, positionChangedID, -1, -1); } - NewtWindow_setVisiblePosSize(window, (NULL == parentWindow) ? TRUE : FALSE /* top */, - TRUE, x, y, width, height); + NewtWindow_setVisiblePosSize(window, TST_FLAG_IS_ALWAYSONTOP(flags), TRUE, x, y, width, height); } } @@ -1473,11 +1477,12 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_reconfigure DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN ; BOOL styleChange = TST_FLAG_CHANGE_DECORATION(flags) || TST_FLAG_CHANGE_FULLSCREEN(flags) || TST_FLAG_CHANGE_PARENTING(flags) ; - DBG_PRINT( "*** WindowsWindow: reconfigureWindow0 parent %p, window %p, %d/%d %dx%d, parentChange %d, hasParent %d, decorationChange %d, undecorated %d, fullscreenChange %d, fullscreen %d, visibleChange %d, visible %d -> styleChange %d\n", + DBG_PRINT( "*** WindowsWindow: reconfigureWindow0 parent %p, window %p, %d/%d %dx%d, parentChange %d, hasParent %d, decorationChange %d, undecorated %d, fullscreenChange %d, fullscreen %d, alwaysOnTopChange %d, alwaysOnTop %d, visibleChange %d, visible %d -> styleChange %d\n", parent, window, x, y, width, height, - TST_FLAG_CHANGE_PARENTING(flags), TST_FLAG_HAS_PARENT(flags), - TST_FLAG_CHANGE_DECORATION(flags), TST_FLAG_IS_UNDECORATED(flags), - TST_FLAG_CHANGE_FULLSCREEN(flags), TST_FLAG_IS_FULLSCREEN(flags), + TST_FLAG_CHANGE_PARENTING(flags), TST_FLAG_HAS_PARENT(flags), + TST_FLAG_CHANGE_DECORATION(flags), TST_FLAG_IS_UNDECORATED(flags), + TST_FLAG_CHANGE_FULLSCREEN(flags), TST_FLAG_IS_FULLSCREEN(flags), + TST_FLAG_CHANGE_ALWAYSONTOP(flags), TST_FLAG_IS_ALWAYSONTOP(flags), TST_FLAG_CHANGE_VISIBILITY(flags), TST_FLAG_IS_VISIBLE(flags), styleChange); if (!IsWindow(hwnd)) { @@ -1530,8 +1535,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_reconfigure SetParent(hwnd, hwndP ); } - NewtWindow_setVisiblePosSize(hwnd, (NULL == hwndP) ? TRUE : FALSE /* top */, - TST_FLAG_IS_VISIBLE(flags), x, y, width, height); + NewtWindow_setVisiblePosSize(hwnd, TST_FLAG_IS_ALWAYSONTOP(flags), TST_FLAG_IS_VISIBLE(flags), x, y, width, height); if( TST_FLAG_CHANGE_VISIBILITY(flags) ) { if( TST_FLAG_IS_VISIBLE(flags) ) { diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index ece11775e..5a7aadd3e 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -635,7 +635,7 @@ static int NewtWindows_isFullscreenEWMHSupported (Display *dpy, Window w) { return res; } -static Bool NewtWindows_setFullscreenEWMH (Display *dpy, Window root, Window w, int emwhMask, Bool isVisible, Bool fullscreen) { +static Bool NewtWindows_setFullscreenEWMH (Display *dpy, Window root, Window w, int emwhMask, Bool isVisible, Bool enable) { Atom _NET_WM_STATE = XInternAtom( dpy, "_NET_WM_STATE", False ); Atom _NET_WM_STATE_ABOVE = XInternAtom( dpy, "_NET_WM_STATE_ABOVE", False ); Atom _NET_WM_STATE_FULLSCREEN = XInternAtom( dpy, "_NET_WM_STATE_FULLSCREEN", False ); @@ -645,7 +645,7 @@ static Bool NewtWindows_setFullscreenEWMH (Display *dpy, Window root, Window w, return False; } - if(!isVisible && True==fullscreen) { + if(!isVisible && True==enable) { // Update Client State first (-> ABOVE) Atom types[2]={0}; int ntypes=0; @@ -658,9 +658,9 @@ static Bool NewtWindows_setFullscreenEWMH (Display *dpy, Window root, Window w, } XChangeProperty( dpy, w, _NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *)&types, ntypes); XSync(dpy, False); - DBG_PRINT( "X11: reconfigureWindow0 FULLSCREEN Old on:%d (xsend-status %d)\n", fullscreen, s); + DBG_PRINT( "X11: reconfigureWindow0 FULLSCREEN Old on:%d (xsend-status %d)\n", enable, s); } else { - if(fullscreen) { + if(enable) { NewtWindows_setCWAbove(dpy, w); } XEvent xev; @@ -675,7 +675,7 @@ static Bool NewtWindows_setFullscreenEWMH (Display *dpy, Window root, Window w, xev.xclient.message_type = _NET_WM_STATE; xev.xclient.format = 32; - xev.xclient.data.l[i++] = ( True == fullscreen ) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE ; + xev.xclient.data.l[i++] = ( True == enable ) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE ; if( 0 != ( _NET_WM_ACTION_FULLSCREEN_SUPPORTED & emwhMask ) ) { xev.xclient.data.l[i++] = _NET_WM_STATE_FULLSCREEN; } @@ -687,7 +687,7 @@ static Bool NewtWindows_setFullscreenEWMH (Display *dpy, Window root, Window w, s = XSendEvent (dpy, root, False, mask, &xev ); } XSync(dpy, False); - DBG_PRINT( "X11: reconfigureWindow0 FULLSCREEN EWMH ON %d, emwhMask 0x%X, visible %d (xsend-status %d)\n", fullscreen, emwhMask, isVisible, s); + DBG_PRINT( "X11: reconfigureWindow0 FULLSCREEN EWMH ON %d, emwhMask 0x%X, visible %d (xsend-status %d)\n", enable, emwhMask, isVisible, s); return Success == s; } @@ -1489,12 +1489,12 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 (JNIEnv *env, jobject obj, jlong parent, jlong display, jint screen_index, jlong visualID, jlong javaObjectAtom, jlong windowDeleteAtom, - jint x, jint y, jint width, jint height, - jboolean undecorated) + jint x, jint y, jint width, jint height, int flags) { Display * dpy = (Display *)(intptr_t)display; Atom wm_delete_atom = (Atom)windowDeleteAtom; int scrn_idx = (int)screen_index; + Window root = RootWindow(dpy, scrn_idx); Window windowParent = (Window) parent; Window window = 0; jobject jwindow = 0; @@ -1523,13 +1523,11 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 scrn = ScreenOfDisplay(dpy, scrn_idx); if(0==windowParent) { - windowParent = XRootWindowOfScreen(scrn); + windowParent = root; } - if( XRootWindowOfScreen(scrn) != XRootWindow(dpy, scrn_idx) ) { - NewtCommon_FatalError(env, "XRoot Malfunction: %p != %p"+XRootWindowOfScreen(scrn), XRootWindow(dpy, scrn_idx)); - } - DBG_PRINT( "X11: CreateWindow dpy %p, parent %p, %x/%d %dx%d, undeco %d\n", - (void*)dpy, (void*)windowParent, x, y, width, height, undecorated); + DBG_PRINT( "X11: CreateWindow dpy %p, parent %p, %x/%d %dx%d, undeco %d, alwaysOnTop %d\n", + (void*)dpy, (void*)windowParent, x, y, width, height, + TST_FLAG_IS_UNDECORATED(flags), TST_FLAG_IS_ALWAYSONTOP(flags)); // try given VisualID on screen memset(&visualTemplate, 0, sizeof(XVisualInfo)); @@ -1605,7 +1603,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 jwindow = (*env)->NewGlobalRef(env, obj); setJavaWindowProperty(env, dpy, window, javaObjectAtom, jwindow); - NewtWindows_setDecorations(dpy, window, ( JNI_TRUE == undecorated ) ? False : True ); + NewtWindows_setDecorations(dpy, window, TST_FLAG_IS_UNDECORATED(flags) ? False : True ); XSync(dpy, False); // since native creation happens at setVisible(true) .. @@ -1641,6 +1639,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 (*env)->CallVoidMethod(env, jwindow, positionChangedID, -1, -1); } NewtWindows_setPosSize(dpy, window, x, y, width, height); + + if( TST_FLAG_IS_ALWAYSONTOP(flags) ) { + NewtWindows_setFullscreenEWMH(dpy, root, window, _NET_WM_ACTION_ABOVE_SUPPORTED, True, True); + } } DBG_PRINT( "X11: [CreateWindow] created window %p on display %p\n", (void*)window, dpy); |