<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1127</bug_id>
          
          <creation_ts>2015-02-06 18:24:08 +0100</creation_ts>
          <short_desc>JPopupMenu unusable over NewtCanvasAWT on Linux (even with lightweight-popups disabled)</short_desc>
          <delta_ts>2015-02-06 20:19:36 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Newt</product>
          <component>awt</component>
          <version>1</version>
          <rep_platform>All</rep_platform>
          <op_sys>linux</op_sys>
          <bug_status>UNCONFIRMED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Mike Hogye">stacktracer</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          <cc>geoff.ulman</cc>
          
          <cf_type>---</cf_type>
          <cf_scm_refs></cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>4577</commentid>
    <comment_count>0</comment_count>
    <who name="Mike Hogye">stacktracer</who>
    <bug_when>2015-02-06 18:24:08 +0100</bug_when>
    <thetext>I have a NewtCanvasAWT, with a GLWindow child, and a mouse-press listener that shows a JPopupMenu. On Windows, it always works fine. On Linux, the popup-menu is visible for a split second, then disappears.

I am already calling &quot;JPopupMenu.setDefaultLightWeightPopupEnabled(false)&quot; and/or &quot;menu.setLightWeightPopupEnabled(false)&quot;. That is not the problem here.

Sometimes, after I start my program, the popup-menu works fine a few times. But eventually, after working correctly a few times, it starts disappearing (after being visible for a split second). Once the disappearing starts, it never seems to stop again, until I close and rerun the program.

Here&apos;s a test case:

    https://gist.github.com/stacktracer/28cec8be325a0a3d1f01</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4578</commentid>
    <comment_count>1</comment_count>
    <who name="Mike Hogye">stacktracer</who>
    <bug_when>2015-02-06 18:29:56 +0100</bug_when>
    <thetext>It turns out to be pretty obvious what&apos;s going on here. NewtCanvasAWT explicitly adds a window-listener that kills the Swing menu whenever its newtChild gains focus:

    http://jogamp.org/git/?p=jogl.git;a=blob;f=src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java;h=5920d6de84755ed21ef24ff2f620ef3969bfe8a2;hb=HEAD#l258

(If that link doesn&apos;t work, look at NewtCanvasAWT.java, and search for &quot;clearAWTMenusOnNewtFocus&quot;.)

The listener is there for a reason -- without it, the popup menu can&apos;t be dismissed by just clicking outside it, which is quite annoying for a user.

However, on Linux, the listener (usually) gets fired immediately after the popup-menu becomes visible. Don&apos;t know why. Maybe a race between the Swing EDT thread and the Newt EDT thread?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4579</commentid>
    <comment_count>2</comment_count>
    <who name="Mike Hogye">stacktracer</who>
    <bug_when>2015-02-06 18:38:53 +0100</bug_when>
    <thetext>Here&apos;s a workaround. Not great for all possible situations, but probably good enough in many cases.


1. Consume the window-gained-focus event, before it can trigger clearAWTMenusOnNewtFocus (note that we&apos;re adding this listener at index 0, so that it runs before clearAWTMenusOnNewtFocus):

    glWindow.addWindowListener( 0, new WindowAdapter( )
    {
        public void windowGainedFocus( WindowEvent ev )
        {
            // Consume the event, to keep it from triggering clearAWTMenusOnNewtFocus
            ev.setConsumed( true );
        }
    } );


2. Do a little extra work when popping up the menu, so that the menu gets dismissed when you click outside it:

    glWindow.addMouseListener( new MouseAdapter( )
    {
        public void mousePressed( final MouseEvent ev )
        {
            SwingUtilities.invokeLater( new Runnable( )
            {
                public void run( )
                {
                    if ( !menu.isVisible( ) )
                    {
                        menu.show( glCanvas, ev.getX( ), ev.getY( ) );
                    }
                    else
                    {
                        menu.setVisible( false );
                    }
                }
            } );
        }
    } );


That&apos;s going to swallow all window-gained-focus events, so there are cases where it’s not a good option. But in many cases it may be better than popup-menus being broken.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4580</commentid>
    <comment_count>3</comment_count>
    <who name="Mike Hogye">stacktracer</who>
    <bug_when>2015-02-06 18:43:37 +0100</bug_when>
    <thetext>Here&apos;s the test case with workaround:

    https://gist.github.com/stacktracer/0617b091d3d184f0a887</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>