From ccf738dfafc69650f24d65bdfa7ff9042cdeda22 Mon Sep 17 00:00:00 2001 From: kappaOne Date: Sun, 9 Dec 2012 22:12:02 +0000 Subject: [PATCH] Implement OS X Mouse.setCursorPosition() when in fullscreen mode --- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 2 +- .../org/lwjgl/opengl/MacOSXNativeMouse.java | 6 ++--- .../org_lwjgl_opengl_MacOSXNativeMouse.m | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 0689c7cb..29f7dee0 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -334,7 +334,7 @@ final class MacOSXDisplay implements DisplayImplementation { public void setCursorPosition(int x, int y) { if (mouse != null) { - mouse.warpCursor(x, y); + mouse.setCursorPosition(x, y); } //MacOSXMouseEventQueue.nWarpCursor(x, y); } diff --git a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java index 12415a35..0e1424e2 100644 --- a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java +++ b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java @@ -80,7 +80,7 @@ final class MacOSXNativeMouse extends EventQueue { this.window_handle = window_handle; } - private native void nWarpCursor(ByteBuffer window_handle, int x, int y); + private native void nSetCursorPosition(ByteBuffer window_handle, int x, int y); public static native void nGrabMouse(boolean grab); @@ -92,8 +92,8 @@ final class MacOSXNativeMouse extends EventQueue { nRegisterMouseListener(window_handle); } - public synchronized void warpCursor(int x, int y) { - nWarpCursor(window_handle, x, y); + public synchronized void setCursorPosition(int x, int y) { + nSetCursorPosition(window_handle, x, y); } public synchronized void unregister() { diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m b/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m index db774a89..7c531649 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m @@ -55,13 +55,25 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nGrabMouse(JNIEnv CGDisplayShowCursor(kCGDirectMainDisplay); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nWarpCursor(JNIEnv *env, jclass this, jobject window_handle, jint x, jint y) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nSetCursorPosition(JNIEnv *env, jclass this, jobject window_handle, jint x, jint y) { MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle); - NSPoint point = NSMakePoint(x, y); - point = [window_info->view convertPoint:point fromView:window_info->view]; + CGPoint p; - p.x = point.x; - p.y = point.y; + + if (window_info->fullscreen) { + NSSize screenSize = [[NSScreen mainScreen] frame].size; + NSSize displaySize = window_info->display_rect.size; + + p.x = (screenSize.width / displaySize.width) * x; + p.y = (screenSize.height / displaySize.height) * y; + } + else { + NSPoint point = NSMakePoint(x, y); + + p.x = point.x; + p.y = point.y; + } + CGWarpMouseCursorPosition(p); }