Attempt to use IsAttached to identify if a menu is a menubar menu

We can't get a mouse position for a menubar menu's event, because the
mouse may be outside our canvas. The original hack to detect menubar
menus may not work fully, and there have been some crashes appearing on
macOS where menubar menus attempted to get mouse position information.

Instead of the hack, try using IsAttached() to detect if the menu is
attached to a menubar, and then gate mouse position access accordingly.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16738
This commit is contained in:
Ian McInerney 2024-01-27 20:59:14 +00:00
parent eacebe63f1
commit 9f66ddb27f
1 changed files with 7 additions and 5 deletions

View File

@ -415,8 +415,8 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
wxMenu* parent = dynamic_cast<wxMenu*>( GetParent() );
// Don't update the position if this menu has a parent
if( !parent && toolMgr )
// Don't update the position if this menu has a parent or is a menubar menu
if( !parent && !IsAttached() && toolMgr )
g_menu_open_position = toolMgr->GetMousePosition();
g_last_menu_highlighted_id = 0;
@ -546,9 +546,11 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
{
evt->SetMousePosition( g_menu_open_position );
}
// Otherwise, if g_last_menu_highlighted_id matches then it's a menubar menu event and has
// no position.
else if( g_last_menu_highlighted_id == aEvent.GetId() )
// Check if it is a menubar event, and don't get any position if it is.
// The original hack is to see if g_last_menu_highlighted_id matches to see if it's a menubar menu event
// IsAttached() checks to see if a menubar was attached to the menu by wx, and if there is one, then the event
// is from a menubar menu.
else if( IsAttached() || ( g_last_menu_highlighted_id == aEvent.GetId() ) )
{
evt->SetHasPosition( false );
}