diff --git a/platform_build/windows_ant/build.xml b/platform_build/windows_ant/build.xml
index 7aa3f9f3..83a8f10f 100644
--- a/platform_build/windows_ant/build.xml
+++ b/platform_build/windows_ant/build.xml
@@ -52,7 +52,7 @@
-
+
diff --git a/src/java/org/lwjgl/opengl/WindowsDisplay.java b/src/java/org/lwjgl/opengl/WindowsDisplay.java
index ce2b1de7..54dc989c 100644
--- a/src/java/org/lwjgl/opengl/WindowsDisplay.java
+++ b/src/java/org/lwjgl/opengl/WindowsDisplay.java
@@ -62,6 +62,7 @@ final class WindowsDisplay implements DisplayImplementation {
private final static int WM_MBUTTONUP = 0x0208;
private final static int WM_MBUTTONDBLCLK = 0x0209;
private final static int WM_MOUSEWHEEL = 0x020A;
+ private final static int WM_MOUSELEAVE = 0x02A3;
private final static int WM_KEYDOWN = 256;
private final static int WM_KEYUP = 257;
private final static int WM_SYSKEYUP = 261;
@@ -149,6 +150,8 @@ final class WindowsDisplay implements DisplayImplementation {
private long small_icon;
private long large_icon;
+ private boolean trackingMouse = false;
+
WindowsDisplay() {
current_display = this;
}
@@ -669,8 +672,18 @@ final class WindowsDisplay implements DisplayImplementation {
}
private void handleMouseMoved(int x, int y, long millis) {
- if (mouse != null)
- mouse.handleMouseMoved(x, y, millis, shouldGrab());
+ if (mouse != null) {
+ mouse.handleMouseMoved(x, y, millis, shouldGrab());
+
+ // if we're not tracking mouse and we get a mouse move event - START TRACKING!
+ if(!trackingMouse && !Mouse.isGrabbed()) {
+ LWJGLUtil.log("initial mouse move - need tracking");
+
+ if (nTrackMouse(hwnd)) {
+ trackingMouse = true;
+ }
+ }
+ }
}
private void handleMouseScrolled(int amount, long millis) {
@@ -796,6 +809,9 @@ final class WindowsDisplay implements DisplayImplementation {
case WM_MBUTTONUP:
handleMouseButton(2, 0, millis);
return 0;
+ case WM_MOUSELEAVE:
+ handleMouseLeave(millis);
+ return 0;
case WM_SYSCHAR:
case WM_CHAR:
handleChar(wParam, lParam, millis);
@@ -886,4 +902,17 @@ final class WindowsDisplay implements DisplayImplementation {
return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right;
}
}
+
+
+
+
+ private static native boolean nTrackMouse(long hwnd);
+
+ private void handleMouseLeave(long millis) {
+ handleMouseButton(0, 0, millis);
+ handleMouseButton(1, 0, millis);
+ handleMouseButton(2, 0, millis);
+ trackingMouse = false;
+ }
+
}
diff --git a/src/native/windows/org_lwjgl_opengl_Display.c b/src/native/windows/org_lwjgl_opengl_Display.c
index 5df1c194..c8eb57f8 100644
--- a/src/native/windows/org_lwjgl_opengl_Display.c
+++ b/src/native/windows/org_lwjgl_opengl_Display.c
@@ -489,3 +489,14 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_getSystemMetrics(JNI
return GetSystemMetrics(index);
}
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nTrackMouse(JNIEnv *env, jclass unused, jlong hwnd_int) {
+ HWND hwnd = (HWND)(INT_PTR)hwnd_int;
+
+ TRACKMOUSEEVENT tme;
+ tme.cbSize = sizeof(TRACKMOUSEEVENT);
+ tme.dwFlags = TME_LEAVE;
+ tme.hwndTrack = hwnd;
+
+ return _TrackMouseEvent(&tme);
+}
+