mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
WindowServer: Refactor window geometry overlay rect calculation logic
This moves the ideal overlay rect calculation into its own function.
This commit is contained in:
parent
e1077ebbad
commit
7795b7bc17
2 changed files with 18 additions and 11 deletions
|
@ -291,6 +291,21 @@ void WindowGeometryOverlay::start_or_stop_move_to_tile_overlay_animation(TileWin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gfx::IntRect WindowGeometryOverlay::calculate_ideal_overlay_rect() const
|
||||||
|
{
|
||||||
|
auto rect = calculate_frame_rect(m_label_rect).centered_within(m_window->frame().rect());
|
||||||
|
auto desktop_rect = WindowManager::the().desktop_rect(ScreenInput::the().cursor_location_screen());
|
||||||
|
if (rect.left() < desktop_rect.left())
|
||||||
|
rect.set_left(desktop_rect.left());
|
||||||
|
if (rect.top() < desktop_rect.top())
|
||||||
|
rect.set_top(desktop_rect.top());
|
||||||
|
if (rect.right() > desktop_rect.right())
|
||||||
|
rect.set_right_without_resize(desktop_rect.right());
|
||||||
|
if (rect.bottom() > desktop_rect.bottom())
|
||||||
|
rect.set_bottom_without_resize(desktop_rect.bottom());
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
void WindowGeometryOverlay::window_rect_changed()
|
void WindowGeometryOverlay::window_rect_changed()
|
||||||
{
|
{
|
||||||
if (auto* window = m_window.ptr()) {
|
if (auto* window = m_window.ptr()) {
|
||||||
|
@ -310,17 +325,7 @@ void WindowGeometryOverlay::window_rect_changed()
|
||||||
}
|
}
|
||||||
m_label_rect = Gfx::IntRect { 0, 0, static_cast<int>(ceilf(wm.font().width(m_label))) + 16, wm.font().pixel_size_rounded_up() + 10 };
|
m_label_rect = Gfx::IntRect { 0, 0, static_cast<int>(ceilf(wm.font().width(m_label))) + 16, wm.font().pixel_size_rounded_up() + 10 };
|
||||||
|
|
||||||
auto rect = calculate_frame_rect(m_label_rect).centered_within(window->frame().rect());
|
m_ideal_overlay_rect = calculate_ideal_overlay_rect();
|
||||||
auto desktop_rect = wm.desktop_rect(ScreenInput::the().cursor_location_screen());
|
|
||||||
if (rect.left() < desktop_rect.left())
|
|
||||||
rect.set_left(desktop_rect.left());
|
|
||||||
if (rect.top() < desktop_rect.top())
|
|
||||||
rect.set_top(desktop_rect.top());
|
|
||||||
if (rect.right() > desktop_rect.right())
|
|
||||||
rect.set_right_without_resize(desktop_rect.right());
|
|
||||||
if (rect.bottom() > desktop_rect.bottom())
|
|
||||||
rect.set_bottom_without_resize(desktop_rect.bottom());
|
|
||||||
m_ideal_overlay_rect = rect;
|
|
||||||
set_actual_rect();
|
set_actual_rect();
|
||||||
invalidate_content(); // Needed in case the rectangle itself doesn't change, but the contents did.
|
invalidate_content(); // Needed in case the rectangle itself doesn't change, but the contents did.
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,8 @@ public:
|
||||||
void start_or_stop_move_to_tile_overlay_animation(TileWindowOverlay*);
|
void start_or_stop_move_to_tile_overlay_animation(TileWindowOverlay*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Gfx::IntRect calculate_ideal_overlay_rect() const;
|
||||||
|
|
||||||
WeakPtr<Window> m_window;
|
WeakPtr<Window> m_window;
|
||||||
DeprecatedString m_label;
|
DeprecatedString m_label;
|
||||||
Gfx::IntRect m_label_rect;
|
Gfx::IntRect m_label_rect;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue