diff --git a/build.xml b/build.xml index 3d2247d3..cd03ab97 100644 --- a/build.xml +++ b/build.xml @@ -316,7 +316,6 @@ - diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 42efd4b7..eaefb87a 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -70,7 +70,7 @@ final class MacOSXDisplay implements DisplayImplementation { private MacOSXCanvasListener canvas_listener; private Canvas canvas; private Robot robot; - private MacOSXMouseEventQueue mouse_queue; + //private MacOSXMouseEventQueue mouse_queue; private KeyboardEventQueue keyboard_queue; private java.awt.DisplayMode requested_mode; @@ -84,30 +84,10 @@ final class MacOSXDisplay implements DisplayImplementation { private int width; private int height; - /* Whether we're using a native window or an AWT canvas */ - private boolean native_mode; - - private boolean close_requested; + private boolean close_requested; MacOSXDisplay() { - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Application.getApplication().addApplicationListener(new ApplicationAdapter() { - public void handleQuit(ApplicationEvent event) { - doHandleQuit(); - } - }); - return null; - } - }); - } catch (Throwable e) { - /** - * In an applet environment, referencing com.apple.eawt.Application can fail with - * a native exception. So log any exceptions instead of re-throwing. - */ - LWJGLUtil.log("Failed to register quit handler: " + e.getMessage()); - } + } private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException; @@ -142,7 +122,6 @@ final class MacOSXDisplay implements DisplayImplementation { window = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(), fullscreen, isUndecorated(), peer_handle, window); - native_mode = true; this.x = x; this.y = y; this.width = mode.getWidth(); @@ -165,15 +144,8 @@ final class MacOSXDisplay implements DisplayImplementation { public native void nDestroyWindow(ByteBuffer window_handle); public void destroyWindow() { - if (native_mode) { - nDestroyWindow(window); - } else { - if (canvas_listener != null) { - canvas_listener.disableListeners(); - canvas_listener = null; - } - } - hideUI(false); + nDestroyWindow(window); + hideUI(false); } public int getGammaRampLength() { @@ -213,11 +185,7 @@ final class MacOSXDisplay implements DisplayImplementation { } public void resetDisplayMode() { - if (!native_mode) { - if (getDevice().getFullScreenWindow() != null) - getDevice().setFullScreenWindow(null); - } - requested_mode = null; + requested_mode = null; restoreGamma(); } @@ -273,12 +241,8 @@ final class MacOSXDisplay implements DisplayImplementation { } public boolean isActive() { - if (native_mode) { - boolean ret = nIsFocused(window); - return ret; - } else { - return canvas.isFocusOwner(); - } + boolean ret = nIsFocused(window); + return ret; } public Canvas getCanvas() { @@ -300,10 +264,7 @@ final class MacOSXDisplay implements DisplayImplementation { private static final IntBuffer current_viewport = BufferUtils.createIntBuffer(16); public void update() { boolean should_update = true; - if (!native_mode) { - should_update = canvas_listener.syncShouldUpdateContext(); - } - /* + /* * Workaround for the "white screen in fullscreen mode" problem * * Sometimes, switching from windowed mode to fullscreen or simply creating the Display @@ -331,14 +292,6 @@ final class MacOSXDisplay implements DisplayImplementation { glGetInteger(GL_VIEWPORT, current_viewport); glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3)); } - /* - if (frame != null && mouse_queue != null) { - if (frame.syncShouldReleaseCursor()) - MacOSXMouseEventQueue.nGrabMouse(false); - if (frame.syncShouldWarpCursor()) - mouse_queue.warpCursor(); - } - */ } /** @@ -369,52 +322,29 @@ final class MacOSXDisplay implements DisplayImplementation { } public void createMouse() throws LWJGLException { - if (native_mode) { - mouse = new MacOSXNativeMouse(this, window); - mouse.register(); - } else { - mouse_queue = new MacOSXMouseEventQueue(canvas); - mouse_queue.register(); - } + mouse = new MacOSXNativeMouse(this, window); + mouse.register(); } public void destroyMouse() { - MacOSXMouseEventQueue.nGrabMouse(false); - if (native_mode) { - if (mouse != null) { - mouse.unregister(); - } - mouse = null; - } else { - if (mouse_queue != null) { - mouse_queue.unregister(); - } - mouse_queue = null; + //MacOSXMouseEventQueue.nGrabMouse(false); + + if (mouse != null) { + mouse.unregister(); } + mouse = null; } public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons_buffer) { - if (native_mode) { - mouse.poll(coord_buffer, buttons_buffer); - } else { - mouse_queue.poll(coord_buffer, buttons_buffer); - } + mouse.poll(coord_buffer, buttons_buffer); } public void readMouse(ByteBuffer buffer) { - if (native_mode) { - mouse.copyEvents(buffer); - } else { - mouse_queue.copyEvents(buffer); - } + mouse.copyEvents(buffer); } public void grabMouse(boolean grab) { - if (native_mode) { - mouse.setGrabbed(grab); - } else { - mouse_queue.setGrabbed(grab); - } + mouse.setGrabbed(grab); } public int getNativeCursorCapabilities() { @@ -422,7 +352,10 @@ final class MacOSXDisplay implements DisplayImplementation { } public void setCursorPosition(int x, int y) { - MacOSXMouseEventQueue.nWarpCursor(x, y); + if (mouse != null) { + mouse.warpCursor(x, y); + } + //MacOSXMouseEventQueue.nWarpCursor(x, y); } public void setNativeCursor(Object handle) throws LWJGLException { @@ -438,41 +371,23 @@ final class MacOSXDisplay implements DisplayImplementation { /* Keyboard */ public void createKeyboard() throws LWJGLException { - if (native_mode) { - this.keyboard = new MacOSXNativeKeyboard(window); - keyboard.register(); - } else { - this.keyboard_queue = new KeyboardEventQueue(canvas); - keyboard_queue.register(); - } + this.keyboard = new MacOSXNativeKeyboard(window); + keyboard.register(); } public void destroyKeyboard() { - if (native_mode) { - if (keyboard != null) - keyboard.unregister(); - keyboard = null; - } else { - if (keyboard_queue != null) - keyboard_queue.unregister(); - keyboard_queue = null; - } + if (keyboard != null) { + keyboard.unregister(); + } + keyboard = null; } public void pollKeyboard(ByteBuffer keyDownBuffer) { - if (native_mode) { - keyboard.poll(keyDownBuffer); - } else { - keyboard_queue.poll(keyDownBuffer); - } + keyboard.poll(keyDownBuffer); } public void readKeyboard(ByteBuffer buffer) { - if (native_mode) { - keyboard.copyEvents(buffer); - } else { - keyboard_queue.copyEvents(buffer); - } + keyboard.copyEvents(buffer); } /** Native cursor handles */ @@ -577,9 +492,7 @@ final class MacOSXDisplay implements DisplayImplementation { } public void setResizable(boolean resizable) { - if (native_mode) { - nSetResizable(window, resizable); - } + nSetResizable(window, resizable); } public boolean wasResized() { diff --git a/src/java/org/lwjgl/opengl/MacOSXFrame.java b/src/java/org/lwjgl/opengl/MacOSXFrame.java deleted file mode 100644 index 18bdcfac..00000000 --- a/src/java/org/lwjgl/opengl/MacOSXFrame.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2002-2008 LWJGL 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 'LWJGL' 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; - -/** - * This is the Mac OS X AWT Frame. It contains thread safe - * methods to manipulateit from non-AWT threads - * @author elias_naur - */ - -import java.awt.BorderLayout; -import java.awt.Frame; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -import org.lwjgl.LWJGLException; - -final class MacOSXFrame extends Frame implements WindowListener, ComponentListener { - - private static final long serialVersionUID = -5823294716668988777L; - - private final MacOSXGLCanvas canvas; - private boolean close_requested; - - /* States */ - private Rectangle bounds; - private boolean active; - private boolean minimized; - private boolean should_warp_cursor; - private boolean should_release_cursor; - - MacOSXFrame(DisplayMode mode, final java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException { - setResizable(Display.isResizable()); - addWindowListener(this); - addComponentListener(this); - canvas = new MacOSXGLCanvas(); - canvas.setFocusTraversalKeysEnabled(false); - add(canvas, BorderLayout.CENTER); - boolean undecorated = Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated"); - setUndecorated(fullscreen || undecorated); - if ( fullscreen ) { - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - getDevice().setFullScreenWindow(MacOSXFrame.this); - getDevice().setDisplayMode(requested_mode); - java.awt.DisplayMode real_mode = getDevice().getDisplayMode(); - /** For some strange reason, the display mode is sometimes silently capped even though the mode is reported as supported */ - if ( requested_mode.getWidth() != real_mode.getWidth() || requested_mode.getHeight() != real_mode.getHeight() ) { - getDevice().setFullScreenWindow(null); - if (isDisplayable()) - dispose(); - throw new LWJGLException("AWT capped mode: requested mode = " + requested_mode.getWidth() + "x" + requested_mode.getHeight() + - " but got " + real_mode.getWidth() + " " + real_mode.getHeight()); - } - return null; - } - }); - } catch (PrivilegedActionException e) { - throw new LWJGLException(e); - } - } - pack(); - resize(x, y, mode.getWidth(), mode.getHeight()); - setVisible(true); - requestFocus(); - canvas.requestFocus(); - updateBounds(); - } - - public void resize(int x, int y, int width, int height) { - Insets insets = getInsets(); - setBounds(x, y, width + insets.left + insets.right, height + insets.top + insets.bottom); - } - - public int getWidth() { - Insets insets = getInsets(); - return super.getWidth() - insets.left - insets.right; - } - - public int getHeight() { - Insets insets = getInsets(); - return super.getHeight() - insets.top - insets.bottom; - } - - public Rectangle syncGetBounds() { - synchronized ( this ) { - return bounds; - } - } - - public void componentShown(ComponentEvent e) { - } - - public void componentHidden(ComponentEvent e) { - } - - private void updateBounds() { - synchronized ( this ) { - bounds = getBounds(); - } - } - - public void componentResized(ComponentEvent e) { - updateBounds(); - } - - public void componentMoved(ComponentEvent e) { - updateBounds(); - } - - public static GraphicsDevice getDevice() { - GraphicsEnvironment g_env = GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice device = g_env.getDefaultScreenDevice(); - return device; - } - - public void windowIconified(WindowEvent e) { - synchronized ( this ) { - minimized = true; - } - } - - public void windowDeiconified(WindowEvent e) { - synchronized ( this ) { - minimized = false; - } - } - - public void windowOpened(WindowEvent e) { - } - - public void windowClosed(WindowEvent e) { - } - - public void windowClosing(WindowEvent e) { - synchronized ( this ) { - close_requested = true; - } - } - - public void windowDeactivated(WindowEvent e) { - synchronized ( this ) { - active = false; - should_release_cursor = true; - should_warp_cursor = false; - } - } - - public void windowActivated(WindowEvent e) { - synchronized ( this ) { - active = true; - should_warp_cursor = true; - should_release_cursor = false; - } - } - - public boolean syncIsCloseRequested() { - boolean result; - synchronized ( this ) { - result = close_requested; - close_requested = false; - } - return result; - } - - public boolean syncIsVisible() { - synchronized ( this ) { - return !minimized; - } - } - - public boolean syncIsActive() { - synchronized ( this ) { - return active; - } - } - - public MacOSXGLCanvas getCanvas() { - return canvas; - } - - public boolean syncShouldReleaseCursor() { - boolean result; - synchronized ( this ) { - result = should_release_cursor; - should_release_cursor = false; - } - return result; - } - - public boolean syncShouldWarpCursor() { - boolean result; - synchronized ( this ) { - result = should_warp_cursor; - should_warp_cursor = false; - } - return result; - } -} diff --git a/src/java/org/lwjgl/opengl/MacOSXMouseEventQueue.java b/src/java/org/lwjgl/opengl/MacOSXMouseEventQueue.java deleted file mode 100644 index 5e4d221a..00000000 --- a/src/java/org/lwjgl/opengl/MacOSXMouseEventQueue.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2002-2008 LWJGL 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 'LWJGL' 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; - -/** - * An AWT implementation of a LWJGL compatible Mouse event queue. - * @author elias_naur - */ - -import java.awt.Component; -import java.awt.Point; -import java.awt.Rectangle; -import java.nio.IntBuffer; - -import org.lwjgl.BufferUtils; - -final class MacOSXMouseEventQueue extends MouseEventQueue { - private IntBuffer delta_buffer = BufferUtils.createIntBuffer(2); - - private boolean skip_event; - private static boolean is_grabbed; - - MacOSXMouseEventQueue(Component component) { - super(component); - } - - public void setGrabbed(boolean grab) { - if (is_grabbed != grab) { - super.setGrabbed(grab); - warpCursor(); - grabMouse(grab); - } - } - - private static synchronized void grabMouse(boolean grab) { - is_grabbed = grab; - if (!grab) - nGrabMouse(grab); - } - - protected void resetCursorToCenter() { - super.resetCursorToCenter(); - /* Clear accumulated deltas */ - getMouseDeltas(delta_buffer); - } - - protected void updateDeltas(long nanos) { - super.updateDeltas(nanos); - synchronized ( this ) { - getMouseDeltas(delta_buffer); - int dx = delta_buffer.get(0); - int dy = -delta_buffer.get(1); - if (skip_event) { - skip_event = false; - nGrabMouse(isGrabbed()); - return; - } - if ( dx != 0 || dy != 0 ) { - putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0, nanos); - addDelta(dx, dy); - } - } - } - - void warpCursor() { - synchronized (this) { - // If we're going to warp the cursor position, we'll skip the next event to avoid bogus delta values - skip_event = isGrabbed(); - } - } - - private static native void getMouseDeltas(IntBuffer delta_buffer); - - public static native void nWarpCursor(int x, int y); - - public static native void nGrabMouse(boolean grab); -} diff --git a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java index 599b6441..a427d8ca 100644 --- a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java +++ b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java @@ -92,6 +92,10 @@ final class MacOSXNativeMouse extends EventQueue { nRegisterMouseListener(window_handle); } + public synchronized void warpCursor(int x, int y) { + nWarpCursor(window_handle, x, y); + } + public synchronized void unregister() { nUnregisterMouseListener(window_handle); } diff --git a/src/native/macosx/org_lwjgl_input_Mouse.c b/src/native/macosx/org_lwjgl_input_Mouse.c deleted file mode 100644 index a9840e6c..00000000 --- a/src/native/macosx/org_lwjgl_input_Mouse.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2002-2008 LWJGL 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 'LWJGL' 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$ - * - * Mac OS X mouse handling. - * - * @author elias_naur - * @version $Revision$ - */ - -#include -#include -#include "org_lwjgl_opengl_MacOSXMouseEventQueue.h" -#include "common_tools.h" - -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_nGrabMouse(JNIEnv *env, jclass unused, jboolean grab) { - CGAssociateMouseAndMouseCursorPosition(grab == JNI_TRUE ? FALSE : TRUE); - if (grab) - CGDisplayHideCursor(kCGDirectMainDisplay); - else - CGDisplayShowCursor(kCGDirectMainDisplay); -} - -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_nWarpCursor(JNIEnv *env, jclass unused, jint x, jint y) { - CGPoint p; - p.x = x; - p.y = y; - CGWarpMouseCursorPosition(p); -} - -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_getMouseDeltas(JNIEnv *env, jclass unused, jobject delta_buffer) { - CGMouseDelta dx, dy; - CGGetLastMouseDelta(&dx, &dy); - int buffer_length = (*env)->GetDirectBufferCapacity(env, delta_buffer); - if (buffer_length != 2) { - printfDebugJava(env, "Delta buffer not large enough!"); - return; - } - jint *buffer = (*env)->GetDirectBufferAddress(env, delta_buffer); - buffer[0] = dx; - buffer[1] = dy; -}