diff options
Diffstat (limited to 'src/newt/classes')
13 files changed, 125 insertions, 111 deletions
diff --git a/src/newt/classes/com/jogamp/newt/OffscreenWindow.java b/src/newt/classes/com/jogamp/newt/OffscreenWindow.java index 0f75fbfa9..e85714d4f 100644 --- a/src/newt/classes/com/jogamp/newt/OffscreenWindow.java +++ b/src/newt/classes/com/jogamp/newt/OffscreenWindow.java @@ -107,9 +107,8 @@ public class OffscreenWindow extends Window implements SurfaceChangeable { // nop return false; } - protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { + protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { shouldNotCallThis(); - return false; } } diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 0cd5b31bc..9c724314e 100755 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -303,6 +303,30 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } protected void requestFocusImpl() {} + /** + * May set to a {@link FocusRunnable}, {@link FocusRunnable#run()} before Newt requests the native focus. + * This allows notifying a covered window toolkit like AWT that the focus is requested, + * hence focus traversal can be made transparent. + */ + public void setFocusAction(FocusRunnable focusAction) { + this.focusAction = focusAction; + } + protected boolean focusAction() { + if(null!=focusAction) { + return focusAction.run(); + } + return false; + } + protected FocusRunnable focusAction = null; + + public static interface FocusRunnable { + /** + * @return false if NEWT shall proceed requesting the focus, + * true if NEWT shall not request the focus. + */ + public boolean run(); + } + // // NativeWindow impl // @@ -888,22 +912,31 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer w = screen.getWidth(); h = screen.getHeight(); } else { - x = nfs_x; - y = nfs_y; + if(0!=parentWindowHandle) { + x=0; + y=0; + } else { + x = nfs_x; + y = nfs_y; + } w = nfs_width; h = nfs_height; } if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { System.out.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()); } - this.fullscreen = setFullscreenImpl(fullscreen, x, y, w, h); + this.fullscreen = fullscreen; + setFullscreenImpl(fullscreen, x, y, w, h); } - return this.fullscreen; } finally { windowUnlock(); } + if( isVisible() ) { + windowRepaint(0, 0, getWidth(), getHeight()); + } + return this.fullscreen; } - protected abstract boolean setFullscreenImpl(boolean fullscreen, int x, int y, int widht, int height); + protected abstract void setFullscreenImpl(boolean fullscreen, int x, int y, int widht, int height); // // Child Window Management @@ -1495,6 +1528,9 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer invalidate(); } + public boolean getPropagateRepaint() { + return propagateRepaint; + } public void setPropagateRepaint(boolean v) { propagateRepaint = v; } diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index b2dd719bc..6fd924e66 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -36,10 +36,11 @@ import java.lang.reflect.*; import java.security.*; import java.awt.Button; -import java.awt.Frame; import java.awt.Canvas; +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.Frame; import java.awt.Graphics; -import java.awt.KeyboardFocusManager; import javax.media.nativewindow.*; @@ -59,7 +60,6 @@ public class NewtCanvasAWT extends java.awt.Canvas { NativeWindow parent = null; Window newtChild = null; AWTAdapter awtAdapter = null; - boolean hasSwingContainer = false; /** * Instantiates a NewtCanvas without a NEWT child.<br> @@ -75,84 +75,39 @@ public class NewtCanvasAWT extends java.awt.Canvas { super(); setNEWTChild(child); } - - class UnfocusRunnable implements Runnable { - boolean focusTraversed = false; - public void run() { - KeyboardFocusManager focusManager = - KeyboardFocusManager.getCurrentKeyboardFocusManager(); - java.awt.Component comp1 = focusManager.getPermanentFocusOwner(); - java.awt.Component comp2 = focusManager.getFocusOwner(); - if(DEBUG_IMPLEMENTATION) { - System.out.println("AWT Unfocus: traversed "+focusTraversed+" (1)"); - System.out.println("PRE PermenetFocusOwner: "+comp1); - System.out.println("PRE FocusOwner: "+comp2); - } - if(null!=comp1) { - if(!focusTraversed && null==comp2) { - comp1.requestFocus(); - focusTraversed=true; - if(DEBUG_IMPLEMENTATION) { - System.out.println("AWT Unfocus: traversed "+focusTraversed+" (*)"); - } - } else { - focusTraversed=false; - } - - if(DEBUG_IMPLEMENTATION) { - comp1 = focusManager.getPermanentFocusOwner(); - comp2 = focusManager.getFocusOwner(); - System.out.println("MID PermenetFocusOwner: "+comp1); - System.out.println("MID FocusOwner: "+comp2); - } - focusManager.clearGlobalFocusOwner(); + class FocusAction implements Window.FocusRunnable { + public boolean run() { + if ( EventQueue.isDispatchThread() ) { + focusActionImpl.run(); + } else { + try { + EventQueue.invokeAndWait(focusActionImpl); + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + return focusActionImpl.result; + } + class FocusActionImpl implements Runnable { + public final boolean result = false; // NEWT shall always proceed requesting the native focus + public void run() { if(DEBUG_IMPLEMENTATION) { - comp1 = focusManager.getPermanentFocusOwner(); - comp2 = focusManager.getFocusOwner(); - System.out.println("POST PermenetFocusOwner: "+comp1); - System.out.println("POST FocusOwner: "+comp2); - } - - if(focusTraversed && null!=newtChild) { - newtChild.requestFocus(); + System.out.println("FocusActionImpl.run() "+Window.getThreadName()); } + NewtCanvasAWT.this.requestFocusAWT(); } } + FocusActionImpl focusActionImpl = new FocusActionImpl(); } - UnfocusRunnable unfocusRunnable = new UnfocusRunnable(); + FocusAction focusAction = new FocusAction(); - class FocusListener extends WindowAdapter { - public synchronized void windowGainedFocus(WindowEvent e) { - if(DEBUG_IMPLEMENTATION) { - System.out.println("NewtCanvasAWT focus on: AWT focus "+ NewtCanvasAWT.this.hasFocus()+ - ", focusable "+NewtCanvasAWT.this.isFocusable()+", onEDT "+hasSwingContainer); - } - if(hasSwingContainer) { - java.awt.EventQueue.invokeLater(unfocusRunnable); - } else { - unfocusRunnable.run(); - } - } - public synchronized void windowLostFocus(WindowEvent e) { - if(DEBUG_IMPLEMENTATION) { - System.out.println("NewtCanvasAWT focus off: AWT focus "+ NewtCanvasAWT.this.hasFocus()); - } - } - } - FocusListener focusListener = new FocusListener(); - /** sets a new NEWT child, provoking reparenting on the NEWT level. */ public NewtCanvasAWT setNEWTChild(Window child) { if(newtChild!=child) { - if(null!=newtChild) { - newtChild.removeWindowListener(focusListener); - } newtChild = child; - if(null!=newtChild) { - newtChild.addWindowListener(focusListener); - } + newtChild.setFocusAction(focusAction); if(null!=parent) { java.awt.Container cont = getContainer(this); // reparent right away, addNotify has been called already @@ -181,16 +136,6 @@ public class NewtCanvasAWT extends java.awt.Canvas { } } - static boolean hasSwingContainer(java.awt.Component comp) { - while( null != comp ) { - if( comp instanceof javax.swing.JComponent ) { - return true; - } - comp = comp.getParent(); - } - return false; - } - static java.awt.Container getContainer(java.awt.Component comp) { while( null != comp ) { if( comp instanceof java.awt.Container ) { @@ -204,13 +149,12 @@ public class NewtCanvasAWT extends java.awt.Canvas { public void addNotify() { super.addNotify(); disableBackgroundErase(); - hasSwingContainer = hasSwingContainer(this); java.awt.Container cont = getContainer(this); if(DEBUG_IMPLEMENTATION) { // if ( isShowing() == false ) -> Container was not visible yet. // if ( isShowing() == true ) -> Container is already visible. System.err.println("NewtCanvasAWT.addNotify: "+newtChild+", "+this+", visible "+isVisible()+", showing "+isShowing()+ - ", displayable "+isDisplayable()+", swingContainer "+hasSwingContainer+" -> "+cont); + ", displayable "+isDisplayable()+" -> "+cont); } reparentWindow(true, cont); } @@ -269,6 +213,49 @@ public class NewtCanvasAWT extends java.awt.Canvas { } } + void requestFocusAWT() { + super.requestFocus(); + } + + public void requestFocus() { + super.requestFocus(); + if(null!=newtChild) { + newtChild.setFocusAction(null); + newtChild.requestFocus(); + newtChild.setFocusAction(focusAction); + } + } + + public boolean requestFocus(boolean temporary) { + boolean res = super.requestFocus(temporary); + if(res && null!=newtChild) { + newtChild.setFocusAction(null); + newtChild.requestFocus(); + newtChild.setFocusAction(focusAction); + } + return res; + } + + public boolean requestFocusInWindow() { + boolean res = super.requestFocusInWindow(); + if(res && null!=newtChild) { + newtChild.setFocusAction(null); + newtChild.requestFocus(); + newtChild.setFocusAction(focusAction); + } + return res; + } + + public boolean requestFocusInWindow(boolean temporary) { + boolean res = super.requestFocusInWindow(temporary); + if(res && null!=newtChild) { + newtChild.setFocusAction(null); + newtChild.requestFocus(); + newtChild.setFocusAction(focusAction); + } + return res; + } + // Disables the AWT's erasing of this Canvas's background on Windows // in Java SE 6. This internal API is not available in previous // releases, but the system property diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java index 43087289a..9f0944ea0 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java @@ -57,7 +57,6 @@ public class AWTParentWindowAdapter if(DEBUG_IMPLEMENTATION) { System.out.println("AWT: focusGained: START "+ e.getComponent()); } - newtWindow.requestFocus(); } public void focusLost(java.awt.event.FocusEvent e) { diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java index 6f936d2c6..56e5a4240 100644 --- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java @@ -240,7 +240,7 @@ public class AWTWindow extends Window { } } - protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { + protected void setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ runOnEDT(false, new Runnable() { public void run() { @@ -257,7 +257,6 @@ public class AWTWindow extends Window { container.setSize(w, h); } }); - return fullscreen; } public Object getWrappedWindow() { diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java index 1b8a62a9c..14621807a 100644 --- a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java +++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java @@ -109,11 +109,10 @@ public class Window extends com.jogamp.newt.Window { } } - protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { + protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { if(0!=surfaceHandle) { SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h); } - return fullscreen; } protected void requestFocusImpl() { diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java index 0fde19cd4..699b675dd 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java @@ -99,17 +99,15 @@ public class MacDisplay extends Display { if(wait) { ReflectionUtil.callStaticMethod( "java.awt.EventQueue", - cl, "invokeAndWait", new Class[] { java.lang.Runnable.class }, - new Object[] { r } ); + new Object[] { r }, cl ); } else { ReflectionUtil.callStaticMethod( "java.awt.EventQueue", - cl, "invokeLater", new Class[] { java.lang.Runnable.class }, - new Object[] { r } ); + new Object[] { r }, cl ); } } catch (Exception e) { throw new NativeWindowException(e); diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java index 9f47aa49f..8f5041253 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java @@ -280,7 +280,7 @@ public class MacWindow extends Window { } } - protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { + protected void setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { nsViewLock.lock(); try { if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { @@ -293,7 +293,6 @@ public class MacWindow extends Window { } finally { nsViewLock.unlock(); } - return fullscreen; } private void insetsChanged(int left, int top, int right, int bottom) { diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java index 7d3a0ac8c..ca06699f5 100755 --- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java @@ -87,10 +87,9 @@ public class Window extends com.jogamp.newt.Window { System.err.println("BCEGL Window.setPositionImpl n/a in BroadcomEGL"); } - protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { + protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { // n/a in BroadcomEGL System.err.println("setFullscreen n/a in BroadcomEGL"); - return false; } public boolean surfaceSwap() { diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java index 0c7254376..2f534548b 100755 --- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java @@ -100,14 +100,13 @@ public class KDWindow extends Window { System.err.println("setPosition n/a in KD"); } - protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { + protected void setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { if(0!=eglWindowHandle) { setFullScreen0(eglWindowHandle, fullscreen); if(!fullscreen) { setSize0(eglWindowHandle, w, h); } } - return true; } //---------------------------------------------------------------------- diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java index 47f79f46a..69cd62201 100755 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java @@ -162,9 +162,8 @@ public class WindowsWindow extends Window { setPosition0(parentWindowHandle, windowHandle, x , y /*, width, height*/); } - protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { + protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { setFullscreen0(fullscreen?0:parentWindowHandle, windowHandle, x, y, w, h, isUndecorated(fullscreen)); - return fullscreen; } protected boolean reparentWindowImpl() { @@ -176,7 +175,7 @@ public class WindowsWindow extends Window { protected void requestFocusImpl() { if (windowHandle != 0L) { - requestFocus0(fullscreen?0:parentWindowHandle, windowHandle); + requestFocus0(windowHandle); } } @@ -207,7 +206,7 @@ public class WindowsWindow extends Window { private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated); private native void reparentWindow0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated); private static native void setTitle0(long windowHandle, String title); - private static native void requestFocus0(long parentWindowHandle, long windowHandle); + private native void requestFocus0(long windowHandle); private void insetsChanged(int left, int top, int right, int bottom) { if (left != -1 && top != -1 && right != -1 && bottom != -1) { diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java index 6890b29fa..7a770f770 100755 --- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java @@ -102,10 +102,9 @@ public class X11Window extends Window { setPosition0(parentWindowHandle, getDisplayHandle(), windowHandle, x, y); } - protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { + protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { setPosSizeDecor0(fullscreen?0:parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, w, h, isUndecorated(fullscreen), isVisible()); - return fullscreen; } protected boolean reparentWindowImpl() { diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index e66ed1e34..99b4314a3 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -305,6 +305,9 @@ public class GLWindow extends Window implements GLAutoDrawable { public void requestFocus() { window.requestFocus(); } + public void setFocusAction(FocusRunnable focusAction) { + window.setFocusAction(focusAction); + } public Insets getInsets() { return window.getInsets(); @@ -327,9 +330,8 @@ public class GLWindow extends Window implements GLAutoDrawable { public boolean setFullscreen(boolean fullscreen) { return window.setFullscreen(fullscreen); } - protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { + protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) { shouldNotCallThis(); - return false; } public boolean isVisible() { |