Attempt to fix focus transfer issue between Display and AWT components in JDK 7:
- Instead of grabbing focus directly to our window, we call requestFocus on the Canvas component. This will clear focus from any other AWT component. - When the parent Canvas gets focus, we detect it in update and that's when we grab focus to our window. We can't use a listener, setFocus must be called in our thread. - Alt-tabbing out/in also works because focus goes to the Canvas. The above check will trigger again and our window will be refocused.
This commit is contained in:
parent
c0b19b7743
commit
9a895b1dba
|
@ -256,7 +256,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
setForegroundWindow(getHwnd());
|
||||
}
|
||||
setFocus(getHwnd());
|
||||
grabFocus();
|
||||
} catch (LWJGLException e) {
|
||||
nReleaseDC(hwnd, hdc);
|
||||
nDestroyWindow(hwnd);
|
||||
|
@ -373,6 +373,17 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private static native void setForegroundWindow(long hwnd);
|
||||
private static native void setFocus(long hwnd);
|
||||
|
||||
private void grabFocus() {
|
||||
if ( parent == null )
|
||||
setFocus(getHwnd());
|
||||
else
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
parent.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void restoreDisplayMode() {
|
||||
try {
|
||||
doSetGammaRamp(current_gamma);
|
||||
|
@ -510,9 +521,10 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
public void update() {
|
||||
nUpdate();
|
||||
|
||||
// This happens when we alt-tab to the frame that contains the parent. The WM_ACTIVATE event is received by AWT instead of our window proc.
|
||||
if ( !isFocused && parent != null && SwingUtilities.isDescendingFrom(parent, KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) )
|
||||
if ( !isFocused && parent != null && parent.isFocusOwner() ) {
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
|
||||
setFocus(getHwnd());
|
||||
}
|
||||
|
||||
if (redoMakeContextCurrent) {
|
||||
redoMakeContextCurrent = false;
|
||||
|
@ -935,7 +947,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
return 0L;
|
||||
case WM_MOUSEACTIVATE:
|
||||
if ( !isFocused )
|
||||
setFocus(getHwnd());
|
||||
grabFocus();
|
||||
|
||||
return 3L; // MA_NOACTIVATE
|
||||
case WM_MOUSEMOVE:
|
||||
|
|
Loading…
Reference in New Issue