From 096da3e59f14105dbd8ab0312daa2c615382ee07 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 22 Nov 2023 19:09:20 +0000 Subject: [PATCH] Fix #11407: Don't steal focus from dropdown menus. (#11484) --- src/window.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index b05615ab2c..409aa602bb 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1393,10 +1393,11 @@ void Window::InitializeData(WindowNumber window_number) this->resize.step_width = this->nested_root->resize_x; this->resize.step_height = this->nested_root->resize_y; - /* Give focus to the opened window unless a text box - * of focused window has focus (so we don't interrupt typing). But if the new - * window has a text box, then take focus anyway. */ - if (!EditBoxInGlobalFocus() || this->nested_root->GetWidgetOfType(WWT_EDITBOX) != nullptr) SetFocusedWindow(this); + /* Give focus to the opened window unless a dropdown menu has focus or a text box of the focused window has focus + * (so we don't interrupt typing) unless the new window has a text box. */ + bool dropdown_active = _focused_window != nullptr && _focused_window->window_class == WC_DROPDOWN_MENU; + bool editbox_active = EditBoxInGlobalFocus() && this->nested_root->GetWidgetOfType(WWT_EDITBOX) == nullptr; + if (!dropdown_active && !editbox_active) SetFocusedWindow(this); /* Insert the window into the correct location in the z-ordering. */ BringWindowToFront(this, false);