diff options
author | Sven Gothel <[email protected]> | 2012-01-16 10:56:59 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-01-16 10:56:59 +0100 |
commit | f5c8cdad92687782184122fecc341258a6283d89 (patch) | |
tree | 9f243409269cba56335d331e0256024f5fdea157 /src/newt | |
parent | 3154801a0054de2dba775902f3da04c96638bb27 (diff) |
NEWT/OSX Pointer Invisible Fix: 10.6.* responder declarations & test focus/isInside
On OS X 10.6.8 the lack of responder method declarations (mouseEntered, ..)
lead to ignore the impl. callbacks.
'isMouseInside' cannot rely on 'mouseExit'/'mouseEntered' when
setMouseInvisible() is being called, deduce it manually.
focusLost == mouseExit (OS X behavior), hence focusGained needs
to set mouse invisible/visible in case it's requested.
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java | 4 | ||||
-rw-r--r-- | src/newt/native/MacWindow.m | 5 | ||||
-rw-r--r-- | src/newt/native/NewtMacWindow.h | 14 | ||||
-rw-r--r-- | src/newt/native/NewtMacWindow.m | 29 |
4 files changed, 41 insertions, 11 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java index 75a3cf6d5..f879ad86c 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java @@ -271,7 +271,7 @@ public class MacWindow extends WindowImpl implements SurfaceChangeable, DriverCl @Override protected boolean setPointerVisibleImpl(final boolean pointerVisible) { if( !isOffscreenInstance ) { - return setPointerVisible0(getWindowHandle(), pointerVisible); + return setPointerVisible0(getWindowHandle(), hasFocus(), pointerVisible); } // else may need offscreen solution ? FIXME return false; } @@ -381,7 +381,7 @@ public class MacWindow extends WindowImpl implements SurfaceChangeable, DriverCl private native void setFrameTopLeftPoint0(long parentWindowHandle, long window, int x, int y); private native void setAlwaysOnTop0(long window, boolean atop); private static native Object getLocationOnScreen0(long windowHandle, int src_x, int src_y); - private static native boolean setPointerVisible0(long windowHandle, boolean visible); + private static native boolean setPointerVisible0(long windowHandle, boolean hasFocus, boolean visible); private static native boolean confinePointer0(long windowHandle, boolean confine); private static native void warpPointer0(long windowHandle, int x, int y); diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index c528ebb64..1dcfacb6d 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -1043,10 +1043,11 @@ JNIEXPORT jobject JNICALL Java_jogamp_newt_driver_macosx_MacWindow_getLocationOn * Signature: (JZ)Z */ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_macosx_MacWindow_setPointerVisible0 - (JNIEnv *env, jclass clazz, jlong window, jboolean mouseVisible) + (JNIEnv *env, jclass clazz, jlong window, jboolean hasFocus, jboolean mouseVisible) { NewtMacWindow *mWin = (NewtMacWindow*) ((intptr_t) window); - [mWin setMouseVisible: ( JNI_TRUE == mouseVisible ) ? YES : NO]; + [mWin setMouseVisible: ( JNI_TRUE == mouseVisible ) ? YES : NO + hasFocus: ( JNI_TRUE == hasFocus ) ? YES : NO]; return JNI_TRUE; } diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h index 3ba89de1e..dea7e32ae 100644 --- a/src/newt/native/NewtMacWindow.h +++ b/src/newt/native/NewtMacWindow.h @@ -129,12 +129,26 @@ - (NSPoint) newtClientWinPos2OSXScreenPos: (NSPoint) p; - (NSPoint) getLocationOnScreen: (NSPoint) p; - (NSPoint) screenPos2NewtClientWinPos: (NSPoint) p; +- (BOOL) isMouseInside; - (void) cursorHide:(BOOL)v; - (void) setMouseVisible:(BOOL)v; - (void) setMouseConfined:(BOOL)v; - (void) setMousePosition:(NSPoint)p; +- (void) mouseEntered: (NSEvent*) theEvent; +- (void) mouseExited: (NSEvent*) theEvent; +- (void) mouseMoved: (NSEvent*) theEvent; +- (void) scrollWheel: (NSEvent*) theEvent; +- (void) mouseDown: (NSEvent*) theEvent; +- (void) mouseDragged: (NSEvent*) theEvent; +- (void) mouseUp: (NSEvent*) theEvent; +- (void) rightMouseDown: (NSEvent*) theEvent; +- (void) rightMouseDragged: (NSEvent*) theEvent; +- (void) rightMouseUp: (NSEvent*) theEvent; +- (void) otherMouseDown: (NSEvent*) theEvent; +- (void) otherMouseUp: (NSEvent*) theEvent; + - (BOOL) becomeFirstResponder; - (BOOL) resignFirstResponder; - (void) becomeKeyWindow; diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index ce41673c4..204feeef7 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -463,10 +463,19 @@ static jmethodID windowRepaintID = NULL; // NSRect rS = [win convertRectFromScreen: r]; // 10.7 NSPoint oS = [self convertScreenToBase: r.origin]; oS.y = viewFrame.size.height - oS.y; // y-flip - return oS; } +- (BOOL) isMouseInside +{ + NSView* view = [self contentView]; + NSRect viewFrame = [view frame]; + NSPoint l1 = [NSEvent mouseLocation]; + NSPoint l0 = [self screenPos2NewtClientWinPos: l1]; + return viewFrame.origin.x <= l0.x && l0.x < (viewFrame.origin.x+viewFrame.size.width) && + viewFrame.origin.y <= l0.y && l0.y < (viewFrame.origin.y+viewFrame.size.height) ; +} + - (BOOL) canBecomeKeyWindow { // Even if the window is borderless, we still want it to be able @@ -624,17 +633,20 @@ static jint mods2JavaMods(NSUInteger mods) } } -- (void) setMouseVisible:(BOOL)v +- (void) setMouseVisible:(BOOL)v hasFocus:(BOOL)focus { mouseVisible = v; - DBG_PRINT( "setMouseVisible: confined %d, visible %d\n", mouseConfined, mouseVisible); - if(YES == mouseInside) { + mouseInside = [self isMouseInside]; + DBG_PRINT( "setMouseVisible: confined %d, visible %d (current: %d), mouseInside %d, hasFocus %d\n", + mouseConfined, mouseVisible, !cursorIsHidden, mouseInside, focus); + if(YES == focus && YES == mouseInside) { [self cursorHide: !mouseVisible]; } } - (void) cursorHide:(BOOL)v { + DBG_PRINT( "cursorHide: %d -> %d\n", cursorIsHidden, v); if(v) { if(!cursorIsHidden) { [NSCursor hide]; @@ -662,15 +674,13 @@ static jint mods2JavaMods(NSUInteger mods) CGPoint pt = { p.x, screenRect.size.height - p.y }; // y-flip (CG is top-left origin) CGEventRef ev = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, pt, kCGMouseButtonLeft); CGEventPost (kCGHIDEventTap, ev); - NSPoint l0 = [NSEvent mouseLocation]; - [self screenPos2NewtClientWinPos: l0]; } - (void) mouseEntered: (NSEvent*) theEvent { DBG_PRINT( "mouseEntered: confined %d, visible %d\n", mouseConfined, mouseVisible); mouseInside = YES; - [self setMouseVisible: mouseVisible]; + [self cursorHide: !mouseVisible]; if(NO == mouseConfined) { [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_ENTERED]; } @@ -886,12 +896,17 @@ static jint mods2JavaMods(NSUInteger mods) - (void) windowDidBecomeKey: (NSNotification *) notification { DBG_PRINT( "*************** windowDidBecomeKey\n"); + mouseInside = [self isMouseInside]; + if(YES == mouseInside) { + [self cursorHide: !mouseVisible]; + } [self focusChanged: YES]; } - (void) windowDidResignKey: (NSNotification *) notification { DBG_PRINT( "*************** windowDidResignKey\n"); + // Implicit mouse exit by OS X [self focusChanged: NO]; } |