From c7e512852a29ac2ead1e16160cdff82a21ca8ab9 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 23 May 2020 21:39:43 +0100 Subject: [PATCH] Fix escape key event propagation regression from bdf94916 The escape key event shouldn't be propagated after the first tool dispatcher. Propagatint it causes it to go to parent frames, which can mean problems arise (such as in cvpcb, where an escape key press in the fpviewer frame was closing the main cvpcb window when it is propagated). --- common/tool/tool_dispatcher.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 27b626f4b4..3ef788a253 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -411,7 +411,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) bool buttonEvents = false; VECTOR2D pos; OPT evt; - int key = 0; // key = 0 if the event is not a key event + bool keyIsEscape = false; // True if the keypress was the escape key bool keyIsSpecial = false; // True if the key is a special key code int type = aEvent.GetEventType(); @@ -480,7 +480,10 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) } else if( type == wxEVT_CHAR_HOOK || type == wxEVT_CHAR ) { - evt = GetToolEvent( static_cast( &aEvent ), &keyIsSpecial ); + wxKeyEvent* ke = static_cast( &aEvent ); + + keyIsEscape = ( ke->GetKeyCode() == WXK_ESCAPE ); + evt = GetToolEvent( ke, &keyIsSpecial ); } else if( type == wxEVT_MENU_OPEN || type == wxEVT_MENU_CLOSE || type == wxEVT_MENU_HIGHLIGHT ) { @@ -533,9 +536,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) handled = m_toolMgr->ProcessEvent( *evt ); - // ESC is the special key for canceling tools, and is therefore seen as handled - if( key == WXK_ESCAPE ) - handled = true; + wxLogTrace( kicadTraceToolStack, "TOOL_DISPATCHER::DispatchWxEvent - Handled: %s %s", + ( handled ? "true" : "false" ), evt->Format() ); } // pass the event to the GUI, it might still be interested in it @@ -557,8 +559,16 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) // Not handled wxEVT_CHAR must be Skipped (sent to GUI). // Otherwise accelerators and shortcuts in main menu or toolbars are not seen. - if( (type == wxEVT_CHAR || type == wxEVT_CHAR_HOOK) && !keyIsSpecial && !handled ) + // Escape key presses are never skipped by the handler since they correspond to tool cancel + // events, and if they aren't skipped then they are propagated to other frames (which we don't want). + if( (type == wxEVT_CHAR || type == wxEVT_CHAR_HOOK) + && !keyIsSpecial + && !handled + && !keyIsEscape ) aEvent.Skip(); + + wxLogTrace( kicadTraceToolStack, "TOOL_DISPATCHER::DispatchWxEvent - Wx event skipped: %s", + ( aEvent.GetSkipped() ? "true" : "false" ) ); }