summaryrefslogtreecommitdiffstats
path: root/src/newt/native/NewtMacWindow.m
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-01-16 10:56:59 +0100
committerSven Gothel <[email protected]>2012-01-16 10:56:59 +0100
commitf5c8cdad92687782184122fecc341258a6283d89 (patch)
tree9f243409269cba56335d331e0256024f5fdea157 /src/newt/native/NewtMacWindow.m
parent3154801a0054de2dba775902f3da04c96638bb27 (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/native/NewtMacWindow.m')
-rw-r--r--src/newt/native/NewtMacWindow.m29
1 files changed, 22 insertions, 7 deletions
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];
}