Fix small race condition in LinuxDisplay when focusing in and out really fast.

This commit is contained in:
kappa1 2011-06-26 11:50:23 +00:00
parent 6e15f0b781
commit 7782156962
1 changed files with 16 additions and 4 deletions

View File

@ -148,16 +148,12 @@ final class LinuxDisplay implements DisplayImplementation {
private final FocusListener focus_listener = new FocusListener() { private final FocusListener focus_listener = new FocusListener() {
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
synchronized (GlobalLock.lock) { synchronized (GlobalLock.lock) {
nGrabKeyboard(getDisplay(), current_window);
focused = true; focused = true;
input_released = false;
} }
} }
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
synchronized (GlobalLock.lock) { synchronized (GlobalLock.lock) {
nUngrabKeyboard(getDisplay());
focused = false; focused = false;
input_released = true;
} }
} }
}; };
@ -823,6 +819,7 @@ final class LinuxDisplay implements DisplayImplementation {
lockAWT(); lockAWT();
try { try {
processEvents(); processEvents();
checkInput();
} finally { } finally {
unlockAWT(); unlockAWT();
} }
@ -904,6 +901,21 @@ final class LinuxDisplay implements DisplayImplementation {
} }
} }
private void checkInput() {
if (parent == null) return;
if (focused != keyboard_grabbed) {
if (focused) {
grabKeyboard();
input_released = false;
}
else {
ungrabKeyboard();
input_released = true;
}
}
}
private void setFocused(boolean got_focus, int focus_detail) { private void setFocused(boolean got_focus, int focus_detail) {
if (focused == got_focus || focus_detail == NotifyDetailNone || focus_detail == NotifyPointer || focus_detail == NotifyPointerRoot || parent != null) if (focused == got_focus || focus_detail == NotifyDetailNone || focus_detail == NotifyPointer || focus_detail == NotifyPointerRoot || parent != null)
return; return;