diff options
author | Sven Gothel <[email protected]> | 2013-10-09 05:24:45 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-10-09 05:24:45 +0200 |
commit | 8be1fc983e584082b9960b4da19c56af5834d08e (patch) | |
tree | 3e30d14d29f9b3e9d23086d98d1eb94491b743e6 /src/test | |
parent | 56502090ba5c2e0c266666a4ba3ddd501e9ad95f (diff) |
NEWT Reparent/Fullscreen: Fixes X11 unsuccessful return to parent window; Add reparentWindow(..) top-level position arguments; Misc
- Fixes X11 unsuccessful return to parent window
On X11 when returning to parent window (-> CHILD),
we have to set the window invisible and wait for the result.
Otherwise it sometimes happens that the WM's reparent operation fails,
i.e. the window won't become a child of desired parent and is positioned randomly.
- Add reparentWindow(..) top-level position arguments
.. allows bringing the child-window to top-level w/ a desired position.
Otherwise the window would be positioned elsewhere as a top-level
as the plain reparenting operation.
X11 needs to set position and size _after_ making the window visible,
otherwise WM may ignore the XConfigureWindow request.
- Reparent recreate shall always store the desired position and size
On OSX/CALayer when recreation is being used, we need to store the pos/size
for later creation.
- Tests: Use 'NewtAWTReparentingKeyAdapter' where possible (reparent/fullscreen)
instead of duplicating such code.
NewtAWTReparentingKeyAdapter: Performs reparenting and fullscreen operations
off-thread (i.e. not on AWT/NEW EDT) while decorating the action w/
revoking/restoring the ExclusiveContextThread (ECT).
Manually tested 'TestGearsES2NewtCanvasAWT' reparenting and fullscreen
on X11, Windows and OSX/CALayer w/ JDK 7u40 successful.
Diffstat (limited to 'src/test')
7 files changed, 87 insertions, 146 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java index cea104e2f..5335d858e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestOffscreenLayer02NewtCanvasAWT.java @@ -162,7 +162,7 @@ public class TestOffscreenLayer02NewtCanvasAWT extends UITestCase { } setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1, null)); frame1.setSize(frameSize0); setupFrameAndShow(frame1, newtCanvasAWT1); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java index 3fc1eb61d..5d091bb6d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java @@ -42,8 +42,6 @@ import com.jogamp.newt.Display; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.awt.NewtCanvasAWT; -import com.jogamp.newt.event.KeyAdapter; -import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.opengl.GLWindow; @@ -51,17 +49,14 @@ import com.jogamp.opengl.test.junit.util.AWTRobotUtil; import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.test.junit.util.QuitAdapter; - import com.jogamp.opengl.util.Animator; - import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.newt.parenting.NewtAWTReparentingKeyAdapter; import javax.media.nativewindow.util.Dimension; -import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.PointImmutable; import javax.media.nativewindow.util.DimensionImmutable; - import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLProfile; @@ -271,50 +266,8 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase { } }); - glWindow.addKeyListener(new KeyAdapter() { - public void keyReleased(KeyEvent e) { - if( !e.isPrintableKey() || e.isAutoRepeat() ) { - return; - } - if(e.getKeyChar()=='f') { - quitAdapter.enable(false); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); - glWindow.setFullscreen(!glWindow.isFullscreen()); - System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); - glWindow.setExclusiveContextThread(t); - quitAdapter.clear(); - quitAdapter.enable(true); - } }.start(); - } else if(e.getKeyChar()=='r') { - quitAdapter.enable(false); - if(glWindow.getParent()==null) { - System.err.println("XXX glWin to home"); - glWindow.reparentWindow(newtCanvasAWT.getNativeWindow()); - } else { - final InsetsImmutable nInsets = glWindow.getInsets(); - java.awt.Insets aInsets = frame.getInsets(); - System.err.println("XXX glWin to TOP - insets " + nInsets + ", " + aInsets); - glWindow.reparentWindow(null); - int dx, dy; - if(nInsets.getTotalHeight()==0) { - dx = aInsets.left; - dy = aInsets.top; - } else { - dx = nInsets.getLeftWidth(); - dy = nInsets.getTopHeight(); - } - glWindow.setPosition(frame.getX()+frame.getWidth()+dx, frame.getY()+dy); - } - glWindow.requestFocus(); - quitAdapter.clear(); - quitAdapter.enable(true); - } - } - }); - + glWindow.addKeyListener(new NewtAWTReparentingKeyAdapter(frame, newtCanvasAWT, glWindow, quitAdapter)); + if( useAnimator ) { animator.add(glWindow); animator.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestLandscapeES2NewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestLandscapeES2NewtCanvasAWT.java index 37172822b..adc2b23ae 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestLandscapeES2NewtCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestLandscapeES2NewtCanvasAWT.java @@ -36,23 +36,18 @@ import com.jogamp.newt.Display; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.awt.NewtCanvasAWT; -import com.jogamp.newt.event.KeyAdapter; -import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.test.junit.util.QuitAdapter; - import com.jogamp.opengl.util.Animator; - import com.jogamp.opengl.test.junit.jogl.demos.es2.LandscapeES2; +import com.jogamp.opengl.test.junit.newt.parenting.NewtAWTReparentingKeyAdapter; import javax.media.nativewindow.util.Dimension; -import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.DimensionImmutable; - import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLProfile; @@ -119,50 +114,8 @@ public class TestLandscapeES2NewtCanvasAWT extends UITestCase { } }); - glWindow.addKeyListener(new KeyAdapter() { - public void keyReleased(KeyEvent e) { - if( !e.isPrintableKey() || e.isAutoRepeat() ) { - return; - } - if(e.getKeyChar()=='f') { - quitAdapter.enable(false); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); - glWindow.setFullscreen(!glWindow.isFullscreen()); - System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); - glWindow.setExclusiveContextThread(t); - quitAdapter.clear(); - quitAdapter.enable(true); - } }.start(); - } else if(e.getKeyChar()=='r') { - quitAdapter.enable(false); - if(glWindow.getParent()==null) { - System.err.println("XXX glWin to home"); - glWindow.reparentWindow(newtCanvasAWT.getNativeWindow()); - } else { - final InsetsImmutable nInsets = glWindow.getInsets(); - java.awt.Insets aInsets = frame.getInsets(); - System.err.println("XXX glWin to TOP - insets " + nInsets + ", " + aInsets); - glWindow.reparentWindow(null); - int dx, dy; - if(nInsets.getTotalHeight()==0) { - dx = aInsets.left; - dy = aInsets.top; - } else { - dx = nInsets.getLeftWidth(); - dy = nInsets.getTopHeight(); - } - glWindow.setPosition(frame.getX()+frame.getWidth()+dx, frame.getY()+dy); - } - glWindow.requestFocus(); - quitAdapter.clear(); - quitAdapter.enable(true); - } - } - }); - + glWindow.addKeyListener(new NewtAWTReparentingKeyAdapter(frame, newtCanvasAWT, glWindow, quitAdapter)); + if( useAnimator ) { animator.add(glWindow); animator.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java index 9d08d8ff4..4bf1f95c3 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java @@ -35,33 +35,58 @@ import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.QuitAdapter; public class NewtAWTReparentingKeyAdapter extends KeyAdapter { - Frame frame; - NewtCanvasAWT newtCanvasAWT; - GLWindow glWindow; + final Frame frame; + final NewtCanvasAWT newtCanvasAWT; + final GLWindow glWindow; + final QuitAdapter quitAdapter; - public NewtAWTReparentingKeyAdapter(Frame frame, NewtCanvasAWT newtCanvasAWT, GLWindow glWindow) { + public NewtAWTReparentingKeyAdapter(Frame frame, NewtCanvasAWT newtCanvasAWT, GLWindow glWindow, QuitAdapter quitAdapter) { this.frame = frame; this.newtCanvasAWT = newtCanvasAWT; this.glWindow = glWindow; + this.quitAdapter = quitAdapter; } public void keyReleased(KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { return; } - if(e.getKeyChar()=='i') { + if( e.getKeySymbol() == KeyEvent.VK_I ) { System.err.println(glWindow); - } else if(e.getKeyChar()=='d') { - glWindow.setUndecorated(!glWindow.isUndecorated()); - } else if(e.getKeyChar()=='f') { - glWindow.setFullscreen(!glWindow.isFullscreen()); - } else if(e.getKeyChar()=='l') { + } else if( e.getKeySymbol() == KeyEvent.VK_L ) { javax.media.nativewindow.util.Point p0 = newtCanvasAWT.getNativeWindow().getLocationOnScreen(null); javax.media.nativewindow.util.Point p1 = glWindow.getLocationOnScreen(null); System.err.println("NewtCanvasAWT position: "+p0+", "+p1); - } else if(e.getKeyChar()=='p') { + } else if( e.getKeySymbol() == KeyEvent.VK_D ) { + glWindow.setUndecorated(!glWindow.isUndecorated()); + } else if( e.getKeySymbol() == KeyEvent.VK_S ) { + if(glWindow.getParent()==null) { + System.err.println("XXX glWin to 100/100"); + glWindow.setPosition(100, 100); + } else { + System.err.println("XXX glWin to 0/0"); + glWindow.setPosition(0, 0); + } + } else if( e.getKeySymbol() == KeyEvent.VK_F ) { + if( null != quitAdapter ) { + quitAdapter.enable(false); + } + new Thread() { + public void run() { + final Thread t = glWindow.setExclusiveContextThread(null); + System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); + glWindow.setFullscreen(!glWindow.isFullscreen()); + System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); + glWindow.setExclusiveContextThread(t); + if( null != quitAdapter ) { + quitAdapter.clear(); + quitAdapter.enable(true); + } + } }.start(); + } else if( e.getKeySymbol() == KeyEvent.VK_P ) { new Thread() { public void run() { if(glWindow.getAnimator().isPaused()) { @@ -71,34 +96,44 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { } } }.run(); - } else if(e.getKeyChar()=='r') { - if(glWindow.getParent()==null) { - System.err.println("XXX glWin to home"); - glWindow.reparentWindow(newtCanvasAWT.getNativeWindow()); - } else { - final InsetsImmutable nInsets = glWindow.getInsets(); - java.awt.Insets aInsets = frame.getInsets(); - System.err.println("XXX glWin to TOP - insets " + nInsets + ", " + aInsets); - glWindow.reparentWindow(null); - int dx, dy; - if(nInsets.getTotalHeight()==0) { - dx = aInsets.left; - dy = aInsets.top; - } else { - dx = nInsets.getLeftWidth(); - dy = nInsets.getTopHeight(); - } - glWindow.setPosition(frame.getX()+frame.getWidth()+dx, frame.getY()+dy); - } - glWindow.requestFocus(); - } else if(e.getKeyChar()=='s') { - if(glWindow.getParent()==null) { - System.err.println("XXX glWin to 100/100"); - glWindow.setPosition(100, 100); - } else { - System.err.println("XXX glWin to 0/0"); - glWindow.setPosition(0, 0); + } else if( e.getKeySymbol() == KeyEvent.VK_R ) { + if( null != quitAdapter ) { + quitAdapter.enable(false); } + new Thread() { + public void run() { + final Thread t = glWindow.setExclusiveContextThread(null); + if(glWindow.getParent()==null) { + System.err.println("XXX glWin to HOME"); + glWindow.reparentWindow(newtCanvasAWT.getNativeWindow()); + } else { + if( null != frame ) { + final InsetsImmutable nInsets = glWindow.getInsets(); + final java.awt.Insets aInsets = frame.getInsets(); + int dx, dy; + if( nInsets.getTotalHeight()==0 ) { + dx = aInsets.left; + dy = aInsets.top; + } else { + dx = nInsets.getLeftWidth(); + dy = nInsets.getTopHeight(); + } + final int topLevelX = frame.getX()+frame.getWidth()+dx; + final int topLevelY = frame.getY()+dy; + System.err.println("XXX glWin to TOP.1 "+topLevelX+"/"+topLevelY+" - insets " + nInsets + ", " + aInsets); + glWindow.reparentWindow(null, topLevelX, topLevelY, false); + } else { + System.err.println("XXX glWin to TOP.0"); + glWindow.reparentWindow(null); + } + } + glWindow.requestFocus(); + glWindow.setExclusiveContextThread(t); + if( null != quitAdapter ) { + quitAdapter.clear(); + quitAdapter.enable(true); + } + } }.start(); } } }
\ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java index 41a6b77fa..1f19241d8 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java @@ -379,7 +379,7 @@ public class TestParenting01NEWT extends UITestCase { // glWindow2 -- child --> glWindow1: compatible Assert.assertEquals(true, glWindow2.isVisible()); System.err.println("Frames(1) "+glWindow2.getTotalFPSFrames()); - reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + reparentAction = glWindow2.reparentWindow(glWindow1, -1, -1, reparentRecreate); System.err.println("Frames(2) "+glWindow2.getTotalFPSFrames()); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); @@ -405,7 +405,7 @@ public class TestParenting01NEWT extends UITestCase { // glWindow2 --> top Assert.assertEquals(true, glWindow2.isVisible()); - reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + reparentAction = glWindow2.reparentWindow(null, -1, -1, reparentRecreate); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); @@ -567,7 +567,7 @@ public class TestParenting01NEWT extends UITestCase { switch(state) { case 0: Assert.assertEquals(true, glWindow2.isVisible()); - reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + reparentAction = glWindow2.reparentWindow(null, -1, -1, reparentRecreate); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); @@ -582,7 +582,7 @@ public class TestParenting01NEWT extends UITestCase { break; case 1: Assert.assertEquals(true, glWindow2.isVisible()); - reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + reparentAction = glWindow2.reparentWindow(glWindow1, -1, -1, reparentRecreate); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java index 60c2b702c..30ee0f129 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java @@ -88,7 +88,7 @@ public class TestParenting03AWT extends UITestCase { GLEventListener demo1 = new GearsES2(1); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1, null)); GLAnimatorControl animator1 = new Animator(glWindow1); animator1.start(); @@ -104,7 +104,7 @@ public class TestParenting03AWT extends UITestCase { GLEventListener demo2 = new GearsES2(1); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); - glWindow2.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT2, glWindow2)); + glWindow2.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT2, glWindow2, null)); animator2 = new Animator(glWindow2); animator2.start(); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java index 58dafba15..693dd1448 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java @@ -147,7 +147,7 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { GLEventListener demo1 = new GearsES2(1); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1, null)); glWindow1.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { |