summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-01-16 21:23:42 +0100
committerSven Gothel <[email protected]>2012-01-16 21:23:42 +0100
commit73d6ec97e65743b49770cf13709082c80b77b935 (patch)
tree228953afe5b6f357f30a1c047d830919bf61ffbd /src
parent10e77e2af4448c3404becdd2ce359a3f34a91f5c (diff)
NewtCanvasAWT: Handle 'lost' child and fullscreen case.
NewtCanvasAWT may loose it's parent role (reparenting). In such cases it shall no more handle focus events. Focus handling is also no more desired in case the child is in fullscreen mode.
Diffstat (limited to 'src')
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java74
-rw-r--r--src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java19
2 files changed, 62 insertions, 31 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index a71c6106d..413dd2fe9 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -136,20 +136,32 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
public boolean isApplet() {
return jawtWindow.isApplet();
}
+
+ boolean isParent() {
+ return null!=newtChild && jawtWindow == newtChild.getParent();
+ }
+
+ boolean isFullscreen() {
+ return null != newtChild && newtChild.isFullscreen();
+ }
class FocusAction implements Window.FocusRunnable {
public boolean run() {
+ final boolean isParent = isParent();
+ final boolean isFullscreen = isFullscreen();
if(DEBUG) {
- System.err.println("NewtCanvasAWT.FocusAction: "+Display.getThreadName()+", isOnscreen "+isOnscreen+", hasFocus "+hasFocus());
+ System.err.println("NewtCanvasAWT.FocusAction: "+Display.getThreadName()+", isOnscreen "+isOnscreen+", hasFocus "+hasFocus()+", isParent "+isParent+", isFS "+isFullscreen);
}
- // Newt-EDT -> AWT-EDT may freeze Window's native peer requestFocus.
- if(!hasFocus()) {
- // Acquire the AWT focus 1st for proper AWT traversal
- NewtCanvasAWT.super.requestFocus();
- }
- if(isOnscreen) {
- // Remove the AWT focus in favor of the native NEWT focus
- KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
+ if(isParent && !isFullscreen) {
+ // Newt-EDT -> AWT-EDT may freeze Window's native peer requestFocus.
+ if(!hasFocus()) {
+ // Acquire the AWT focus 1st for proper AWT traversal
+ NewtCanvasAWT.super.requestFocus();
+ }
+ if(isOnscreen) {
+ // Remove the AWT focus in favor of the native NEWT focus
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
+ }
}
return false; // NEWT shall proceed requesting the native focus
}
@@ -159,7 +171,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
WindowListener clearAWTMenusOnNewtFocus = new WindowAdapter() {
@Override
public void windowGainedFocus(WindowEvent arg0) {
- MenuSelectionManager.defaultManager().clearSelectedPath();
+ if( isParent() && !isFullscreen() ) {
+ MenuSelectionManager.defaultManager().clearSelectedPath();
+ }
}
};
@@ -167,10 +181,14 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
boolean suppress = false;
public void keyPressed(KeyEvent e) {
- handleKey(e, false);
+ if( isParent() && !isFullscreen() ) {
+ handleKey(e, false);
+ }
}
public void keyReleased(KeyEvent e) {
- handleKey(e, true);
+ if( isParent() && !isFullscreen() ) {
+ handleKey(e, true);
+ }
}
public void keyTyped(KeyEvent e) {
if(suppress) {
@@ -217,21 +235,25 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
public void propertyChange(PropertyChangeEvent evt) {
final Object oldF = evt.getOldValue();
final Object newF = evt.getNewValue();
+ final boolean isParent = isParent();
+ final boolean isFullscreen = isFullscreen();
if(DEBUG) {
- System.err.println("NewtCanvasAWT.FocusProperty: "+evt.getPropertyName()+", src "+evt.getSource()+", "+oldF+" -> "+newF);
+ System.err.println("NewtCanvasAWT.FocusProperty: "+evt.getPropertyName()+", src "+evt.getSource()+", "+oldF+" -> "+newF+", isParent "+isParent+", isFS "+isFullscreen);
}
- if(oldF == NewtCanvasAWT.this && newF == null) {
- // focus traversal to NEWT - NOP
- if(DEBUG) {
- System.err.println("NewtCanvasAWT.FocusProperty: NEWT focus traversal");
- }
- } else if(null != newF && newF != NewtCanvasAWT.this) {
- // focus traversal to another AWT component
- if(DEBUG) {
- System.err.println("NewtCanvasAWT.FocusProperty: lost focus - clear focus");
- }
- if(newtChild.getDelegatedWindow() instanceof DriverClearFocus) {
- ((DriverClearFocus)newtChild.getDelegatedWindow()).clearFocus();
+ if(isParent && !isFullscreen) {
+ if(oldF == NewtCanvasAWT.this && newF == null) {
+ // focus traversal to NEWT - NOP
+ if(DEBUG) {
+ System.err.println("NewtCanvasAWT.FocusProperty: NEWT focus traversal");
+ }
+ } else if(null != newF && newF != NewtCanvasAWT.this) {
+ // focus traversal to another AWT component
+ if(DEBUG) {
+ System.err.println("NewtCanvasAWT.FocusProperty: lost focus - clear focus");
+ }
+ if(newtChild.getDelegatedWindow() instanceof DriverClearFocus) {
+ ((DriverClearFocus)newtChild.getDelegatedWindow()).clearFocus();
+ }
}
}
}
@@ -294,7 +316,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
throw new InternalError("XXX");
}
isOnscreen = jawtWindow.getGraphicsConfiguration().getChosenCapabilities().isOnscreen();
- awtAdapter = new AWTParentWindowAdapter(newtChild).addTo(this);
+ awtAdapter = new AWTParentWindowAdapter(jawtWindow, newtChild).addTo(this);
newtChild.addWindowListener(clearAWTMenusOnNewtFocus);
newtChild.setFocusAction(focusAction); // enable AWT focus traversal
newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingProtocol.DO_NOTHING_ON_CLOSE);
diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java b/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java
index 8e9c028d4..ce8ed7c49 100644
--- a/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java
+++ b/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java
@@ -30,6 +30,8 @@ package jogamp.newt.awt.event;
import java.awt.KeyboardFocusManager;
+import javax.media.nativewindow.NativeWindow;
+
import jogamp.newt.driver.DriverUpdatePosition;
import com.jogamp.newt.event.awt.AWTAdapter;
@@ -43,8 +45,11 @@ public class AWTParentWindowAdapter
extends AWTWindowAdapter
implements java.awt.event.HierarchyListener
{
- public AWTParentWindowAdapter(com.jogamp.newt.Window downstream) {
+ NativeWindow downstreamParent;
+
+ public AWTParentWindowAdapter(NativeWindow downstreamParent, com.jogamp.newt.Window downstream) {
super(downstream);
+ this.downstreamParent = downstreamParent;
}
public AWTAdapter addTo(java.awt.Component awtComponent) {
@@ -61,13 +66,17 @@ public class AWTParentWindowAdapter
// forward focus to NEWT child
final com.jogamp.newt.Window newtChild = getNewtWindow();
final boolean isOnscreen = newtChild.isNativeValid() && newtChild.getGraphicsConfiguration().getChosenCapabilities().isOnscreen();
+ final boolean isParent = downstreamParent == newtChild.getParent();
+ final boolean isFullscreen = newtChild.isFullscreen();
if(DEBUG_IMPLEMENTATION) {
- System.err.println("AWT: focusGained: onscreen "+ isOnscreen+", "+e);
+ System.err.println("AWT: focusGained: onscreen "+ isOnscreen+", "+e+", isParent: "+isParent+", isFS "+isFullscreen);
}
- if(isOnscreen) {
- KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
+ if(isParent) {
+ if(isOnscreen && !isFullscreen) {
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
+ }
+ newtChild.requestFocus(false);
}
- newtChild.requestFocus(false);
}
public void focusLost(java.awt.event.FocusEvent e) {