From 340b1ceb07907be113e33c54d084e53ddc93e368 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 3 Sep 2010 00:06:03 +0300 Subject: NEWT: Focus Fix + Cleanup Issueing 'requestFocus' via the native EDT dispatch loop may cause a deadlock, due to a possible implicite AWT requestFocus call (NewtCanvasAWT). Approach: RequestFocus issued directly, by Window.requestFocus() and the native EDT dispatch loop, is queued for later execution by EDT. This shall decouple a possible native windowing TK resource collision. - X11Windows.c: Add missing 'reparented' param for requestFocus to force requestFocus after reparenting. - AWTWindow.java: Add requestFocusImpl() +++ NEWT: Cleanup - Remove Event Type Bits in: - EventListener.h - NEWTEventListener.java - Remove InputEvent 'consume' status - --- .../com/jogamp/opengl/impl/GLContextImpl.java | 20 +++++++-------- .../junit/newt/parenting/TestParenting01cAWT.java | 3 --- src/newt/classes/com/jogamp/newt/Display.java | 6 ++--- src/newt/classes/com/jogamp/newt/Window.java | 28 +++++++++++++------- .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 30 ++++++++++------------ .../classes/com/jogamp/newt/event/InputEvent.java | 9 ------- .../classes/com/jogamp/newt/event/NEWTEvent.java | 9 +++++++ .../com/jogamp/newt/event/NEWTEventConsumer.java | 4 +-- .../com/jogamp/newt/event/NEWTEventListener.java | 5 ---- .../com/jogamp/newt/impl/awt/AWTDisplay.java | 2 +- .../com/jogamp/newt/impl/awt/AWTWindow.java | 8 ++++++ src/newt/native/BroadcomEGL.c | 1 - src/newt/native/EventListener.h | 9 ------- src/newt/native/IntelGDL.c | 1 - src/newt/native/KDWindow.c | 1 - src/newt/native/MacWindow.m | 1 - src/newt/native/WindowsWindow.c | 19 +++++++++----- src/newt/native/X11Window.c | 28 +++++++++++++------- 18 files changed, 98 insertions(+), 86 deletions(-) delete mode 100644 src/newt/native/EventListener.h diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java index 61705439e..9dc77679b 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java @@ -250,14 +250,14 @@ public abstract class GLContextImpl extends GLContext { * MakeCurrent functionality, which also issues the creation of the actual OpenGL context.
* The complete callgraph for general OpenGL context creation is:
* *
* * Once at startup, ie triggered by the singleton constructor of a {@link GLDrawableFactoryImpl} specialization, @@ -267,10 +267,10 @@ public abstract class GLContextImpl extends GLContext { * + *
  • {@link #createContextARBVersions}
  • + * + *
  • {@link #mapVersionAvailable}
  • + * *
    * * @see #makeCurrentImpl diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java index 0233a6aad..abd5b95ce 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java @@ -73,7 +73,6 @@ public class TestParenting01cAWT { static int width, height; static long durationPerTest = 800; - static long waitReparent = 0; static GLCapabilities glCaps; @BeforeClass @@ -232,8 +231,6 @@ public class TestParenting01cAWT { for(int i=0; i * The NEWT will automatically handle the event semantics internally, regardless of whether a program is receiving these events or not.
    * The actual event semantic is processed before the event is send.
    + * + * Event type registry:
    + *
    */ public class NEWTEvent extends java.util.EventObject { private boolean isSystemEvent; @@ -61,6 +68,8 @@ public class NEWTEvent extends java.util.EventObject { // 2: com.jogamp.newt.Window // 2: com.jogamp.newt.event.awt.AWTNewtEventFactory // + // FIXME: verify the isSystemEvent evaluation + // static final String WindowClazzName = "com.jogamp.newt.Window" ; static final String AWTNewtEventFactoryClazzName = "com.jogamp.newt.event.awt.AWTNewtEventFactory" ; diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java index e37c820a1..d3d897f3b 100644 --- a/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java @@ -36,8 +36,8 @@ public interface NEWTEventConsumer { /** * Consume the event * - * @return true if the event can be consumed now, - * otherwise propagate it later. + * @return true if the event has been consumed, + * otherwise it returns false for later propagation. */ public boolean consumeEvent(NEWTEvent event); } diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java index 2a187f8c4..90d00383d 100644 --- a/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java @@ -37,10 +37,5 @@ import com.jogamp.newt.*; public interface NEWTEventListener extends java.util.EventListener { - public static final int WINDOW = 1 << 0; - public static final int MOUSE = 1 << 1; - public static final int KEY = 1 << 2; - public static final int SURFACE = 1 << 3; - } diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java index e705d364a..92c4e53eb 100644 --- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java @@ -54,7 +54,7 @@ public class AWTDisplay extends Display { protected void closeNative() { } - public boolean runCreateAndDestroyOnEDT() { + protected boolean getShallRunOnEDT() { return false; } protected void dispatchMessagesNative() { /* nop */ } 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 56e5a4240..db55aee6f 100644 --- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java @@ -84,6 +84,14 @@ public class AWTWindow extends Window { // non fullscreen dimensions .. private int nfs_width, nfs_height, nfs_x, nfs_y; + protected void requestFocusImpl() { + runOnEDT(true, new Runnable() { + public void run() { + container.requestFocus(); + } + }); + } + protected void setTitleImpl(final String title) { runOnEDT(true, new Runnable() { public void run() { diff --git a/src/newt/native/BroadcomEGL.c b/src/newt/native/BroadcomEGL.c index 7bb21cd3b..ddac0ef45 100644 --- a/src/newt/native/BroadcomEGL.c +++ b/src/newt/native/BroadcomEGL.c @@ -43,7 +43,6 @@ #include "com_jogamp_newt_impl_opengl_broadcom_egl_Window.h" -#include "EventListener.h" #include "MouseEvent.h" #include "KeyEvent.h" diff --git a/src/newt/native/EventListener.h b/src/newt/native/EventListener.h deleted file mode 100644 index 2e0e92323..000000000 --- a/src/newt/native/EventListener.h +++ /dev/null @@ -1,9 +0,0 @@ - -#ifndef _EVENT_LISTSENER_H -#define _EVENT_LISTSENER_H - -#define EVENT_WINDOW (1 << 0) -#define EVENT_MOUSE (1 << 1) -#define EVENT_KEY (1 << 2) - -#endif diff --git a/src/newt/native/IntelGDL.c b/src/newt/native/IntelGDL.c index 8a4d7172c..eb6becbbd 100644 --- a/src/newt/native/IntelGDL.c +++ b/src/newt/native/IntelGDL.c @@ -41,7 +41,6 @@ #include "com_jogamp_newt_impl_intel_gdl_Screen.h" #include "com_jogamp_newt_impl_intel_gdl_Window.h" -#include "EventListener.h" #include "MouseEvent.h" #include "KeyEvent.h" diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c index b67b8dbd3..75a2fe1a1 100644 --- a/src/newt/native/KDWindow.c +++ b/src/newt/native/KDWindow.c @@ -66,7 +66,6 @@ #include "com_jogamp_newt_impl_opengl_kd_KDWindow.h" -#include "EventListener.h" #include "MouseEvent.h" #include "KeyEvent.h" diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 6e8599d92..950a26acc 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -36,7 +36,6 @@ #import "com_jogamp_newt_impl_macosx_MacWindow.h" #import "NewtMacWindow.h" -#import "EventListener.h" #import "MouseEvent.h" #import "KeyEvent.h" diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index cda6a4086..6b8f2b73f 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -91,7 +91,6 @@ #include "com_jogamp_newt_impl_windows_WindowsWindow.h" -#include "EventListener.h" #include "MouseEvent.h" #include "InputEvent.h" #include "KeyEvent.h" @@ -117,9 +116,12 @@ static jmethodID visibleChangedID = NULL; static jmethodID windowDestroyNotifyID = NULL; static jmethodID windowDestroyedID = NULL; static jmethodID windowRepaintID = NULL; +static jmethodID enqueueMouseEventID = NULL; static jmethodID sendMouseEventID = NULL; +static jmethodID enqueueKeyEventID = NULL; static jmethodID sendKeyEventID = NULL; static jmethodID focusActionID = NULL; +static jmethodID enqueueRequestFocusID = NULL; static RECT* UpdateInsets(JNIEnv *env, HWND hwnd, jobject window); @@ -806,7 +808,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, case WM_LBUTTONDOWN: DBG_PRINT("*** WindowsWindow: LBUTTONDOWN\n"); - NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already .. + (*env)->CallVoidMethod(env, window, enqueueRequestFocusID, JNI_FALSE); (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, GetModifiers(), @@ -826,7 +828,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, case WM_MBUTTONDOWN: DBG_PRINT("*** WindowsWindow: MBUTTONDOWN\n"); - NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already .. + (*env)->CallVoidMethod(env, window, enqueueRequestFocusID, JNI_FALSE); (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, GetModifiers(), @@ -846,7 +848,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, case WM_RBUTTONDOWN: DBG_PRINT("*** WindowsWindow: RBUTTONDOWN\n"); - NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already .. + (*env)->CallVoidMethod(env, window, enqueueRequestFocusID, JNI_FALSE); (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, GetModifiers(), @@ -1075,8 +1077,11 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V"); windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V"); + enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZIIIIII)V"); sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZIIIC)V"); sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + enqueueRequestFocusID = (*env)->GetMethodID(env, clazz, "enqueueRequestFocus", "(Z)V"); focusActionID = (*env)->GetMethodID(env, clazz, "focusAction", "()Z"); if (insetsChangedID == NULL || @@ -1087,10 +1092,12 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI windowDestroyNotifyID == NULL || windowDestroyedID == NULL || windowRepaintID == NULL || + enqueueMouseEventID == NULL || sendMouseEventID == NULL || + enqueueKeyEventID == NULL || sendKeyEventID == NULL || - focusActionID == NULL) - { + focusActionID == NULL || + enqueueRequestFocusID == NULL) { return JNI_FALSE; } BuildDynamicKeyMapTable(); diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 11c11915d..61575c947 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -49,7 +49,6 @@ #include "com_jogamp_newt_impl_x11_X11Window.h" -#include "EventListener.h" #include "MouseEvent.h" #include "KeyEvent.h" #include "WindowEvent.h" @@ -160,9 +159,12 @@ static jmethodID windowDestroyNotifyID = NULL; static jmethodID windowDestroyedID = NULL; static jmethodID windowRepaintID = NULL; static jmethodID windowCreatedID = NULL; +static jmethodID enqueueMouseEventID = NULL; static jmethodID sendMouseEventID = NULL; +static jmethodID enqueueKeyEventID = NULL; static jmethodID sendKeyEventID = NULL; static jmethodID focusActionID = NULL; +static jmethodID enqueueRequestFocusID = NULL; static jmethodID displayCompletedID = NULL; @@ -391,11 +393,12 @@ static Window NewtWindows_getParent (Display *dpy, Window w) { return 0; } */ -static void NewtWindows_requestFocus0 (JNIEnv *env, jobject window, Display *dpy, Window w, XWindowAttributes *xwa) { +static void NewtWindows_requestFocus0 (JNIEnv *env, jobject window, Display *dpy, Window w, XWindowAttributes *xwa, + Bool reparented){ Window focus_return; int revert_to_return; XGetInputFocus(dpy, &focus_return, &revert_to_return); - if(focus_return!=w) { + 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) { @@ -405,11 +408,12 @@ static void NewtWindows_requestFocus0 (JNIEnv *env, jobject window, Display *dpy } } -static void NewtWindows_requestFocus1 (JNIEnv *env, jobject window, Display *dpy, Window w) { +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); + NewtWindows_requestFocus0 (env, window, dpy, w, &xwa, reparented); XSync(dpy, False); } @@ -541,7 +545,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages switch(evt.type) { case ButtonPress: - NewtWindows_requestFocus1 ( env, jwindow, dpy, evt.xany.window ); + (*env)->CallVoidMethod(env, jwindow, enqueueRequestFocusID, JNI_FALSE); (*env)->CallVoidMethod(env, jwindow, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, (jint) evt.xbutton.state, @@ -710,8 +714,11 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Window_initIDs0 windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V"); windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V"); windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V"); + enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZIIIIII)V"); sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZIIIC)V"); sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + enqueueRequestFocusID = (*env)->GetMethodID(env, clazz, "enqueueRequestFocus", "(Z)V"); focusActionID = (*env)->GetMethodID(env, clazz, "focusAction", "()Z"); if (sizeChangedID == NULL || @@ -722,9 +729,12 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Window_initIDs0 windowDestroyedID == NULL || windowRepaintID == NULL || windowCreatedID == NULL || + enqueueMouseEventID == NULL || sendMouseEventID == NULL || + enqueueKeyEventID == NULL || sendKeyEventID == NULL || - focusActionID == NULL) { + focusActionID == NULL || + enqueueRequestFocusID == NULL) { return JNI_FALSE; } return JNI_TRUE; @@ -1019,7 +1029,7 @@ static void NewtWindows_reparentWindow XMapRaised(dpy, w); XSync(dpy, False); - NewtWindows_requestFocus0 ( env, obj, dpy, w, xwa ); + NewtWindows_requestFocus0 ( env, obj, dpy, w, xwa, True ); XSync(dpy, False); } @@ -1102,7 +1112,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_reparentWindow0 JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_requestFocus0 (JNIEnv *env, jobject obj, jlong display, jlong window) { - NewtWindows_requestFocus1 ( env, obj, (Display *) (intptr_t) display, (Window)window ) ; + NewtWindows_requestFocus1 ( env, obj, (Display *) (intptr_t) display, (Window)window, False ) ; } /* -- cgit v1.2.3