From e4b098c5e20b9f4465e3a5efc34cc40684df259d Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Mon, 9 Feb 2015 17:08:38 +0200 Subject: [PATCH] Do not reset cursor clipping when releasing mouse grab in fullscreen mode. Fix #106 Also refactored and optimized cursor handling. --- src/java/org/lwjgl/opengl/WindowsDisplay.java | 25 +++++------------ src/java/org/lwjgl/opengl/WindowsMouse.java | 27 +++---------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/src/java/org/lwjgl/opengl/WindowsDisplay.java b/src/java/org/lwjgl/opengl/WindowsDisplay.java index e2d59af2..9988aded 100644 --- a/src/java/org/lwjgl/opengl/WindowsDisplay.java +++ b/src/java/org/lwjgl/opengl/WindowsDisplay.java @@ -379,16 +379,13 @@ final class WindowsDisplay implements DisplayImplementation { } setFocus(getHwnd()); redoMakeContextCurrent = true; - if (Display.isFullscreen()) - updateClipping(); } else { if ( keyboard != null ) keyboard.releaseAll(millis); if ( Display.isFullscreen() ) { showWindow(getHwnd(), SW_SHOWMINNOACTIVE); resetDisplayMode(); - } else - updateClipping(); + } } updateCursor(); inAppActivate = false; @@ -610,7 +607,7 @@ final class WindowsDisplay implements DisplayImplementation { } public void grabMouse(boolean grab) { - mouse.grab(grab, shouldGrab()); + mouse.grab(grab); updateCursor(); } @@ -634,13 +631,15 @@ final class WindowsDisplay implements DisplayImplementation { private void updateCursor() { try { - if (mouse != null && shouldGrab()) + if (mouse != null && shouldGrab()) { + centerCursor(hwnd); nSetNativeCursor(getHwnd(), mouse.getBlankCursor()); - else + } else nSetNativeCursor(getHwnd(), current_cursor); } catch (LWJGLException e) { LWJGLUtil.log("Failed to update cursor: " + e); } + updateClipping(); } static native void nSetNativeCursor(long hwnd, Object handle) throws LWJGLException; @@ -981,16 +980,6 @@ final class WindowsDisplay implements DisplayImplementation { resized = true; updateWidthAndHeight(); break; - case WM_SETCURSOR: - if((lParam & 0xFFFF) == HTCLIENT) { - // if the cursor is inside the client area, reset it - // to the current LWJGL-cursor - updateCursor(); - return -1; //TRUE - } else { - // let Windows handle cursors outside the client area for resizing, etc. - return defWindowProc(hwnd, msg, wParam, lParam); - } case WM_KILLFOCUS: appActivate(false, millis); return 0L; @@ -1012,7 +1001,7 @@ final class WindowsDisplay implements DisplayImplementation { } if ( !mouseInside ) { mouseInside = true; - updateClipping(); + updateCursor(); nTrackMouseEvent(hwnd); } return 0L; diff --git a/src/java/org/lwjgl/opengl/WindowsMouse.java b/src/java/org/lwjgl/opengl/WindowsMouse.java index a7e279b6..ad3b8169 100644 --- a/src/java/org/lwjgl/opengl/WindowsMouse.java +++ b/src/java/org/lwjgl/opengl/WindowsMouse.java @@ -105,7 +105,7 @@ final class WindowsMouse { coord_buffer.put(coord_buffer.position() + 1, accum_dy); if ( display.isActive() && display.isVisible() && (accum_dx != 0 || accum_dy != 0) ) - centerCursor(); + WindowsDisplay.centerCursor(hwnd); } else { coord_buffer.put(coord_buffer.position() + 0, last_x); coord_buffer.put(coord_buffer.position() + 1, last_y); @@ -135,25 +135,8 @@ final class WindowsMouse { return blank_cursor; } - public void grab(boolean grab, boolean should_center) { - if (grab) { - if (!mouse_grabbed) { - mouse_grabbed = true; - if (should_center) { - try { - WindowsDisplay.setupCursorClipping(hwnd); - } catch (LWJGLException e) { - LWJGLUtil.log("Failed to setup cursor clipping: " + e); - } - centerCursor(); - } - } - } else { - if (mouse_grabbed) { - mouse_grabbed = false; - WindowsDisplay.resetCursorClipping(); - } - } + public void grab(boolean grab) { + mouse_grabbed = grab; event_queue.clearEvents(); } @@ -162,10 +145,6 @@ final class WindowsMouse { putMouseEvent((byte)-1, (byte)0, event_dwheel, millis*1000000); } - private void centerCursor() { - WindowsDisplay.centerCursor(hwnd); - } - public void setPosition(int x, int y) { this.last_x = x; this.last_y = y;