From 7c83b3d24dc376c9b3566f3d774c7ac4c7f1cb5a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 16 Jan 2012 22:17:00 +0100 Subject: NEWTWindow Focus: Skip requestFocus() if already owning focus; setFullscreen() requests focus 'later'. We shall rely on the focus state, hence we can skip 'requestFocus()' if we already own the focus. This allows a fast-path especially when called from native code (mouse click). Request focus 'later' on setFullscreen() allowing native WM to complete event handling, this is required especially on X11 to guarantee a focused fullscreen window. --- src/newt/classes/jogamp/newt/WindowImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 6e7735509..10fa36a83 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -1584,7 +1584,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public void requestFocus(boolean wait) { - if(isNativeValid() && !focusAction()) { + if(!hasFocus() && isNativeValid() && !focusAction()) { runOnEDTIfAvail(wait, requestFocusAction); } } @@ -1743,8 +1743,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer display.dispatchMessagesNative(); // status up2date WindowImpl.this.waitForSize(w, h, false, TIMEOUT_NATIVEWINDOW); display.dispatchMessagesNative(); // status up2date - requestFocusInt(true); - display.dispatchMessagesNative(); // status up2date if(DEBUG_IMPLEMENTATION) { System.err.println("Window fs done: " + WindowImpl.this); @@ -1761,6 +1759,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer public boolean setFullscreen(boolean fullscreen) { runOnEDTIfAvail(true, new FullScreenActionImpl(fullscreen)); + if(isVisible()) { + // Request focus 'later' allowing native WM to complete event handling, + // this is required especially on X11 to guarantee a focused fullscreen window. + try { + Thread.sleep(100); + } catch (InterruptedException e) { } + requestFocus(true); + } return this.fullscreen; } -- cgit v1.2.3