diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 29f7dee0..32ee96a4 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -79,10 +79,6 @@ final class MacOSXDisplay implements DisplayImplementation { private MacOSXNativeKeyboard keyboard; private ByteBuffer window; private ByteBuffer context; - private int x; - private int y; - private int width; - private int height; private boolean close_requested; @@ -102,6 +98,10 @@ final class MacOSXDisplay implements DisplayImplementation { private native boolean nWasResized(ByteBuffer window_handle); + private native int nGetX(ByteBuffer window_handle); + + private native int nGetY(ByteBuffer window_handle); + private native int nGetWidth(ByteBuffer window_handle); private native int nGetHeight(ByteBuffer window_handle); @@ -124,10 +124,6 @@ final class MacOSXDisplay implements DisplayImplementation { window = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(), fullscreen, isUndecorated(), resizable, parented, peer_handle, window); - this.x = x; - this.y = y; - this.width = mode.getWidth(); - this.height = mode.getHeight(); this.canvas = parent; if (fullscreen) { @@ -135,8 +131,8 @@ final class MacOSXDisplay implements DisplayImplementation { skipViewportValue = true; // if starting in fullscreen then set initial viewport to displaymode size if (current_viewport.get(2) == 0 && current_viewport.get(3) == 0) { - current_viewport.put(2, width); - current_viewport.put(3, height); + current_viewport.put(2, mode.getWidth()); + current_viewport.put(3, mode.getHeight()); } } } catch (LWJGLException e) { @@ -453,11 +449,11 @@ final class MacOSXDisplay implements DisplayImplementation { } public int getX() { - return x; + return nGetX(window); } public int getY() { - return y; + return nGetY(window); } public int getWidth() { diff --git a/src/native/macosx/org_lwjgl_opengl_Display.m b/src/native/macosx/org_lwjgl_opengl_Display.m index 85b70306..c9c0e41d 100644 --- a/src/native/macosx/org_lwjgl_opengl_Display.m +++ b/src/native/macosx/org_lwjgl_opengl_Display.m @@ -396,6 +396,23 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nSetResizable(JNIEnv [window_info->window setStyleMask:style_mask]; } +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGetX(JNIEnv *env, jobject this, jobject window_handle) { + MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle); + jint x = [[window_info->view window] frame].origin.x; + return x; +} + +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGetY(JNIEnv *env, jobject this, jobject window_handle) { + MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle); + + NSRect screenRect = [[NSScreen mainScreen] frame]; + NSRect winRect = [[window_info->view window] frame]; + + // get top corner of window frame, also flip coords so origin is in top left + jint y = screenRect.size.height - (winRect.origin.y + winRect.size.height) - 1; + return y; +} + JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nSetTitle(JNIEnv *env, jobject this, jobject window_handle, jobject title_buffer) { MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle); const char *title_cstr = (const char *)(*env)->GetDirectBufferAddress(env, title_buffer);