1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

WindowServer: Make Menus the input window when showing them

This solves a problem where windows don't receive a WindowInputLeft
event when popup menus are opened. This prevented ComboBox being
closed when right clicking the application on the task bar.
This commit is contained in:
Tom 2020-07-15 10:13:13 -06:00 committed by Andreas Kling
parent 59596ff816
commit 8286e72187
8 changed files with 125 additions and 62 deletions

View file

@ -311,7 +311,7 @@ void MenuManager::close_everyone()
}
m_open_menu_stack.clear();
m_current_search.clear();
m_current_menu = nullptr;
clear_current_menu();
refresh();
}
@ -332,7 +332,7 @@ void MenuManager::close_menus(const Vector<Menu*>& menus)
{
for (auto& menu : menus) {
if (menu == m_current_menu)
m_current_menu = nullptr;
clear_current_menu();
if (menu->menu_window())
menu->menu_window()->set_visible(false);
menu->clear_hovered_item();
@ -373,8 +373,11 @@ void MenuManager::toggle_menu(Menu& menu)
void MenuManager::open_menu(Menu& menu, bool as_current_menu)
{
if (is_open(menu)) {
if (as_current_menu)
if (as_current_menu || current_menu() != &menu) {
// This menu is already open. If requested, or if the current
// window doesn't match this one, then set it to this
set_current_menu(&menu);
}
return;
}
@ -390,16 +393,30 @@ void MenuManager::open_menu(Menu& menu, bool as_current_menu)
if (m_open_menu_stack.find([&menu](auto& other) { return &menu == other.ptr(); }).is_end())
m_open_menu_stack.append(menu.make_weak_ptr());
if (as_current_menu)
if (as_current_menu || !current_menu()) {
// Only make this menu the current menu if requested, or if no
// other menu is current
set_current_menu(&menu);
}
refresh();
}
void MenuManager::clear_current_menu()
{
Menu* previous_current_menu = m_current_menu;
m_current_menu = nullptr;
if (previous_current_menu) {
// When closing the last menu, restore the previous active input window
auto& wm = WindowManager::the();
wm.restore_active_input_window(m_previous_input_window);
}
}
void MenuManager::set_current_menu(Menu* menu)
{
if (!menu) {
m_current_menu = nullptr;
clear_current_menu();
return;
}
@ -409,7 +426,17 @@ void MenuManager::set_current_menu(Menu* menu)
}
m_current_search.clear();
Menu* previous_current_menu = m_current_menu;
m_current_menu = menu->make_weak_ptr();
auto& wm = WindowManager::the();
if (!previous_current_menu) {
// When opening the first menu, store the current active input window
m_previous_input_window = wm.active_input_window()->make_weak_ptr();
}
wm.set_active_input_window(m_current_menu->menu_window());
}
void MenuManager::close_bar()