Making a menu_bar submenu close when the menu_bar loses focus

11 views
Skip to first unread message

pvr...@btinternet.com

unread,
Sep 15, 2020, 8:11:25 AM9/15/20
to fltk.general
When I open a top-level sub-menu in my Fl_Menu_Bar I then find that it stays dropped down when I move focus away from the menu_bar. The only times it doesn't is if 1) I pass the mouse over another menu item, in which case the second sub-menu drops down, or 2) I click on the menu_bar away from any menu items. This has the effect that all other events in my app seem to be blocked, especially the app close event which is the most infuriating.

I presume I need to handle the UNFOCUS event in the menu_bar, but how do I cause the sub-menu to close.

Alternaively I would like to generate a system noise alert that window close is being ignored.

I am using a recent (23/4/2020) snap-shot of 1.4 on W10 (2004

Thanks in advance
Phil.

Greg Ercolano

unread,
Sep 15, 2020, 11:15:53 AM9/15/20
to fltkg...@googlegroups.com
On 2020-09-15 05:11, 'pvr...@btinternet.com' via fltk.general wrote:
> When I open a top-level sub-menu in my Fl_Menu_Bar I then find that it stays
> dropped down when I move focus away from the menu_bar.

Sounds like perfectly normal behavior to me.

I get the same behavior from the menubars for e.g. Firefox on Win7, Linux and Mac
(just checked) and even Windows 7's own file browser menubar.

I don't know if Win10 is different.

> Alternaively I would like to generate a system noise alert that window close is being ignored.

By "window close" do you mean the "X" to close the window, and want to ignore it?
If so, make a callback for the window (which will be called when the "X" is clicked)
and invoke whatever Win10 API call is needed to generate the system sound effect,
then simply return from the callback to prevent the window from closing.

(If you wanted the window to close, you'd just call e.g. exit(0);)

Philip Rose

unread,
Sep 15, 2020, 11:29:10 AM9/15/20
to fltkg...@googlegroups.com

From: Greg Ercolano
Sent: 15 September 2020 16:15
To: fltkg...@googlegroups.com
Subject: Re: [fltk.general] Making a menu_bar submenu close when the menu_barloses focus

Thanks Greg, I catch the “X to close” event normally. I am not seeing it as the menu item has the focus. So I don’t think this will help.

 

Phil

 

Greg Ercolano

unread,
Sep 15, 2020, 11:36:58 AM9/15/20
to fltkg...@googlegroups.com
On 2020-09-15 08:29, 'Philip Rose' via fltk.general wrote:
> Thanks Greg, I catch the “X to close” event normally.
> I am not seeing it as the menu item has the focus. So I don’t think this will help.

Hmm, does the menu stay up when you click outside of it?
That certainly would be bad, otherwise you can't get rid of the menu.

Perhaps the first click is lost to unpost the menu, but a follow up click
should close it.

With firefox on linux, if I have a menu open and glide away from it, hover
over a button and click, the menu unposts, but the button under the mouse
doesn't 'see' the click until I click again.

On the Mac I get different results;

With Audacity (a QT based widget) if I click over a button while a system
submenu is posted, the button under the mouse is ignored until I click again.

But in Firefox if I do the same thing, the button under the mouse does fire
on that first click away from the menu.

I've noticed on macs that if one window is over another, you can click on a
button of the lower window, and seems like sometimes the button fires without
having to first bring the window forward, and othertimes not. Not sure what
that's about either.

pvr...@btinternet.com

unread,
Sep 16, 2020, 9:03:34 AM9/16/20
to fltk.general
On Tuesday, September 15, 2020 at 4:36:58 PM UTC+1 Greg Ercolano wrote:
On 2020-09-15 08:29, 'Philip Rose' via fltk.general wrote:
> Thanks Greg, I catch the “X to close” event normally.
> I am not seeing it as the menu item has the focus. So I don’t think this will help.

Hmm, does the menu stay up when you click outside of it?
That certainly would be bad, otherwise you can't get rid of the menu.

Perhaps the first click is lost to unpost the menu, but a follow up click
should close it.

With firefox on linux, if I have a menu open and glide away from it, hover
over a button and click, the menu unposts, but the button under the mouse
doesn't 'see' the click until I click again.


Thanks Greg and Ian

It's actually quite strange behaviour, which I also see in the menubar demo. If I remain within the main window, then it behaves as you describe. However if I move the mouse out of the main window and try and click the "X" nothing happens. I can click other widgets within the window, but not the widgets in the title-bar (minimise, maximise and close). They do however get highlighted when I pass the mouse over them but do not respond to a click.

With some other apps I've tried (Firefox and Visual Studio), the menu closes as soon as the mouse leaves the main window area, and the title-bar buttons are available for clicking. With another app that I know is Qt-based (WSJT-X), the menu does not close when the mouse leaves the main window but the title-bar widgets respond to the first click by closing the menu and the second click by doing what they should. Curiouser and curiouser, it seems that in two apps I know are FLTK-based (fldigi and flrig) the title bar widgets do respond to clicks after the mouse leaves the main window.

Thanks Phil.


Reply all
Reply to author
Forward
0 new messages