Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze due to menu safe triangle event queue #870

Closed
Chrriis opened this issue Jul 19, 2024 · 10 comments
Closed

Freeze due to menu safe triangle event queue #870

Chrriis opened this issue Jul 19, 2024 · 10 comments
Milestone

Comments

@Chrriis
Copy link
Contributor

Chrriis commented Jul 19, 2024

Hi!

I have an application that has its own event queue. This event queue must be the active event queue or else the application freezes. Unfortunately, when I show a menu under FlatLaf, the application freezes due to the safe triangle feature and its custom event queue.

Thus, I would like to deactivate the safe triangle feature, but I cannot change the code of the application.

  • Is there a way to force "Menu.useSafeTriangle=false" using system properties?
  • Is there a way to use a theme properties file which path is defined by a system property?

Related:
apache/netbeans#4231
#490

Cheers,
-Christopher

@DevCharly
Copy link
Collaborator

Is there a way to force "Menu.useSafeTriangle=false" using system properties?

no

Is there a way to use a theme properties file which path is defined by a system property?

no

What you could do is use your own main method, disable safe triangle, and invoke application main method.
E.g.

class MyApp {
    public static void main( String[] args ) {
        UIManager.put( "Menu.useSafeTriangle", false );
        com.application.App.main( args );
    }
}

Hint: Newer Java versions can execute single .java files directly (without compiling).

@Chrriis
Copy link
Contributor Author

Chrriis commented Jul 20, 2024

Hi Karl, thanks for your fast answer as usual!

Unfortunately, I have limited possibilities... I can add system properties (and the product allows to set the look and feel through properties), I can alter the classpath, but I cannot change the way the main is invoked (hidden from me).

Would it be possible to add a system property to switch off this queue-interfering business? Or else FlatLaf will not be a viable option for me 😞

Cheers,
-Christopher

@DevCharly
Copy link
Collaborator

I wonder what "product" you use?

Maybe it makes sense to disable this feature automatically if a custom event queue is used?
But I'm not sure whether this would affect special environments. E.g. WebSwing

@Chrriis
Copy link
Contributor Author

Chrriis commented Jul 20, 2024

I wonder what "product" you use?

It is a legacy application that has its own launcher (exe).

Maybe it makes sense to disable this feature automatically if a custom event queue is used?

Hard to tell, I am not sure if having a custom event queue necessarily means that yours will freeze the application?

So, as a first step, I think it would make sens to have a way to switch it off... don't you agree? 😉

@DevCharly
Copy link
Collaborator

Ok, I'll add a system property in the next release.

If you need a solution now, remove following line and build flatlaf-core:

subMenuUsabilityHelperInstalled = SubMenuUsabilityHelper.install();

@DevCharly DevCharly added this to the 3.6 milestone Jul 20, 2024
@Chrriis
Copy link
Contributor Author

Chrriis commented Jul 20, 2024

Thanks, but I cannot use unofficial versions of FlatLaf...

Possible improvement to the properties logic:
If no property is specified, then safe triangle feature is active only if there is no custom event queue.
If a property is specified (sys prop and/or UIManager prop), then most restrictive is used.

It would prevent unexpected freezes due to custom event queues for users who have no idea what the problem could be.
This would also allow someone with a custom event queue to activate the feature by setting the property to "=true".

DevCharly added a commit that referenced this issue Aug 5, 2024
…Triangle` to allow disabling submenu safe triangle for SWTSwing (issue #870)

also check whether EventQueue.push() succeeded; if not, disable submenu safe triangle
@DevCharly
Copy link
Collaborator

implemented in latest 3.5.1-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

Added system property flatlaf.useSubMenuSafeTriangle to allow disabling submenu safe triangle.
Also check whether EventQueue.push() succeeded; if not, disable submenu safe triangle.

Did not implement your suggestion because this would break some application that use FlatLaf (e.g. OpenPnP, jadx and Pixelitor).
https://github.com/search?q=getSystemEventQueue%28%29.push&type=code

3.5.1 release is coming soon...

@DevCharly DevCharly modified the milestones: 3.6, 3.5.1 Aug 5, 2024
@Chrriis
Copy link
Contributor Author

Chrriis commented Aug 5, 2024

Hi Karl,

Thanks a lot for the system property!! 😃

Did not implement your suggestion because this would break some application that use FlatLaf

I am confused by this comment... Do you mean that you push your own queue even if a custom queue is already in place? Don't you think THAT is going to break the applications, since their queue will be ignored?

Also check whether EventQueue.push() succeeded

Good point!

@DevCharly
Copy link
Collaborator

Did not implement your suggestion because this would break some application that use FlatLaf

I am confused by this comment...

I meant that your suggestion would disable submenu safe triangle for existing applications that use FlatLaf and use a custom event queue.

Do you mean that you push your own queue even if a custom queue is already in place?

Yes, that has not changed. This is done since FlatLaf 2.1.

Don't you think THAT is going to break the applications, since their queue will be ignored?

Good question, but the FlatLaf submenu event queue is used only temporary for a short time while the mouse is over a JMenu that has submenus, or while moving within the safe triangle...

A (temporary) custom event queue was the only solution (to my knowledge) to catch and ignore mouse events while mouse is moving within safe triangle. And this is a huge usability improvement for submenus and IMHO worth the risk of temporary loosing some feature of a custom application event queue.

@Chrriis
Copy link
Contributor Author

Chrriis commented Aug 5, 2024

A (temporary) custom event queue was the only solution (to my knowledge) to catch and ignore mouse events

Hm, I wonder... Perhaps when a sub-menu is showing you could:

  • Remove all the listeners of the sibling items.
  • Add a custom listener to the sibling items, that checks the distance. It restores the original states and propagates the event if outside the triangle.
  • Restore state when the sub-menu is hidden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants