mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +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:
parent
4133caba78
commit
f88361fc28
3 changed files with 27 additions and 21 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue