Skip to content

Commit

Permalink
WindowServer: Stop exposing open_menu_stack in MenuManager
Browse files Browse the repository at this point in the history
The open menu stack is an internal data structure that outside classes
shouldn't really need to know about. Add MenuManager::has_open_menu()
so that the WindowManager can still know whether a menu is open or not.
  • Loading branch information
shannonbooth authored and awesomekling committed Feb 20, 2020
1 parent 238b687 commit 088d7be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Servers/WindowServer/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
if (handled_menubar_event)
return;

if (!open_menu_stack().is_empty()) {
auto* topmost_menu = open_menu_stack().last().ptr();
if (has_open_menu()) {
auto* topmost_menu = m_open_menu_stack.last().ptr();
ASSERT(topmost_menu);
auto* window = topmost_menu->menu_window();
ASSERT(window);
Expand Down Expand Up @@ -207,7 +207,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
}

if (mouse_event.type() == Event::MouseMove) {
for (auto& menu : open_menu_stack()) {
for (auto& menu : m_open_menu_stack) {
if (!menu)
continue;
if (!menu->menu_window()->rect().contains(mouse_event.position()))
Expand All @@ -227,7 +227,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
void MenuManager::handle_menu_mouse_event(Menu& menu, const MouseEvent& event)
{
bool is_hover_with_any_menu_open = event.type() == MouseEvent::MouseMove
&& !m_open_menu_stack.is_empty()
&& has_open_menu()
&& (m_open_menu_stack.first()->menubar() || m_open_menu_stack.first() == m_system_menu.ptr());
bool is_mousedown_with_left_button = event.type() == MouseEvent::MouseDown && event.button() == MouseButton::Left;
bool should_open_menu = &menu != m_current_menu && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
Expand All @@ -251,7 +251,7 @@ void MenuManager::set_needs_window_resize()

void MenuManager::close_all_menus_from_client(Badge<ClientConnection>, ClientConnection& client)
{
if (m_open_menu_stack.is_empty())
if (!has_open_menu())
return;
if (m_open_menu_stack.first()->client() != &client)
return;
Expand Down
3 changes: 1 addition & 2 deletions Servers/WindowServer/MenuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class MenuManager final : public Core::Object {
void refresh();

bool is_open(const Menu&) const;

Vector<WeakPtr<Menu>>& open_menu_stack() { return m_open_menu_stack; }
bool has_open_menu() const { return !m_open_menu_stack.is_empty(); }

Gfx::Rect menubar_rect() const;
static int menubar_menu_margin() { return 16; }
Expand Down
2 changes: 1 addition & 1 deletion Servers/WindowServer/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_wind
}

// FIXME: Now that the menubar has a dedicated window, is this special-casing really necessary?
if (!MenuManager::the().open_menu_stack().is_empty() || (!active_window_is_modal() && menubar_rect().contains(event.position()))) {
if (MenuManager::the().has_open_menu() || (!active_window_is_modal() && menubar_rect().contains(event.position()))) {
MenuManager::the().dispatch_event(event);
return;
}
Expand Down

0 comments on commit 088d7be

Please sign in to comment.