From 906417cc0d8edb6194996973930e7b88971028e8 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 22 Oct 2023 15:31:42 +0200 Subject: [PATCH] GUI: Autofocus newly opened GUIModalMenu instances (#13911) This in particular fixes incorrect event propagation to menus that are no longer shown, such as the key change menu when opened within the settings tab. --- src/gui/guiChatConsole.cpp | 1 - src/gui/mainmenumanager.h | 5 ++++- src/gui/modalMenu.cpp | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index 219a4b4f9..36982b20e 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -114,7 +114,6 @@ void GUIChatConsole::openConsole(f32 scale) reformatConsole(); m_animate_time_old = porting::getTimeMs(); IGUIElement::setVisible(true); - Environment->setFocus(this); m_menumgr->createdMenu(this); } diff --git a/src/gui/mainmenumanager.h b/src/gui/mainmenumanager.h index 76d357340..4ba420a75 100644 --- a/src/gui/mainmenumanager.h +++ b/src/gui/mainmenumanager.h @@ -57,6 +57,7 @@ public: if(!m_stack.empty()) m_stack.back()->setVisible(false); m_stack.push_back(menu); + guienv->setFocus(m_stack.back()); } virtual void deletingMenu(gui::IGUIElement *menu) @@ -64,8 +65,10 @@ public: // Remove all entries if there are duplicates m_stack.remove(menu); - if(!m_stack.empty()) + if(!m_stack.empty()) { m_stack.back()->setVisible(true); + guienv->setFocus(m_stack.back()); + } } // Returns true to prevent further processing diff --git a/src/gui/modalMenu.cpp b/src/gui/modalMenu.cpp index 9f5258cdf..c231f1e72 100644 --- a/src/gui/modalMenu.cpp +++ b/src/gui/modalMenu.cpp @@ -49,7 +49,6 @@ GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, #endif setVisible(true); - Environment->setFocus(this); m_menumgr->createdMenu(this); m_doubleclickdetect[0].time = 0;