mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 01:48:11 +00:00
WindowServer: Stop exposing open_menu_stack in MenuManager
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.
This commit is contained in:
parent
238b6871e0
commit
088d7be19c
3 changed files with 7 additions and 8 deletions
|
@ -173,8 +173,8 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
|
||||||
if (handled_menubar_event)
|
if (handled_menubar_event)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!open_menu_stack().is_empty()) {
|
if (has_open_menu()) {
|
||||||
auto* topmost_menu = open_menu_stack().last().ptr();
|
auto* topmost_menu = m_open_menu_stack.last().ptr();
|
||||||
ASSERT(topmost_menu);
|
ASSERT(topmost_menu);
|
||||||
auto* window = topmost_menu->menu_window();
|
auto* window = topmost_menu->menu_window();
|
||||||
ASSERT(window);
|
ASSERT(window);
|
||||||
|
@ -207,7 +207,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse_event.type() == Event::MouseMove) {
|
if (mouse_event.type() == Event::MouseMove) {
|
||||||
for (auto& menu : open_menu_stack()) {
|
for (auto& menu : m_open_menu_stack) {
|
||||||
if (!menu)
|
if (!menu)
|
||||||
continue;
|
continue;
|
||||||
if (!menu->menu_window()->rect().contains(mouse_event.position()))
|
if (!menu->menu_window()->rect().contains(mouse_event.position()))
|
||||||
|
@ -227,7 +227,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
|
||||||
void MenuManager::handle_menu_mouse_event(Menu& menu, const MouseEvent& event)
|
void MenuManager::handle_menu_mouse_event(Menu& menu, const MouseEvent& event)
|
||||||
{
|
{
|
||||||
bool is_hover_with_any_menu_open = event.type() == MouseEvent::MouseMove
|
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());
|
&& (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 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);
|
bool should_open_menu = &menu != m_current_menu && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
|
||||||
|
@ -251,7 +251,7 @@ void MenuManager::set_needs_window_resize()
|
||||||
|
|
||||||
void MenuManager::close_all_menus_from_client(Badge<ClientConnection>, ClientConnection& client)
|
void MenuManager::close_all_menus_from_client(Badge<ClientConnection>, ClientConnection& client)
|
||||||
{
|
{
|
||||||
if (m_open_menu_stack.is_empty())
|
if (!has_open_menu())
|
||||||
return;
|
return;
|
||||||
if (m_open_menu_stack.first()->client() != &client)
|
if (m_open_menu_stack.first()->client() != &client)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -45,8 +45,7 @@ public:
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
bool is_open(const Menu&) const;
|
bool is_open(const Menu&) const;
|
||||||
|
bool has_open_menu() const { return !m_open_menu_stack.is_empty(); }
|
||||||
Vector<WeakPtr<Menu>>& open_menu_stack() { return m_open_menu_stack; }
|
|
||||||
|
|
||||||
Gfx::Rect menubar_rect() const;
|
Gfx::Rect menubar_rect() const;
|
||||||
static int menubar_menu_margin() { return 16; }
|
static int menubar_menu_margin() { return 16; }
|
||||||
|
|
|
@ -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?
|
// 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);
|
MenuManager::the().dispatch_event(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue