From: <eli...@us...> - 2008-04-09 23:40:20
|
Revision: 3000 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3000&view=rev Author: elias_naur Date: 2008-04-09 16:40:18 -0700 (Wed, 09 Apr 2008) Log Message: ----------- Linux: Removed grab/ungrabServer logic and replace it with catching of any X errors occruing because of a XSetInputFocus race Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2008-04-09 18:44:25 UTC (rev 2999) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2008-04-09 23:40:18 UTC (rev 3000) @@ -752,15 +752,7 @@ if (focused_at_least_once) releaseInput(); if (parent != null && parent.isFocusOwner()) { - // Normally, a real time stamp from an event should be passed to XSetInputFocus instead of CurrentTime, but we don't get timestamps - // from awt. Instead we grab the server and check if the focus changed to avoid a race where our window is made unviewable while focusing it. - grabServer(getDisplay()); - try { - if (nGetInputFocus(getDisplay()) == current_focus) - setInputFocus(getDisplay(), getWindow(), CurrentTime); - } finally { - ungrabServer(getDisplay()); - } + setInputFocusUnsafe(); } } } @@ -768,6 +760,17 @@ private static native void grabServer(long display); private static native void ungrabServer(long display); + private static void setInputFocusUnsafe() { + setInputFocus(getDisplay(), getWindow(), CurrentTime); + try { + checkXError(getDisplay()); + } catch (LWJGLException e) { + // Since we don't have any event timings for XSetInputFocus, a race condition might give a BadMatch, which we'll catch ang ignore + LWJGLUtil.log("Got exception while trying to focus: " + e); + } + } + private static native void checkXError(long display) throws LWJGLException; + private void releaseInput() { if (isLegacyFullscreen() || input_released) return; Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2008-04-09 18:44:25 UTC (rev 2999) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2008-04-09 23:40:18 UTC (rev 3000) @@ -79,7 +79,7 @@ static bool async_x_error; static char error_message[ERR_MSG_SIZE]; -bool checkXError(JNIEnv *env, Display *disp) { +static bool checkXError(JNIEnv *env, Display *disp) { XSync(disp, False); if (async_x_error) { async_x_error = false; @@ -113,6 +113,12 @@ return (intptr_t)display_connection; } +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_checkXError(JNIEnv *env, jclass unused, jlong display_ptr) { + Display *disp = (Display *)(intptr_t)display_ptr; + XSync(disp, False); + checkXError(env, disp); +} + JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetDefaultScreen(JNIEnv *env, jclass unused, jlong display_ptr) { Display *disp = (Display *)(intptr_t)display_ptr; return XDefaultScreen(disp); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |