summaryrefslogtreecommitdiff
path: root/Userland/Services/WindowServer
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2023-04-12 09:19:35 -0600
committerLinus Groh <mail@linusgroh.de>2023-04-13 20:18:49 +0200
commit7795b7bc176c9f131d85cb299ea1b2d54c9bdf2b (patch)
tree3704e21c8066e5dcd898ccd198513c52cc31f3a2 /Userland/Services/WindowServer
parente1077ebbadc9767fbdb320236aba4a3884b59146 (diff)
downloadserenity-7795b7bc176c9f131d85cb299ea1b2d54c9bdf2b.zip
WindowServer: Refactor window geometry overlay rect calculation logic
This moves the ideal overlay rect calculation into its own function.
Diffstat (limited to 'Userland/Services/WindowServer')
-rw-r--r--Userland/Services/WindowServer/Overlays.cpp27
-rw-r--r--Userland/Services/WindowServer/Overlays.h2
2 files changed, 18 insertions, 11 deletions
diff --git a/Userland/Services/WindowServer/Overlays.cpp b/Userland/Services/WindowServer/Overlays.cpp
index 990b1f2468..d2dee23516 100644
--- a/Userland/Services/WindowServer/Overlays.cpp
+++ b/Userland/Services/WindowServer/Overlays.cpp
@@ -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()
{
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 };
- auto rect = calculate_frame_rect(m_label_rect).centered_within(window->frame().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;
+ m_ideal_overlay_rect = calculate_ideal_overlay_rect();
set_actual_rect();
invalidate_content(); // Needed in case the rectangle itself doesn't change, but the contents did.
}
diff --git a/Userland/Services/WindowServer/Overlays.h b/Userland/Services/WindowServer/Overlays.h
index 7aab875359..aae30db077 100644
--- a/Userland/Services/WindowServer/Overlays.h
+++ b/Userland/Services/WindowServer/Overlays.h
@@ -151,6 +151,8 @@ public:
void start_or_stop_move_to_tile_overlay_animation(TileWindowOverlay*);
private:
+ Gfx::IntRect calculate_ideal_overlay_rect() const;
+
WeakPtr<Window> m_window;
DeprecatedString m_label;
Gfx::IntRect m_label_rect;