From 51466773f4fe54c1526fc9daea6203b30808a665 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 16 Jan 2006 23:09:58 +0000 Subject: [PATCH] Win32: Quick test to see if we can get more accurate polling data from the mouse when not grabbed --- src/native/win32/org_lwjgl_input_Mouse.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/native/win32/org_lwjgl_input_Mouse.c b/src/native/win32/org_lwjgl_input_Mouse.c index 27d96bd9..cc3b079d 100644 --- a/src/native/win32/org_lwjgl_input_Mouse.c +++ b/src/native/win32/org_lwjgl_input_Mouse.c @@ -392,12 +392,19 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse if(grab) { if (!mouse_grabbed) { mouse_grabbed = true; + IDirectInputDevice_Unacquire(mDIDevice); + if (IDirectInputDevice_SetCooperativeLevel(mDIDevice, getCurrentHWND(), DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) + printfDebugJava(env, "Failed to reset cooperative mode"); IDirectInputDevice_Acquire(mDIDevice); } } else { if (mouse_grabbed) { mouse_grabbed = false; IDirectInputDevice_Unacquire(mDIDevice); + if (IDirectInputDevice_SetCooperativeLevel(mDIDevice, getCurrentHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) == DI_OK || + IDirectInputDevice_SetCooperativeLevel(mDIDevice, getCurrentHWND(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) == DI_OK) { + IDirectInputDevice_Acquire(mDIDevice); + } } } initEventQueue(&event_queue, EVENT_SIZE); @@ -467,8 +474,8 @@ static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject but return; } - if (mouse_grabbed) { - hRes = IDirectInputDevice_GetDeviceState(mDIDevice, sizeof(DIMOUSESTATE), &diMouseState); + hRes = IDirectInputDevice_GetDeviceState(mDIDevice, sizeof(DIMOUSESTATE), &diMouseState); + if (mouse_grabbed || hRes == DI_OK) { if (hRes != DI_OK) { // Don't allow the mouse to drift when failed diMouseState.lX = 0;