Do not reset cursor clipping when releasing mouse grab in fullscreen mode. Fix #106

Also refactored and optimized cursor handling.
This commit is contained in:
Ioannis Tsakpinis 2015-02-09 17:08:38 +02:00
parent ae4606c53f
commit e4b098c5e2
2 changed files with 10 additions and 42 deletions

View file

@ -379,16 +379,13 @@ final class WindowsDisplay implements DisplayImplementation {
} }
setFocus(getHwnd()); setFocus(getHwnd());
redoMakeContextCurrent = true; redoMakeContextCurrent = true;
if (Display.isFullscreen())
updateClipping();
} else { } else {
if ( keyboard != null ) if ( keyboard != null )
keyboard.releaseAll(millis); keyboard.releaseAll(millis);
if ( Display.isFullscreen() ) { if ( Display.isFullscreen() ) {
showWindow(getHwnd(), SW_SHOWMINNOACTIVE); showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
resetDisplayMode(); resetDisplayMode();
} else }
updateClipping();
} }
updateCursor(); updateCursor();
inAppActivate = false; inAppActivate = false;
@ -610,7 +607,7 @@ final class WindowsDisplay implements DisplayImplementation {
} }
public void grabMouse(boolean grab) { public void grabMouse(boolean grab) {
mouse.grab(grab, shouldGrab()); mouse.grab(grab);
updateCursor(); updateCursor();
} }
@ -634,13 +631,15 @@ final class WindowsDisplay implements DisplayImplementation {
private void updateCursor() { private void updateCursor() {
try { try {
if (mouse != null && shouldGrab()) if (mouse != null && shouldGrab()) {
centerCursor(hwnd);
nSetNativeCursor(getHwnd(), mouse.getBlankCursor()); nSetNativeCursor(getHwnd(), mouse.getBlankCursor());
else } else
nSetNativeCursor(getHwnd(), current_cursor); nSetNativeCursor(getHwnd(), current_cursor);
} catch (LWJGLException e) { } catch (LWJGLException e) {
LWJGLUtil.log("Failed to update cursor: " + e); LWJGLUtil.log("Failed to update cursor: " + e);
} }
updateClipping();
} }
static native void nSetNativeCursor(long hwnd, Object handle) throws LWJGLException; static native void nSetNativeCursor(long hwnd, Object handle) throws LWJGLException;
@ -981,16 +980,6 @@ final class WindowsDisplay implements DisplayImplementation {
resized = true; resized = true;
updateWidthAndHeight(); updateWidthAndHeight();
break; 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: case WM_KILLFOCUS:
appActivate(false, millis); appActivate(false, millis);
return 0L; return 0L;
@ -1012,7 +1001,7 @@ final class WindowsDisplay implements DisplayImplementation {
} }
if ( !mouseInside ) { if ( !mouseInside ) {
mouseInside = true; mouseInside = true;
updateClipping(); updateCursor();
nTrackMouseEvent(hwnd); nTrackMouseEvent(hwnd);
} }
return 0L; return 0L;

View file

@ -105,7 +105,7 @@ final class WindowsMouse {
coord_buffer.put(coord_buffer.position() + 1, accum_dy); coord_buffer.put(coord_buffer.position() + 1, accum_dy);
if ( display.isActive() && display.isVisible() && (accum_dx != 0 || accum_dy != 0) ) if ( display.isActive() && display.isVisible() && (accum_dx != 0 || accum_dy != 0) )
centerCursor(); WindowsDisplay.centerCursor(hwnd);
} else { } else {
coord_buffer.put(coord_buffer.position() + 0, last_x); coord_buffer.put(coord_buffer.position() + 0, last_x);
coord_buffer.put(coord_buffer.position() + 1, last_y); coord_buffer.put(coord_buffer.position() + 1, last_y);
@ -135,25 +135,8 @@ final class WindowsMouse {
return blank_cursor; return blank_cursor;
} }
public void grab(boolean grab, boolean should_center) { public void grab(boolean grab) {
if (grab) { mouse_grabbed = 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();
}
}
event_queue.clearEvents(); event_queue.clearEvents();
} }
@ -162,10 +145,6 @@ final class WindowsMouse {
putMouseEvent((byte)-1, (byte)0, event_dwheel, millis*1000000); putMouseEvent((byte)-1, (byte)0, event_dwheel, millis*1000000);
} }
private void centerCursor() {
WindowsDisplay.centerCursor(hwnd);
}
public void setPosition(int x, int y) { public void setPosition(int x, int y) {
this.last_x = x; this.last_x = x;
this.last_y = y; this.last_y = y;