From f65ae73d47641ad184bc90fd046330bc2f24bbe6 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 15 Nov 2004 15:28:53 +0000 Subject: [PATCH] Mac OS X: Don't hide mouse mouse when already hidden (because the cursor state is counted) --- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 4 ++-- src/native/macosx/org_lwjgl_input_Mouse.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index e993699f..3e36a42d 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -270,9 +270,9 @@ final class MacOSXDisplay implements DisplayImplementation { } public void grabMouse(boolean grab) { - nGrabMouse(grab); mouse_queue.setGrabbed(grab); warpCursor(); + nGrabMouse(grab); } private native void nWarpCursor(int x, int y); @@ -294,7 +294,7 @@ final class MacOSXDisplay implements DisplayImplementation { with another setCursor. 2. When the cursor is moving in the top pixel row (y = 0 in AWT coordinates) in fullscreen mode, no mouse moved events are reported, even though mouse pressed/released and dragged - are reported + events are reported */ return 0; } diff --git a/src/native/macosx/org_lwjgl_input_Mouse.c b/src/native/macosx/org_lwjgl_input_Mouse.c index 66ffd224..a0d5013e 100644 --- a/src/native/macosx/org_lwjgl_input_Mouse.c +++ b/src/native/macosx/org_lwjgl_input_Mouse.c @@ -43,12 +43,18 @@ #include #include "common_tools.h" +static bool is_grabbed; + JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGrabMouse(JNIEnv *env, jobject this, jboolean grab) { - CGAssociateMouseAndMouseCursorPosition(grab == JNI_TRUE ? FALSE : TRUE); - if (grab == JNI_TRUE) - CGDisplayHideCursor(kCGDirectMainDisplay); - else - CGDisplayShowCursor(kCGDirectMainDisplay); + bool new_grabbed = grab == JNI_TRUE; + if (is_grabbed != new_grabbed) { + is_grabbed = new_grabbed; + CGAssociateMouseAndMouseCursorPosition(is_grabbed ? FALSE : TRUE); + if (is_grabbed) + CGDisplayHideCursor(kCGDirectMainDisplay); + else + CGDisplayShowCursor(kCGDirectMainDisplay); + } } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nWarpCursor(JNIEnv *env, jobject this, jint x, jint y) {