From 4489f9dbefa4aaff32825d0371e1bf062bd3d91c Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Tue, 16 Aug 2022 06:54:29 -0400 Subject: [PATCH] WindowServer: Add MenuManager helper to find closest open ancestor --- Userland/Services/WindowServer/MenuManager.cpp | 8 ++++++++ Userland/Services/WindowServer/MenuManager.h | 1 + 2 files changed, 9 insertions(+) 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