Linux: Removed grab/ungrabServer logic and replace it with catching of any X errors occruing because of a XSetInputFocus race

This commit is contained in:
Elias Naur 2008-04-09 23:40:18 +00:00
parent ab4bb1ebcb
commit 450634c49c
2 changed files with 19 additions and 10 deletions

View File

@ -752,15 +752,7 @@ final class LinuxDisplay implements DisplayImplementation {
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 @@ final class LinuxDisplay implements DisplayImplementation {
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;

View File

@ -79,7 +79,7 @@ static Visual *current_visual;
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 @@ static jlong openDisplay(JNIEnv *env) {
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);