diff options
Diffstat (limited to 'src/newt')
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/Window.java | 2 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java | 4 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/x11/X11Window.java | 43 | ||||
-rw-r--r-- | src/newt/native/MacWindow.m | 30 | ||||
-rw-r--r-- | src/newt/native/WindowEvent.h | 12 | ||||
-rwxr-xr-x | src/newt/native/X11Window.c | 64 |
6 files changed, 101 insertions, 54 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java index 918e54e1f..49cd49a4d 100755 --- a/src/newt/classes/com/sun/javafx/newt/Window.java +++ b/src/newt/classes/com/sun/javafx/newt/Window.java @@ -90,7 +90,7 @@ public abstract class Window implements NativeWindow Window window = (Window) windowClass.newInstance(); window.invalidate(); window.screen = screen; - window.setUndecorated(undecorated); + window.setUndecorated(undecorated||0!=parentWindowHandle); window.createNative(parentWindowHandle, caps); return window; } catch (Throwable t) { diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java index b3d141c43..277aec796 100755 --- a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java @@ -349,7 +349,7 @@ public class MacWindow extends Window { nsViewLock.lock(); try { if (windowHandle != 0) { - setFrameTopLeftPoint(windowHandle, x, y); + setFrameTopLeftPoint(parentWindowHandle, windowHandle, x, y); } } finally { nsViewLock.unlock(); @@ -596,5 +596,5 @@ public class MacWindow extends Window { private native long contentView(long window); private native long changeContentView(long window, long view); private native void setContentSize(long window, int w, int h); - private native void setFrameTopLeftPoint(long window, int x, int y); + private native void setFrameTopLeftPoint(long parentWindowHandle, long window, int x, int y); } diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java index aaea78589..57653a6d3 100755 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java @@ -99,6 +99,11 @@ public class X11Window extends Window { public void setSize(int width, int height) { if(0==windowHandle) return; + if(!visible) { + // set values, since no event roundtrip will happen to set them + this.width = width; + this.height = height; + } if(!fullscreen) { nfs_width=width; nfs_height=height; @@ -108,6 +113,11 @@ public class X11Window extends Window { public void setPosition(int x, int y) { if(0==windowHandle) return; + if(!visible) { + // set values, since no event roundtrip will happen to set them + this.x = x; + this.y = y; + } if(!fullscreen) { nfs_x=x; nfs_y=y; @@ -150,24 +160,25 @@ public class X11Window extends Window { int x, int y, int width, int height, int decorationToggle, boolean setVisible); private native void setPosition0(long display, long windowHandle, int x, int y); - private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; + private void windowChanged(int newX, int newY, int newWidth, int newHeight) { + if(width != newWidth || height != newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private void positionChanged(int newX, int newY) { - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; + if(x != newX || y != newY) { + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); } private void windowCreated(long windowHandle) { diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index d59a61e42..d862ca392 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -52,14 +52,27 @@ NSString* jstringToNSString(JNIEnv* env, jstring jstr) return str; } -void setFrameTopLeftPoint(NSWindow* win, jint x, jint y) +void setFrameTopLeftPoint(NSWindow* pwin, NSWindow* win, jint x, jint y) { NSScreen* screen = [NSScreen mainScreen]; + // this allows for better compatibility with awt behavior - NSRect visibleScreenRect = [screen frame]; + NSRect visibleRect; // either screen or parent-window NSPoint pt; + int d_pty=0; // parent titlebar height - pt = NSMakePoint(x, visibleScreenRect.origin.y + visibleScreenRect.size.height - y); + if(NULL==pwin) { + visibleRect = [screen frame]; + } else { + visibleRect = [pwin frame]; + + NSView* pview = [pwin contentView]; + NSRect viewRect = [pview frame]; + d_pty = visibleRect.size.height - viewRect.size.height; + } + + pt = NSMakePoint(visibleRect.origin.x + x, visibleRect.origin.y + visibleRect.size.height - y - d_pty); + [win setFrameTopLeftPoint: pt]; } @@ -264,11 +277,11 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_createWindow0 backing: (NSBackingStoreType) bufferingType screen: screen] retain]; - /** FIXME: test .. NSWindow* parentWindow = (NSWindow*) ((intptr_t) parent); if(NULL!=parentWindow) { + [parentWindow addChildWindow: window ordered: NSWindowAbove]; [window setParentWindow: parentWindow]; - } */ + } if (fullscreen) { [window setOpaque: YES]; @@ -282,7 +295,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_createWindow0 } // Immediately re-position the window based on an upper-left coordinate system - setFrameTopLeftPoint(window, x, y); + setFrameTopLeftPoint(parentWindow, window, x, y); // specify we want mouse-moved events [window setAcceptsMouseMovedEvents:YES]; @@ -448,11 +461,12 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setContentSize * Signature: (JII)V */ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setFrameTopLeftPoint - (JNIEnv *env, jobject unused, jlong window, jint x, jint y) + (JNIEnv *env, jobject unused, jlong parent, jlong window, jint x, jint y) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* pwin = (NSWindow*) ((intptr_t) parent); NSWindow* win = (NSWindow*) ((intptr_t) window); - setFrameTopLeftPoint(win, x, y); + setFrameTopLeftPoint(pwin, win, x, y); [pool release]; } diff --git a/src/newt/native/WindowEvent.h b/src/newt/native/WindowEvent.h new file mode 100644 index 000000000..6274f9443 --- /dev/null +++ b/src/newt/native/WindowEvent.h @@ -0,0 +1,12 @@ + +#ifndef _WINDOW_EVENT_H_ +#define _WINDOW_EVENT_H_ + +#define EVENT_WINDOW_RESIZED = 100; +#define EVENT_WINDOW_MOVED = 101; +#define EVENT_WINDOW_DESTROY_NOTIFY = 102; +#define EVENT_WINDOW_GAINED_FOCUS = 103; +#define EVENT_WINDOW_LOST_FOCUS = 104; +#define EVENT_WINDOW_REPAINT = 105; // TODO + +#endif diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 79457031f..7e1f5d9dd 100755 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -51,17 +51,18 @@ #include "EventListener.h" #include "MouseEvent.h" #include "KeyEvent.h" +#include "WindowEvent.h" // #define VERBOSE_ON 1 #ifdef VERBOSE_ON // Workaround for ancient compiler on Solaris/SPARC - // #define DBG_PRINT(args...) fprintf(stderr, args); fflush(stderr) - #define DBG_PRINT0(str) fprintf(stderr, str); flush(stderr) - #define DBG_PRINT1(str, arg1) fprintf(stderr, str, arg1); flush(stderr) - #define DBG_PRINT2(str, arg1, arg2) fprintf(stderr, str, arg1, arg2); flush(stderr) - #define DBG_PRINT3(str, arg1, arg2, arg3) fprintf(stderr, str, arg1, arg2, arg3); flush(stderr) - #define DBG_PRINT4(str, arg1, arg2, arg3, arg4) fprintf(stderr, str, arg1, arg2, arg3, arg4); flush(stderr) + // #define DBG_PRINT(args...) fprintf(stderr, args); + #define DBG_PRINT0(str) fprintf(stderr, str); + #define DBG_PRINT1(str, arg1) fprintf(stderr, str, arg1); + #define DBG_PRINT2(str, arg1, arg2) fprintf(stderr, str, arg1, arg2); + #define DBG_PRINT3(str, arg1, arg2, arg3) fprintf(stderr, str, arg1, arg2, arg3); + #define DBG_PRINT4(str, arg1, arg2, arg3, arg4) fprintf(stderr, str, arg1, arg2, arg3, arg4); #define DUMP_VISUAL_INFO(a,b) _dumpVisualInfo((a),(b)) @@ -148,8 +149,7 @@ static const char * const ClazzNameNewtWindow = "com/sun/javafx/newt/Window"; static jclass newtWindowClz=NULL; -static jmethodID sizeChangedID = NULL; -static jmethodID positionChangedID = NULL; +static jmethodID windowChangedID = NULL; static jmethodID windowDestroyNotifyID = NULL; static jmethodID windowDestroyedID = NULL; static jmethodID windowCreatedID = NULL; @@ -400,9 +400,6 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_DispatchMessages (jint) evt.xkey.state, X11KeySym2NewtVKey(keySym), (jchar) keyChar); break; - case FocusIn: - case FocusOut: - break; case DestroyNotify: DBG_PRINT1( "event . DestroyNotify call 0x%X\n", evt.xdestroywindow.window); (*env)->CallVoidMethod(env, jwindow, windowDestroyedID); @@ -411,6 +408,28 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_DispatchMessages DBG_PRINT1( "event . CreateNotify call 0x%X\n", evt.xcreatewindow.window); (*env)->CallVoidMethod(env, jwindow, windowCreatedID); break; + case ConfigureNotify: + DBG_PRINT3( "event . ConfigureNotify call 0x%X %dx%d\n", evt.xconfigure.window, evt.xconfigure.width, evt.xconfigure.height); + (*env)->CallVoidMethod(env, jwindow, windowChangedID, + (jint) evt.xconfigure.x, (jint) evt.xconfigure.y, + (jint) evt.xconfigure.width, (jint) evt.xconfigure.height); + break; + case ClientMessage: + if (evt.xclient.send_event==True && evt.xclient.data.l[0]==(Atom)wmDeleteAtom) { + DBG_PRINT2( "event . ClientMessage call 0x%X type 0x%X !!!\n", evt.xclient.window, evt.xclient.message_type); + (*env)->CallVoidMethod(env, jwindow, windowDestroyNotifyID); + // Called by Window.java: CloseWindow(); + } + break; + + // unhandled events .. yet .. + + case FocusIn: + DBG_PRINT1( "event . FocusIn call 0x%X\n", evt.xvisibility.window); + break; + case FocusOut: + DBG_PRINT1( "event . FocusOut call 0x%X\n", evt.xvisibility.window); + break; case VisibilityNotify: DBG_PRINT1( "event . VisibilityNotify call 0x%X\n", evt.xvisibility.window); break; @@ -421,13 +440,8 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_DispatchMessages case UnmapNotify: DBG_PRINT1( "event . UnmapNotify call 0x%X\n", evt.xunmap.window); break; - case ClientMessage: - if (evt.xclient.send_event==True && evt.xclient.data.l[0]==(Atom)wmDeleteAtom) { - DBG_PRINT2( "event . ClientMessage call 0x%X type 0x%X !!!\n", evt.xclient.window, evt.xclient.message_type); - (*env)->CallVoidMethod(env, jwindow, windowDestroyNotifyID); - // Called by Window.java: CloseWindow(); - } - break; + default: + DBG_PRINT3("event . unhandled %d 0x%X call 0x%X\n", evt.type, evt.type, evt.xunmap.window); } } } @@ -488,16 +502,14 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Screen_getHeight0 JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs (JNIEnv *env, jclass clazz) { - sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V"); - positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); + windowChangedID = (*env)->GetMethodID(env, clazz, "windowChanged", "(IIII)V"); windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V"); windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V"); sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); - if (sizeChangedID == NULL || - positionChangedID == NULL || + if (windowChangedID == NULL || windowDestroyNotifyID == NULL || windowDestroyedID == NULL || windowCreatedID == NULL || @@ -719,7 +731,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setSize0 XWindowChanges xwc; - DBG_PRINT4( "setSize0 %dx%d, dec %d, vis %d\n", width, height, decorationToggle, isVisible); + DBG_PRINT4( "setSize0 %dx%d, dec %d, vis %d\n", width, height, decorationToggle, setVisible); XSync(dpy, False); @@ -761,8 +773,8 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setSize0 XSync(dpy, False); - DBG_PRINT0( "setSize0 . sizeChangedID call\n"); - (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height); + // DBG_PRINT0( "setSize0 . windowChangedID call\n"); + // (*env)->CallVoidMethod(env, obj, windowChangedID, (jint) x, (jint) y, (jint) width, (jint) height); } /* @@ -782,7 +794,5 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setPosition0 xwc.y=y; XConfigureWindow(dpy, w, CWX|CWY, &xwc); XSync(dpy, False); - - // (*env)->CallVoidMethod(env, obj, positionChangedID, (jint) width, (jint) height); } |