mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 17:15:26 +00:00
WindowServer: Add WindowStack::window_at() and use it a bunch
This performs a hit test on the window stack to find the window under a given cursor position.
This commit is contained in:
@@ -38,6 +38,14 @@ void WindowStack::move_to_front(Window& window)
|
||||
m_windows.append(window);
|
||||
}
|
||||
|
||||
Window* WindowStack::window_at(Gfx::IntPoint const& position) const
|
||||
{
|
||||
auto result = hit_test(position);
|
||||
if (!result.has_value())
|
||||
return nullptr;
|
||||
return result->window;
|
||||
}
|
||||
|
||||
void WindowStack::set_highlight_window(Window* window)
|
||||
{
|
||||
if (!window)
|
||||
@@ -54,4 +62,16 @@ void WindowStack::set_active_window(Window* window)
|
||||
m_active_window = window->make_weak_ptr<Window>();
|
||||
}
|
||||
|
||||
Optional<HitTestResult> WindowStack::hit_test(Gfx::IntPoint const& position) const
|
||||
{
|
||||
Optional<HitTestResult> result;
|
||||
const_cast<WindowStack*>(this)->for_each_visible_window_from_front_to_back([&](Window& window) {
|
||||
result = window.hit_test(position);
|
||||
if (result.has_value())
|
||||
return IterationDecision::Break;
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user