WindowManager: Simplify menu bar open/close logic

Let the global menu bar be either "open" or "closed". Clicking on one
of the menus in the menu bar toggles the state.

This ends up simpler and more intuitive than what we had before.
This commit is contained in:
Andreas Kling 2019-11-11 12:54:23 +01:00
parent cbecad0a77
commit 5e61fd0e67
4 changed files with 18 additions and 8 deletions

View file

@ -242,7 +242,7 @@ void WSMenu::did_activate(WSMenuItem& item)
if (on_item_activation)
on_item_activation(item);
WSWindowManager::the().menu_manager().close_everyone();
WSWindowManager::the().menu_manager().close_bar();
WSAPI_ServerMessage message;
message.type = WSAPI_ServerMessage::Type::MenuItemActivated;

View file

@ -145,7 +145,10 @@ void WSMenuManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& ev
bool is_mousedown_with_left_button = event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left;
bool should_open_menu = &menu != m_current_menu && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
if (should_open_menu) {
if (is_mousedown_with_left_button)
m_bar_open = !m_bar_open;
if (should_open_menu && m_bar_open) {
if (m_current_menu == &menu)
return;
close_everyone();
@ -158,11 +161,9 @@ void WSMenuManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& ev
refresh();
return;
}
if (event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left) {
if (!m_bar_open)
close_everyone();
set_current_menu(nullptr);
return;
}
}
void WSMenuManager::set_needs_window_resize()
@ -177,6 +178,7 @@ void WSMenuManager::close_everyone()
menu->menu_window()->set_visible(false);
}
m_open_menu_stack.clear();
m_current_menu = nullptr;
refresh();
}
@ -240,3 +242,9 @@ void WSMenuManager::set_current_menu(WSMenu* menu, bool is_submenu)
m_open_menu_stack.append(menu->make_weak_ptr());
}
}
void WSMenuManager::close_bar()
{
close_everyone();
m_bar_open = false;
}

View file

@ -26,6 +26,7 @@ public:
WSMenu* current_menu() { return m_current_menu.ptr(); }
void set_current_menu(WSMenu*, bool is_submenu = false);
void close_bar();
void close_everyone();
void close_everyone_not_in_lineage(WSMenu&);
void close_menu_and_descendants(WSMenu&);
@ -49,5 +50,6 @@ private:
WeakPtr<WSMenu> m_current_menu;
Vector<WeakPtr<WSMenu>> m_open_menu_stack;
bool m_needs_window_resize;
bool m_needs_window_resize { false };
bool m_bar_open { false };
};

View file

@ -731,7 +731,7 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& hovere
if (topmost_menu->hovered_item())
topmost_menu->clear_hovered_item();
if (event.type() == WSEvent::MouseDown || event.type() == WSEvent::MouseUp)
m_menu_manager.close_everyone();
m_menu_manager.close_bar();
if (event.type() == WSEvent::MouseMove) {
for (auto& menu : m_menu_manager.open_menu_stack()) {
if (!menu)