← Back to team overview

kicad-developers team mailing list archive

Strange behavior of draw panel gal focus.

 

Hi Orson,

Could you have a look into this patch?

It fixes (this it only a workaround) a very strange behavior of focus, for the draw panel GAL.
Sometimes the draw panel do not have the focus (and moreover do not accept the focus) on W7 32 bits.

It happens when 2 EDA_FRAME are opened, for instance the board editor and the footprint viewer.

When the 2 frame are shown on screen, no problem.
But if you iconize one frame (for instance the footprint viewer) the remaining frame does not
receive some events (key events and mousewheel event).

I had a look into this strange behavior and found 2 problems:
1 - When happens, the wxWindow::FindFocus() method returns nullptr (that explains why some events
are no longer received)
2 - And the active draw panel gal does not accept the focus (SetFocus() do nothing). Only the main
Draw Frame accepts SetFocus().

This small patch gives the Focus to the main Draw Frame when wxWindow::FindFocus() method returns
nullptr.

More strange:
The first time the footprint viewer is iconized, the focus is lost.
but if you raise and iconize the footprint viewer, the focus is OK.

In short when iconizing n times the footprint viewer, if n is odd, the focus is lost, and if n is
even, the focus is OK.

I also noticed (when reading the tool_dispatcher.cpp source) there is a similar focus issue on OSX.

Perhaps my workaround also fixes this OSX issue.

Thanks.

-- 
Jean-Pierre CHARRAS
 common/tool/tool_dispatcher.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp
index 5c9113f..f45fb01 100644
--- a/common/tool/tool_dispatcher.cpp
+++ b/common/tool/tool_dispatcher.cpp
@@ -313,6 +313,13 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
 
     int type = aEvent.GetEventType();
 
+    // Sometimes there is no window that has the focus (it happens when an other PCB_BASE_FRAME
+    // is opened and is iconized on Windows).
+    // In this case, gives the focus to the parent PCB_BASE_FRAME (for an obscure reason,
+    // when happens, the GAL canvas itself does not accept the focus)
+    if( wxWindow::FindFocus() == nullptr )
+        static_cast<PCB_BASE_FRAME*>( m_toolMgr->GetEditFrame() )->SetFocus();
+
     // Mouse handling
     // Note: wxEVT_LEFT_DOWN event must always be skipped.
     if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL ||

Follow ups