From c3f840346c8fdb8a0e1da9d5d990d422a3a7a869 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 1 Oct 2003 09:33:22 +0000 Subject: [PATCH] Loading Mac OS X hack through reflection --- src/java/org/lwjgl/opengl/MacOSX.java | 55 +++++++++++++++++++ src/java/org/lwjgl/opengl/Window.java | 28 +++++----- src/native/macosx/Makefile.am | 1 + src/native/macosx/Window.h | 48 ++++++++++++++++ .../macosx/org_lwjgl_input_Keyboard.cpp | 2 +- src/native/macosx/org_lwjgl_opengl_MacOSX.cpp | 45 +++++++++++++++ src/native/macosx/org_lwjgl_opengl_MacOSX.h | 21 +++++++ src/native/macosx/org_lwjgl_opengl_Window.cpp | 6 +- src/native/macosx/tools.h | 2 +- 9 files changed, 190 insertions(+), 18 deletions(-) create mode 100644 src/java/org/lwjgl/opengl/MacOSX.java create mode 100644 src/native/macosx/Window.h create mode 100644 src/native/macosx/org_lwjgl_opengl_MacOSX.cpp create mode 100644 src/native/macosx/org_lwjgl_opengl_MacOSX.h diff --git a/src/java/org/lwjgl/opengl/MacOSX.java b/src/java/org/lwjgl/opengl/MacOSX.java new file mode 100644 index 00000000..ab683666 --- /dev/null +++ b/src/java/org/lwjgl/opengl/MacOSX.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2002 Lightweight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.lwjgl.opengl; + +/** + * $Id$ + * + * Mac OS X specific hacks + * + * @author elias_naur + * @version $Revision$ + */ +class MacOSX { + public static void initMacOSX() { + java.awt.Toolkit.getDefaultToolkit(); + new com.apple.eawt.Application().addApplicationListener(new com.apple.eawt.ApplicationAdapter() { + public void handleQuit(com.apple.eawt.ApplicationEvent e) { + e.setHandled(false); + setQuitRequested(); + } + }); + } + + private static native void setQuitRequested(); +} diff --git a/src/java/org/lwjgl/opengl/Window.java b/src/java/org/lwjgl/opengl/Window.java index ace1bea3..9dfe8923 100644 --- a/src/java/org/lwjgl/opengl/Window.java +++ b/src/java/org/lwjgl/opengl/Window.java @@ -25,6 +25,7 @@ import org.lwjgl.Display; import org.lwjgl.Sys; import java.util.HashSet; +import java.lang.reflect.Method; public final class Window { @@ -53,19 +54,19 @@ public final class Window { * I have posted a bug report to apple regarding the behaviour. * */ - if (Display.getPlatform() == Display.PLATFORM_AGL) { - java.awt.Toolkit.getDefaultToolkit(); - new com.apple.eawt.Application().addApplicationListener(new com.apple.eawt.ApplicationAdapter() { - public void handleQuit(com.apple.eawt.ApplicationEvent e) { - e.setHandled(false); - apple_quit = true; - } - }); - } + if (Display.getPlatform() == Display.PLATFORM_AGL) + initMacOSX(); } - /** Special quit boolean set from the apple version */ - private static boolean apple_quit; + private static void initMacOSX() { + try { + Class mac_class = Class.forName("org.lwjgl.opengl.MacOSX"); + Method init_method = mac_class.getMethod("initMacOSX", null); + init_method.invoke(null, null); + } catch (Exception e) { + e.printStackTrace(); + } + } /** Whether the window is currently created, ie. has a native peer */ private static boolean created; @@ -185,9 +186,7 @@ public final class Window { */ public static boolean isCloseRequested() { assert isCreated() : "Cannot determine state of uncreated window"; - boolean result = nIsCloseRequested() || apple_quit; - apple_quit = false; - return result; + return nIsCloseRequested(); } private static native boolean nIsCloseRequested(); @@ -342,7 +341,6 @@ public final class Window { throws Exception; private static void createWindow() throws Exception { - apple_quit = false; HashSet extensions = new HashSet(); nCreate(title, x, y, width, height, fullscreen, color, alpha, depth, stencil, extensions); GLCaps.determineAvailableExtensions(extensions); diff --git a/src/native/macosx/Makefile.am b/src/native/macosx/Makefile.am index 7b3d0464..aa1cfc62 100644 --- a/src/native/macosx/Makefile.am +++ b/src/native/macosx/Makefile.am @@ -8,6 +8,7 @@ NATIVE = \ org_lwjgl_Sys.cpp \ # org_lwjgl_input_Controller.cpp \ org_lwjgl_input_Keyboard.cpp \ + org_lwjgl_opengl_MacOSX.cpp \ # org_lwjgl_input_Mouse.cpp \ # org_lwjgl_input_Cursor.cpp \ org_lwjgl_opengl_Window.cpp diff --git a/src/native/macosx/Window.h b/src/native/macosx/Window.h new file mode 100644 index 00000000..a44c41ca --- /dev/null +++ b/src/native/macosx/Window.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * $Id$ + * + * Include file to access public window features + * + * @author elias_naur + * @version $Revision$ + */ + +#ifndef _LWJGL_WINDOW_H_INCLUDED_ + #define _LWJGL_WINDOW_H_INCLUDED_ + + #include + extern void setQuitRequested(void); + +#endif /* _LWJGL_WINDOW_H_INCLUDED_ */ diff --git a/src/native/macosx/org_lwjgl_input_Keyboard.cpp b/src/native/macosx/org_lwjgl_input_Keyboard.cpp index 86d3c6db..a8c7143a 100644 --- a/src/native/macosx/org_lwjgl_input_Keyboard.cpp +++ b/src/native/macosx/org_lwjgl_input_Keyboard.cpp @@ -33,7 +33,7 @@ /** * $Id$ * - * Linux keyboard handling. + * Mac OS X keyboard handling. * * @author elias_naur * @version $Revision$ diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSX.cpp b/src/native/macosx/org_lwjgl_opengl_MacOSX.cpp new file mode 100644 index 00000000..90df06d5 --- /dev/null +++ b/src/native/macosx/org_lwjgl_opengl_MacOSX.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * $Id$ + * + * @author elias_naur + * @version $Revision$ + */ + +#include "Window.h" +#include "org_lwjgl_opengl_MacOSX.h" + +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSX_setQuitRequested(JNIEnv *, jclass) { + setQuitRequested(); +} diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSX.h b/src/native/macosx/org_lwjgl_opengl_MacOSX.h new file mode 100644 index 00000000..e57fb45e --- /dev/null +++ b/src/native/macosx/org_lwjgl_opengl_MacOSX.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_lwjgl_opengl_MacOSX */ + +#ifndef _Included_org_lwjgl_opengl_MacOSX +#define _Included_org_lwjgl_opengl_MacOSX +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_lwjgl_opengl_MacOSX + * Method: setQuitRequested + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSX_setQuitRequested + (JNIEnv *, jclass); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/native/macosx/org_lwjgl_opengl_Window.cpp b/src/native/macosx/org_lwjgl_opengl_Window.cpp index 88f1d4ae..3b728090 100644 --- a/src/native/macosx/org_lwjgl_opengl_Window.cpp +++ b/src/native/macosx/org_lwjgl_opengl_Window.cpp @@ -62,8 +62,12 @@ static void setWindowTitle(JNIEnv *env, jstring title_obj) { env->ReleaseStringUTFChars(title_obj, title); } -static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) { +void setQuitRequested(void) { close_requested = true; +} + +static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) { + setQuitRequested(); return noErr; } diff --git a/src/native/macosx/tools.h b/src/native/macosx/tools.h index 06577fc4..0ea1b091 100644 --- a/src/native/macosx/tools.h +++ b/src/native/macosx/tools.h @@ -3,6 +3,6 @@ #include -void throwException(JNIEnv* env, const char* msg); +extern void throwException(JNIEnv* env, const char* msg); #endif