Mac OS X: Be less aggressive when grabbing mouse to allow dragging of lwjgl windows with grabbed mouse

This commit is contained in:
Elias Naur 2008-09-11 09:52:23 +00:00
parent ca0023a05d
commit 36d9d31dab
3 changed files with 23 additions and 5 deletions

View File

@ -283,8 +283,11 @@ final class MacOSXDisplay implements DisplayImplementation {
GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport);
GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
}
if (frame != null && frame.syncShouldWarpCursor() && mouse_queue != null) {
mouse_queue.warpCursor();
if (frame != null && mouse_queue != null) {
if (frame.syncShouldReleaseCursor())
MacOSXMouseEventQueue.nGrabMouse(false);
if (frame.syncShouldWarpCursor())
mouse_queue.warpCursor();
}
}

View File

@ -65,6 +65,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
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(false);
@ -169,6 +170,8 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
public void windowDeactivated(WindowEvent e) {
synchronized ( this ) {
active = false;
should_release_cursor = true;
should_warp_cursor = false;
}
}
@ -176,6 +179,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
synchronized ( this ) {
active = true;
should_warp_cursor = true;
should_release_cursor = false;
}
}
@ -204,6 +208,15 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
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 ) {

View File

@ -62,7 +62,8 @@ final class MacOSXMouseEventQueue extends MouseEventQueue {
private static synchronized void grabMouse(boolean grab) {
if (is_grabbed != grab) {
is_grabbed = grab;
nGrabMouse(grab);
if (!grab)
nGrabMouse(grab);
}
}
@ -80,6 +81,7 @@ final class MacOSXMouseEventQueue extends MouseEventQueue {
int dy = -delta_buffer.get(1);
if (skip_event) {
skip_event = false;
nGrabMouse(isGrabbed());
return;
}
if ( dx != 0 || dy != 0 ) {
@ -94,13 +96,13 @@ final class MacOSXMouseEventQueue extends MouseEventQueue {
// If we're going to warp the cursor position, we'll skip the next event to avoid bogus delta values
skip_event = isGrabbed();
}
if (isGrabbed()) {
/* if (isGrabbed()) {
Rectangle bounds = getComponent().getBounds();
Point location_on_screen = getComponent().getLocationOnScreen();
int x = location_on_screen.x + bounds.width/2;
int y = location_on_screen.y + bounds.height/2;
nWarpCursor(x, y);
}
}*/
}
private static native void getMouseDeltas(IntBuffer delta_buffer);