From 44a75afe9318ce43e3034f40992c76a68dbe3360 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 21 Jul 2020 08:44:57 -0700 Subject: [PATCH] Make sure toplevel is active in SetFocus(), episode 2 Toplevel must be active for child to actually receive focus See #18783 --- src/gtk/window.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 412702ef29..e0345ada38 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -4583,6 +4583,13 @@ void wxWindowGTK::SetFocus() if (gs_currentFocus != this) gs_pendingFocus = this; + // Toplevel must be active for child to actually receive focus. + // But avoid activating if tlw is not yet shown, as that will + // cause it to be immediately shown. + GtkWidget* tlw = gtk_widget_get_ancestor(m_widget, GTK_TYPE_WINDOW); + if (tlw && gtk_widget_get_visible(tlw) && !gtk_window_is_active(GTK_WINDOW(tlw))) + gtk_window_present(GTK_WINDOW(tlw)); + GtkWidget *widget = m_wxwindow ? m_wxwindow : m_focusWidget; if ( GTK_IS_CONTAINER(widget) &&