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;