diff --git a/src/native/linux/org_lwjgl_Window.cpp b/src/native/linux/org_lwjgl_Window.cpp index ecc25e7b..704d03fa 100644 --- a/src/native/linux/org_lwjgl_Window.cpp +++ b/src/native/linux/org_lwjgl_Window.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include "Window.h" #include "org_lwjgl_Window.h" static Atom delete_atom; @@ -69,7 +69,7 @@ static void waitMapped(Display *disp, Window win) { } bool releaseInput(void) { - if (current_fullscreen) + if (current_fullscreen || input_released) return false; releaseKeyboard(); releasePointer(); @@ -94,6 +94,9 @@ static void handleMessages(JNIEnv *env, jobject window_obj) { if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom)) env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "closeRequested", "Z"), JNI_TRUE); break; + case FocusOut: + releaseInput(); + break; case FocusIn: acquireInput(); break; diff --git a/src/native/linux/org_lwjgl_input_Keyboard.cpp b/src/native/linux/org_lwjgl_input_Keyboard.cpp index 5a24beb4..dbddef30 100644 --- a/src/native/linux/org_lwjgl_input_Keyboard.cpp +++ b/src/native/linux/org_lwjgl_input_Keyboard.cpp @@ -98,18 +98,6 @@ static void ungrabKeyboard(void) { setRepeatMode(AutoRepeatModeDefault); } -void acquireKeyboard(void) { - if (!created) - return; - should_grab = true; -} - -void releaseKeyboard(void) { - if (!created) - return; - should_grab = false; -} - static void updateGrab(void) { if (should_grab) { if (!keyboard_grabbed) @@ -120,6 +108,16 @@ static void updateGrab(void) { } } +void acquireKeyboard(void) { + should_grab = true; + updateGrab(); +} + +void releaseKeyboard(void) { + should_grab = false; + updateGrab(); +} + /* * Class: org_lwjgl_input_Keyboard * Method: nCreate diff --git a/src/native/linux/org_lwjgl_input_Mouse.cpp b/src/native/linux/org_lwjgl_input_Mouse.cpp index 6510a233..e6724602 100644 --- a/src/native/linux/org_lwjgl_input_Mouse.cpp +++ b/src/native/linux/org_lwjgl_input_Mouse.cpp @@ -122,10 +122,11 @@ static int grabPointer(void) { int result; int mask = FocusChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask; result = XGrabPointer(getCurrentDisplay(), getCurrentWindow(), False, mask, GrabModeAsync, GrabModeAsync, getCurrentWindow(), blank_cursor, CurrentTime); - XWarpPointer(getCurrentDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y); - XF86VidModeSetViewPort(getCurrentDisplay(), getCurrentScreen(), 0, 0); // make sure we have a centered window - if (result == GrabSuccess) + if (result == GrabSuccess) { pointer_grabbed = true; + XWarpPointer(getCurrentDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y); + XF86VidModeSetViewPort(getCurrentDisplay(), getCurrentScreen(), 0, 0); // make sure we have a centered window + } return result; } @@ -134,19 +135,6 @@ static void ungrabPointer(void) { XUngrabPointer(getCurrentDisplay(), CurrentTime); } -void acquirePointer(void) { - if (!created) - return; - should_grab = true; -} - -void releasePointer(void) { - if (!created) - return; - should_grab = false; -} - - static void updateGrab(void) { if (should_grab) { if (!pointer_grabbed) @@ -157,6 +145,16 @@ static void updateGrab(void) { } } +void acquirePointer(void) { + should_grab = true; + updateGrab(); +} + +void releasePointer(void) { + should_grab = false; + updateGrab(); +} + /* * Class: org_lwjgl_input_Mouse * Method: nCreate