From 0feca163be47db2ea94f7546e696136d6f9496e9 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 23 Sep 2010 16:21:39 +0200 Subject: NEWT: Fix Display/Window/Screen OO Identity, Reparenting and requestFocus NativeWindow: Interface NativeWindow changes: - Remove 'throws' qualifier in lockSurface(), since it is not - Adding convenient 'one call' isSurfaceLockedByOtherThread() - Adding getSurfaceLockOwner() NEWT Window/GLWindow: - Unclutter Window/GLWindow relationship - save Window's indentity GLWindow's role is a GLAutoDrawable implementation aggregating (maybe even compositioning) a Window. The previous implementation just derived from the Window implementation, overwriting methods and fields - impossible to ensure sanity / completness. It was also not ensured that the added functionality of GLWindow (setVisible, destroy, ..) has been issued in case of handling the aggregated Window alone (window callbacks, ..). To solve this issue in a 1st attempt without changing the GLWindow API, Window is just an interface, being implemented by their specializations, hence sanity is intrinsic. GLWindow's added functionality is ensured by a Window.LifecycleHook interfaced implementation, registered at the aggregated Window. - Screen and Window are interfaces now (new files) - Display is an abstract class. - Their (abstract) implementations resides in impl/Impl - GLWindow implements Window as well - Remove Screen reference handled by setScreen(Screen) method. - Lock native parentWindow if used (createNative/reparenting) - Move lockSurface/unlockSurface from unchecked override pattern to an callback style using abstract methods lockSurfaceImpl/... - Sorting all methods to semantic sections, abstract, superinterface, .. - Reparenting: Handling different reparenting situations: - Unchanged - No change - Native Reparenting - Compatible Display/Screen, try native reparenting - Native (Re)Creation - Use destroy/create pattern - Native Creation Pending - Create later - setUndecorated() calls reconfigure Window now, ie tries to change the window actually - Don't issue 'requestFocus()' directly from the native implementation anymore, call it from the Java code. - Window/GLWindow/NewtFactory: Constructor simplification Avoid explosion of constructor overloading, ie removing the 'undecorated' variant, since this is redundant due to the 'setUndecorated(boolean)' method. - Fixed/added API documentation --- src/newt/native/X11Window.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/newt/native/X11Window.c') diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 61575c947..350a0a704 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -393,27 +393,22 @@ static Window NewtWindows_getParent (Display *dpy, Window w) { return 0; } */ -static void NewtWindows_requestFocus0 (JNIEnv *env, jobject window, Display *dpy, Window w, XWindowAttributes *xwa, - Bool reparented){ +static void NewtWindows_requestFocus (JNIEnv *env, jobject window, Display *dpy, Window w, + Bool reparented) { + XWindowAttributes xwa; Window focus_return; int revert_to_return; + + XGetWindowAttributes(dpy, w, &xwa); XGetInputFocus(dpy, &focus_return, &revert_to_return); if(reparented || focus_return!=w) { // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable if( JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { - if(xwa->map_state == IsViewable) { + if(xwa.map_state == IsViewable) { XSetInputFocus(dpy, w, RevertToParent, CurrentTime); } } } -} - -static void NewtWindows_requestFocus1 (JNIEnv *env, jobject window, Display *dpy, Window w, - Bool reparented) { - XWindowAttributes xwa; - - XGetWindowAttributes(dpy, w, &xwa); - NewtWindows_requestFocus0 (env, window, dpy, w, &xwa, reparented); XSync(dpy, False); } @@ -904,7 +899,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CloseWindow0 XUnmapWindow(dpy, w); // Drain all events related to this window .. - JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages0(env, obj, display, javaObjectAtom, wmDeleteAtom); + Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages0(env, obj, display, javaObjectAtom, wmDeleteAtom); XDestroyWindow(dpy, w); XSync(dpy, False); @@ -1028,9 +1023,6 @@ static void NewtWindows_reparentWindow if(JNI_TRUE == isVisible) { XMapRaised(dpy, w); XSync(dpy, False); - - NewtWindows_requestFocus0 ( env, obj, dpy, w, xwa, True ); - XSync(dpy, False); } DBG_PRINT( "X11: reparentWindow X\n"); @@ -1038,10 +1030,10 @@ static void NewtWindows_reparentWindow /* * Class: com_jogamp_newt_impl_x11_X11Window - * Method: setPosSizeDecor0 + * Method: reconfigureWindow0 * Signature: (JJIJIIIIZ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setPosSizeDecor0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_reconfigureWindow0 (JNIEnv *env, jobject obj, jlong jparent, jlong display, jint screen_index, jlong window, jint x, jint y, jint width, jint height, jboolean undecorated, jboolean isVisible) { @@ -1052,7 +1044,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setPosSizeDecor0 XWindowChanges xwc; XWindowAttributes xwa; - DBG_PRINT( "X11: setPosSizeDecor0 dpy %p, parent %p, win %p, %d/%d %dx%d undec %d, visible %d\n", + DBG_PRINT( "X11: reconfigureWindow0 dpy %p, parent %p, win %p, %d/%d %dx%d undec %d, visible %d\n", (void*)dpy, (void*) jparent, (void*)w, x, y, width, height, undecorated, isVisible); if(dpy==NULL) { @@ -1110,9 +1102,9 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_reparentWindow0 * Signature: (JJ)V */ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_requestFocus0 - (JNIEnv *env, jobject obj, jlong display, jlong window) + (JNIEnv *env, jobject obj, jlong display, jlong window, jboolean bReparented) { - NewtWindows_requestFocus1 ( env, obj, (Display *) (intptr_t) display, (Window)window, False ) ; + NewtWindows_requestFocus ( env, obj, (Display *) (intptr_t) display, (Window)window, bReparented ) ; } /* -- cgit v1.2.3