summaryrefslogtreecommitdiffstats
path: root/src/newt/native/KDWindow.c
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-06-17 13:26:29 +0000
committerSven Gothel <[email protected]>2009-06-17 13:26:29 +0000
commita92906bcb4ce4746f291d40a736949ec8476de61 (patch)
tree49708922895aa07bdc72b0513bb5e90f63ecedb2 /src/newt/native/KDWindow.c
parent802288f8964affbda3460eea52df3d241ae3036a (diff)
- Add: GLProfile.get(name) return default if name=="GL" as well (or if null)
- Add: NEWT pumpMessages/dispatchMessages - Handled by the Display implementation for all windows - Windows .. OK - MacOSX .. OK - X11 .. OK - Added Atom Property handling to attach java window object to window - Removed the eventMask for dispatching messages, since dispatching is for all windows now. (Wasn't impl. for all platforms anyways) - All init static code will funnel in the Display.initSingletion(), to ensure a proper init order for all platforms. - Display creation is unique for (name,thread). Handling a TLS mapping of display-names to Displays. - GLWindow: autoSwapBufferMode and eventHandlerMode are static members - Tested with experimental tagged GLWindow.setRunPumpMessages()/runCurrentThreadPumpMessage(), 1 thread - 4 windows, etc .. java demos.es2.RedSquare -1thread -onepump -GL2 -GL2 -GL2 -GL2 No benefit .. However .. the implementation is more correct now, due to the display/current-thread message pumping. - Fix: Window.sendMouseEvent() bounds check - Fix: MacWindow has proper nsView locking now, local to the window instance. locked in lockSurface besides general window manipulation. - Fix: JAWT utilized JAWTUtil.init() to init libraries - NativeLibLoaderBase.loadNativeWindow("awt") call was missing. (Visible on MacOSX + AWT) - Fix: GLXUtil proper locking - Fix: X11Util proper locking git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1976 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/newt/native/KDWindow.c')
-rwxr-xr-xsrc/newt/native/KDWindow.c252
1 files changed, 126 insertions, 126 deletions
diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c
index d08d5411c..682edff24 100755
--- a/src/newt/native/KDWindow.c
+++ b/src/newt/native/KDWindow.c
@@ -81,16 +81,121 @@
#endif
#endif
-/**
- * Window
- */
-
+#define JOGL_KD_USERDATA_MAGIC 0xDEADBEEF
+typedef struct {
+ long magic;
+ KDWindow * kdWindow;
+ jobject javaWindow;
+} JOGLKDUserdata;
+
+static jmethodID windowCreatedID = NULL;
static jmethodID sizeChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
static jmethodID sendMouseEventID = NULL;
static jmethodID sendKeyEventID = NULL;
+/**
+ * Display
+ */
+
+JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDDisplay_DispatchMessages
+ (JNIEnv *env, jobject obj)
+{
+ const KDEvent * evt;
+ int numEvents = 0;
+
+ // Periodically take a break
+ while( numEvents<100 && NULL!=(evt=kdWaitEvent(0)) ) {
+ KDWindow *kdWindow;
+ jobject javaWindow;
+ JOGLKDUserdata * userData = (JOGLKDUserdata *)(intptr_t)evt->userptr;
+ if(NULL == userData || userData->magic!=JOGL_KD_USERDATA_MAGIC) {
+ DBG_PRINT( "event unrelated: evt type: 0x%X\n", evt->type);
+ continue;
+ }
+ kdWindow = userData->kdWindow;
+ javaWindow = userData->javaWindow;
+ DBG_PRINT( "[DispatchMessages]: userData %p, evt type: 0x%X\n", userData, evt->type);
+
+ numEvents++;
+
+ // FIXME: support resize and window re-positioning events
+
+ switch(evt->type) {
+ case KD_EVENT_WINDOW_FOCUS:
+ {
+ KDboolean hasFocus;
+ kdGetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_FOCUS, &hasFocus);
+ DBG_PRINT( "event window focus : src: %p\n", userData);
+ }
+ break;
+ case KD_EVENT_WINDOW_CLOSE:
+ {
+ DBG_PRINT( "event window close : src: %p\n", userData);
+ (*env)->CallVoidMethod(env, javaWindow, windowDestroyNotifyID);
+ // Called by Window.java: DestroyWindow(wnd);
+ // (*env)->CallVoidMethod(env, javaWindow, windowDestroyedID);
+ }
+ break;
+ case KD_EVENT_WINDOWPROPERTY_CHANGE:
+ {
+ const KDEventWindowProperty* prop = &evt->data.windowproperty;
+ switch (prop->pname) {
+ case KD_WINDOWPROPERTY_SIZE:
+ {
+ KDint32 v[2];
+ if(!kdGetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, v)) {
+ DBG_PRINT( "event window size change : src: %p %dx%d\n", userData, v[0], v[1]);
+ (*env)->CallVoidMethod(env, javaWindow, sizeChangedID, (jint) v[0], (jint) v[1]);
+ } else {
+ DBG_PRINT( "event window size change error: src: %p %dx%d\n", userData, v[0], v[1]);
+ }
+ }
+ break;
+ case KD_WINDOWPROPERTY_FOCUS:
+ DBG_PRINT( "event window focus: src: %p\n", userData);
+ break;
+ case KD_WINDOWPROPERTY_VISIBILITY:
+ {
+ KDboolean visible;
+ kdGetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visible);
+ DBG_PRINT( "event window visibility: src: %p, v:%d\n", userData, visible);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case KD_EVENT_INPUT_POINTER:
+ {
+ const KDEventInputPointer* ptr = &(evt->data.inputpointer);
+ // button idx: evt->data.input.index
+ // pressed = ev->data.input.value.i
+ // time = ev->timestamp
+ if(KD_INPUT_POINTER_SELECT==ptr->index) {
+ DBG_PRINT( "event mouse click: src: %p, s:%d, (%d,%d)\n", userData, ptr->select, ptr->x, ptr->y);
+ (*env)->CallVoidMethod(env, javaWindow, sendMouseEventID,
+ (ptr->select==0) ? (jint) EVENT_MOUSE_RELEASED : (jint) EVENT_MOUSE_PRESSED,
+ (jint) 0,
+ (jint) ptr->x, (jint) ptr->y, 1, 0);
+ } else {
+ DBG_PRINT( "event mouse: src: %d, s:%p, i:0x%X (%d,%d)\n", userData, ptr->select, ptr->index, ptr->x, ptr->y);
+ (*env)->CallVoidMethod(env, javaWindow, sendMouseEventID, (jint) EVENT_MOUSE_MOVED,
+ 0,
+ (jint) ptr->x, (jint) ptr->y, 0, 0);
+ }
+ }
+ break;
+ }
+ }
+}
+
+/**
+ * Window
+ */
+
JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_kd_KDWindow_initIDs
(JNIEnv *env, jclass clazz)
{
@@ -100,12 +205,14 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_kd_KDWindow_initIDs
_wfreopen(TEXT(STDERR_FILE),L"w",stderr);
#endif
#endif
+ windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V");
sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
- if (sizeChangedID == NULL ||
+ if (windowCreatedID == NULL ||
+ sizeChangedID == NULL ||
windowDestroyNotifyID == NULL ||
windowDestroyedID == NULL ||
sendMouseEventID == NULL ||
@@ -118,15 +225,13 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_kd_KDWindow_initIDs
}
JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CreateWindow
- (JNIEnv *env, jobject obj, jint owner, jlong display, jintArray jAttrs)
+ (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs)
{
jint * attrs = NULL;
jsize attrsLen;
EGLDisplay dpy = (EGLDisplay)(intptr_t)display;
KDWindow *window = 0;
- DBG_PRINT( "[CreateWindow]: owner %d\n", owner);
-
if(dpy==NULL) {
fprintf(stderr, "[CreateWindow] invalid display connection..\n");
return 0;
@@ -143,15 +248,21 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CreateWindow
return 0;
}
- /* passing the KDWindow instance for the eventuserptr */
- window = kdCreateWindow(dpy, attrs, (void *)(intptr_t)owner);
+ JOGLKDUserdata * userData = kdMalloc(sizeof(JOGLKDUserdata));
+ userData->magic = JOGL_KD_USERDATA_MAGIC;
+ window = kdCreateWindow(dpy, attrs, (void *)userData);
(*env)->ReleaseIntArrayElements(env, jAttrs, attrs, 0);
if(NULL==window) {
+ kdFree(userData);
fprintf(stderr, "[CreateWindow] failed: 0x%X\n", kdGetError());
+ } else {
+ userData->javaWindow = (*env)->NewGlobalRef(env, obj);
+ userData->kdWindow = window;
+ (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) userData);
+ DBG_PRINT( "[CreateWindow] ok: %p, userdata %p\n", window, userData);
}
- DBG_PRINT( "[CreateWindow] ok: %p, owner %d\n", window, (void *)(intptr_t)owner);
return (jlong) (intptr_t) window;
}
@@ -171,10 +282,13 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_RealizeWindow
}
JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CloseWindow
- (JNIEnv *env, jobject obj, jlong window)
+ (JNIEnv *env, jobject obj, jlong window, jlong juserData)
{
KDWindow *w = (KDWindow*) (intptr_t) window;
+ JOGLKDUserdata * userData = (JOGLKDUserdata*) (intptr_t) juserData;
int res = kdDestroyWindow(w);
+ (*env)->DeleteGlobalRef(env, userData->javaWindow);
+ kdFree(userData);
DBG_PRINT( "[CloseWindow] res: %d\n", res);
return res;
@@ -194,120 +308,6 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setVisible0
DBG_PRINT( "[setVisible] v=%d\n", visible);
}
-JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_DispatchMessages
- (JNIEnv *env, jobject obj, jint owner, jlong window, jint eventMask)
-{
- KDWindow *w = (KDWindow*) (intptr_t) window;
- const KDEvent * evt;
-
- // Periodically take a break
- while( NULL!=(evt=kdWaitEvent(0)) ) {
- jint src_owner = (jint)(intptr_t)evt->userptr;
- if(src_owner != owner) {
- DBG_PRINT( "event unrelated: src: %d, caller: %d, evt type: 0x%X\n", src_owner, owner, evt->type);
- continue;
- }
- DBG_PRINT( "[DispatchMessages]: caller %d, evt type: 0x%X\n", owner, evt->type);
-
- switch(evt->type) {
- case KD_EVENT_INPUT_POINTER:
- if( ! ( eventMask & EVENT_MOUSE ) ) {
- DBG_PRINT( "event mouse ignored: src: %d\n", owner);
- continue;
- }
- break;
- /*
- case KeyPress:
- case KeyRelease:
- if( ! ( eventMask & EVENT_KEY ) ) {
- DBG_PRINT( "event key ignored: src: %d\n", owner);
- continue;
- }
- break;
- */
- case KD_EVENT_WINDOW_FOCUS:
- case KD_EVENT_WINDOW_CLOSE:
- case KD_EVENT_WINDOWPROPERTY_CHANGE:
- case KD_EVENT_WINDOW_REDRAW:
- if( ! ( eventMask & EVENT_WINDOW ) ) {
- DBG_PRINT( "event window ignored: src: %d\n", owner);
- continue;
- }
- break;
- }
-
- // FIXME: support resize and window re-positioning events
-
- switch(evt->type) {
- case KD_EVENT_WINDOW_FOCUS:
- {
- KDboolean hasFocus;
- kdGetWindowPropertybv(w, KD_WINDOWPROPERTY_FOCUS, &hasFocus);
- DBG_PRINT( "event window focus : src: %d\n", owner);
- }
- break;
- case KD_EVENT_WINDOW_CLOSE:
- {
- DBG_PRINT( "event window close : src: %d\n", owner);
- (*env)->CallVoidMethod(env, obj, windowDestroyNotifyID);
- // Called by Window.java: DestroyWindow(wnd);
- // (*env)->CallVoidMethod(env, obj, windowDestroyedID);
- }
- break;
- case KD_EVENT_WINDOWPROPERTY_CHANGE:
- {
- const KDEventWindowProperty* prop = &evt->data.windowproperty;
- switch (prop->pname) {
- case KD_WINDOWPROPERTY_SIZE:
- {
- KDint32 v[2];
- if(!kdGetWindowPropertyiv(w, KD_WINDOWPROPERTY_SIZE, v)) {
- DBG_PRINT( "event window size change : src: %d %dx%d\n", owner, v[0], v[1]);
- (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) v[0], (jint) v[1]);
- } else {
- DBG_PRINT( "event window size change error: src: %d %dx%d\n", owner, v[0], v[1]);
- }
- }
- break;
- case KD_WINDOWPROPERTY_FOCUS:
- DBG_PRINT( "event window focus: src: %d\n", owner);
- break;
- case KD_WINDOWPROPERTY_VISIBILITY:
- {
- KDboolean visible;
- kdGetWindowPropertybv(w, KD_WINDOWPROPERTY_VISIBILITY, &visible);
- DBG_PRINT( "event window visibility: src: %d, v:%d\n", owner, visible);
- }
- break;
- default:
- break;
- }
- }
- break;
- case KD_EVENT_INPUT_POINTER:
- {
- const KDEventInputPointer* ptr = &(evt->data.inputpointer);
- // button idx: evt->data.input.index
- // pressed = ev->data.input.value.i
- // time = ev->timestamp
- if(KD_INPUT_POINTER_SELECT==ptr->index) {
- DBG_PRINT( "event mouse click: src: %d, s:%d, (%d,%d)\n", owner, ptr->select, ptr->x, ptr->y);
- (*env)->CallVoidMethod(env, obj, sendMouseEventID,
- (ptr->select==0) ? (jint) EVENT_MOUSE_RELEASED : (jint) EVENT_MOUSE_PRESSED,
- (jint) 0,
- (jint) ptr->x, (jint) ptr->y, 1, 0);
- } else {
- DBG_PRINT( "event mouse: src: %d, s:%d, i:0x%X (%d,%d)\n", owner, ptr->select, ptr->index, ptr->x, ptr->y);
- (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_MOVED,
- 0,
- (jint) ptr->x, (jint) ptr->y, 0, 0);
- }
- }
- break;
- }
- }
-}
-
JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setFullScreen0
(JNIEnv *env, jobject obj, jlong window, jboolean fullscreen)
{