Skip to content

Commit 7795b7b

Browse files
tomutalinusg
authored andcommitted
WindowServer: Refactor window geometry overlay rect calculation logic
This moves the ideal overlay rect calculation into its own function.
1 parent e1077eb commit 7795b7b

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

Userland/Services/WindowServer/Overlays.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ void WindowGeometryOverlay::start_or_stop_move_to_tile_overlay_animation(TileWin
291291
}
292292
}
293293

294+
Gfx::IntRect WindowGeometryOverlay::calculate_ideal_overlay_rect() const
295+
{
296+
auto rect = calculate_frame_rect(m_label_rect).centered_within(m_window->frame().rect());
297+
auto desktop_rect = WindowManager::the().desktop_rect(ScreenInput::the().cursor_location_screen());
298+
if (rect.left() < desktop_rect.left())
299+
rect.set_left(desktop_rect.left());
300+
if (rect.top() < desktop_rect.top())
301+
rect.set_top(desktop_rect.top());
302+
if (rect.right() > desktop_rect.right())
303+
rect.set_right_without_resize(desktop_rect.right());
304+
if (rect.bottom() > desktop_rect.bottom())
305+
rect.set_bottom_without_resize(desktop_rect.bottom());
306+
return rect;
307+
}
308+
294309
void WindowGeometryOverlay::window_rect_changed()
295310
{
296311
if (auto* window = m_window.ptr()) {
@@ -310,17 +325,7 @@ void WindowGeometryOverlay::window_rect_changed()
310325
}
311326
m_label_rect = Gfx::IntRect { 0, 0, static_cast<int>(ceilf(wm.font().width(m_label))) + 16, wm.font().pixel_size_rounded_up() + 10 };
312327

313-
auto rect = calculate_frame_rect(m_label_rect).centered_within(window->frame().rect());
314-
auto desktop_rect = wm.desktop_rect(ScreenInput::the().cursor_location_screen());
315-
if (rect.left() < desktop_rect.left())
316-
rect.set_left(desktop_rect.left());
317-
if (rect.top() < desktop_rect.top())
318-
rect.set_top(desktop_rect.top());
319-
if (rect.right() > desktop_rect.right())
320-
rect.set_right_without_resize(desktop_rect.right());
321-
if (rect.bottom() > desktop_rect.bottom())
322-
rect.set_bottom_without_resize(desktop_rect.bottom());
323-
m_ideal_overlay_rect = rect;
328+
m_ideal_overlay_rect = calculate_ideal_overlay_rect();
324329
set_actual_rect();
325330
invalidate_content(); // Needed in case the rectangle itself doesn't change, but the contents did.
326331
}

Userland/Services/WindowServer/Overlays.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class WindowGeometryOverlay : public RectangularOverlay {
151151
void start_or_stop_move_to_tile_overlay_animation(TileWindowOverlay*);
152152

153153
private:
154+
Gfx::IntRect calculate_ideal_overlay_rect() const;
155+
154156
WeakPtr<Window> m_window;
155157
DeprecatedString m_label;
156158
Gfx::IntRect m_label_rect;

0 commit comments

Comments
 (0)