From f6a2bc832732bd2835f3f8b4d7ee4b0cfd8f8d6f Mon Sep 17 00:00:00 2001 From: kappaOne Date: Sun, 3 Feb 2013 18:58:00 +0000 Subject: [PATCH] Detect correctly if mouse is inside or outside the Display on creation and resize. --- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 2 -- src/native/macosx/org_lwjgl_opengl_Display.m | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index c646a278..2f6251f9 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -153,8 +153,6 @@ final class MacOSXDisplay implements DisplayImplementation { } native_mode = nIsNativeMode(peer_handle); - mouseInsideWindow = true; - updateNativeCursor = true; if (!native_mode) { robot = AWTUtil.createRobot(canvas); diff --git a/src/native/macosx/org_lwjgl_opengl_Display.m b/src/native/macosx/org_lwjgl_opengl_Display.m index 2dc923d4..b197af03 100644 --- a/src/native/macosx/org_lwjgl_opengl_Display.m +++ b/src/native/macosx/org_lwjgl_opengl_Display.m @@ -342,11 +342,23 @@ static NSAutoreleasePool *pool; owner:self userInfo:nil]; [self addTrackingArea:_trackingArea]; + + // since nstrackingarea's don't know if mouse is inside or outside on creation + // manually detect this and send a fake mouse entered/exited message + NSPoint mouseLocation = [[self window] mouseLocationOutsideOfEventStream]; + mouseLocation = [self convertPoint:mouseLocation fromView:nil]; + + if (NSPointInRect(mouseLocation, [self bounds])) { + [self mouseEntered: nil]; + } + else { + [self mouseExited: nil]; + } } -(void)mouseEntered:(NSEvent *)event { JNIEnv *env = attachCurrentThread(); - if (env == nil || event == nil || _parent == nil || _parent->jdisplay == nil) { + if (env == nil || _parent == nil || _parent->jdisplay == nil) { return; } @@ -357,7 +369,7 @@ static NSAutoreleasePool *pool; -(void)mouseExited:(NSEvent *)event { JNIEnv *env = attachCurrentThread(); - if (env == nil || event == nil || _parent == nil || _parent->jdisplay == nil) { + if (env == nil || _parent == nil || _parent->jdisplay == nil) { return; }