From 609391b46e3ccc07dd86fd3c298909dc14e6949a Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Wed, 24 Aug 2022 06:23:25 -0400 Subject: [PATCH] WindowServer: Add modeless_ancestor() helper --- Userland/Services/WindowServer/Window.cpp | 11 +++++++++++ Userland/Services/WindowServer/Window.h | 1 + 2 files changed, 12 insertions(+) diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index b2d14112ed..3c648bcec5 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -989,6 +989,17 @@ void Window::set_parent_window(Window& parent_window) parent_window.add_child_window(*this); } +Window* Window::modeless_ancestor() +{ + if (!is_modal()) + return this; + for (auto parent = m_parent_window; parent; parent = parent->parent_window()) { + if (!parent->is_modal()) + return parent; + } + return nullptr; +} + bool Window::is_accessory() const { if (!m_accessory) diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index bc915aa71a..6a19a51722 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -184,6 +184,7 @@ public: bool is_modal() const; bool is_modal_dont_unparent() const { return m_modal && m_parent_window; } + Window* modeless_ancestor(); Gfx::IntRect rect() const { return m_rect; } void set_rect(Gfx::IntRect const&);