From 73d6ec97e65743b49770cf13709082c80b77b935 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 16 Jan 2012 21:23:42 +0100 Subject: 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. --- .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 74 ++++++++++++++-------- .../newt/awt/event/AWTParentWindowAdapter.java | 19 ++++-- 2 files changed, 62 insertions(+), 31 deletions(-) (limited to 'src') 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) { -- cgit v1.2.3