diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-08-16 06:54:29 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-16 16:52:09 +0200 |
commit | 4489f9dbefa4aaff32825d0371e1bf062bd3d91c (patch) | |
tree | 86e4b770e88a3e47badc93b4ab10dbf0d762f54e /Userland/Services | |
parent | db852548ce212c764266a0bf6910ec15c9992539 (diff) | |
download | serenity-4489f9dbefa4aaff32825d0371e1bf062bd3d91c.zip |
WindowServer: Add MenuManager helper to find closest open ancestor
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WindowServer/MenuManager.cpp | 8 | ||||
-rw-r--r-- | Userland/Services/WindowServer/MenuManager.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Services/WindowServer/MenuManager.cpp b/Userland/Services/WindowServer/MenuManager.cpp index 3a882c7b46..ad0e8543aa 100644 --- a/Userland/Services/WindowServer/MenuManager.cpp +++ b/Userland/Services/WindowServer/MenuManager.cpp @@ -229,6 +229,14 @@ void MenuManager::close_everyone() clear_current_menu(); } +Menu* MenuManager::closest_open_ancestor_of(Menu const& other) const +{ + for (auto& menu : m_open_menu_stack.in_reverse()) + if (menu->is_menu_ancestor_of(other)) + return menu.ptr(); + return nullptr; +} + void MenuManager::close_everyone_not_in_lineage(Menu& menu) { Vector<Menu&> menus_to_close; diff --git a/Userland/Services/WindowServer/MenuManager.h b/Userland/Services/WindowServer/MenuManager.h index 90312238e5..77d214c852 100644 --- a/Userland/Services/WindowServer/MenuManager.h +++ b/Userland/Services/WindowServer/MenuManager.h @@ -26,6 +26,7 @@ public: bool has_open_menu() const { return !m_open_menu_stack.is_empty(); } Menu* current_menu() { return m_current_menu.ptr(); } + Menu* closest_open_ancestor_of(Menu const&) const; void set_current_menu(Menu*); void clear_current_menu(); void open_menu(Menu&, bool as_current_menu = true); |