Re: Thread blocking issue with AWT (but not NEWT) on OSX

Posted by hharrison on
URL: https://forum.jogamp.org/Thread-blocking-issue-with-AWT-but-not-NEWT-on-OSX-tp4026674p4026675.html

We've been hitting what may be related probelms with respect to requesting focus in AWT, below is the local patch
we've been running with and haven't seen any problems since.  Seen on Win7 64 bit fairly regularly when changing focus
between two AWT windows containing NewtCanvasAWTs


---
 .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java |   36 +++++++++++++-------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index 89a749c..b702852 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -163,34 +163,44 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
             if(DEBUG) {
                 System.err.println("NewtCanvasAWT.FocusAction: "+Display.getThreadName()+", isOnscreen "+isOnscreen+", hasFocus "+hasFocus()+", isParent "+isParent+", isFS "+isFullscreen);
             }
-            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();
+            java.awt.EventQueue.invokeLater(new Runnable() {
+                public void run() {
+
+                    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
         }
     }
     private FocusAction focusAction = new FocusAction();
-    
+
     WindowListener clearAWTMenusOnNewtFocus = new WindowAdapter() {
           @Override
           public void windowGainedFocus(WindowEvent arg0) {
               if( isParent() && !isFullscreen() ) {
-                  MenuSelectionManager.defaultManager().clearSelectedPath();
+                  java.awt.EventQueue.invokeLater(new Runnable() {
+                      public void run() {
+                          MenuSelectionManager.defaultManager().clearSelectedPath();
+                      }
+                  });
               }
           }
     };
 
     class FocusTraversalKeyListener implements KeyListener {
          boolean suppress = false;
-        
+
          public void keyPressed(KeyEvent e) {
              if( isParent() && !isFullscreen() ) {
                  handleKey(e, false);
--
1.7.10.msysgit.1