From 4059f24cf5e6ba8eb5bed80bcb5db7ae8c41959b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 24 Jul 2018 01:36:37 +0200 Subject: [PATCH] Reset pending focus when losing focus in wxGTK It could happen that the window remained as the global "pending focus" even after it lost its focus, resulting in FindFocus() still returning it as the currently focused window, even though it didn't have focus any more. This notably broke focus logic of wxCompositeWindow and could result in missing wxEVT_KILL_FOCUS for windows using it, such as wxDatePickerCtrl, and quite likely was responsible for other focus problems in wxGTK as well. --- src/gtk/window.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 866eb2905f..9f17f19ebe 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -4374,7 +4374,13 @@ bool wxWindowGTK::GTKHandleFocusIn() gtk_im_context_focus_in(m_imContext); gs_currentFocus = this; - gs_pendingFocus = NULL; + + if ( gs_pendingFocus ) + { + wxLogTrace(TRACE_FOCUS, "Resetting pending focus %s on focus set", + wxDumpWindow(gs_pendingFocus)); + gs_pendingFocus = NULL; + } #if wxUSE_CARET // caret needs to be informed about focus change @@ -4406,6 +4412,15 @@ bool wxWindowGTK::GTKHandleFocusOut() // handler issues a repaint const bool retval = m_wxwindow ? true : false; + // If this window is still the pending focus one, reset that pointer as + // we're not going to have focus any longer and DoFindFocus() must not + // return this window. + if ( gs_pendingFocus == this ) + { + wxLogTrace(TRACE_FOCUS, "Resetting pending focus %s on focus loss", + wxDumpWindow(this)); + gs_pendingFocus = NULL; + } // NB: If a control is composed of several GtkWidgets and when focus // changes from one of them to another within the same wxWindow, we get