1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

WindowServer: Split double-duty Window::normalize_rect()

This commit:
- merges the two(!) places that defined independently the minimum size of a window.
- splits Window::normalize_rect(), which was originally just a function to apply
  the minimum size requirement, and has taken on the additional job of nudging
  windows back onto the desktop.

This inadvertantly fixes a crash that happens when a malicious program creates a
window of size (0, 0). Now, a window at [0,0 50x50] is created instead.
This commit is contained in:
Ben Wiederhake 2021-01-28 22:47:32 +01:00 committed by Andreas Kling
parent 79f534ef12
commit cf586311a6
4 changed files with 30 additions and 24 deletions

View file

@ -176,27 +176,30 @@ void Window::set_rect_without_repaint(const Gfx::IntRect& rect)
m_frame.notify_window_rect_changed(old_rect, rect); // recomputes occlusions
}
void Window::normalize_rect(bool force_titlebar_visible)
void Window::apply_minimum_size(Gfx::IntRect& rect)
{
Gfx::IntSize minimum_size { 1, 1 };
if (type() == WindowType::Normal)
minimum_size = { 50, 50 };
rect.set_width(max(minimum_size.width(), rect.width()));
rect.set_height(max(minimum_size.height(), rect.height()));
}
void Window::nudge_into_desktop(bool force_titlebar_visible)
{
Gfx::IntRect arena = WindowManager::the().arena_rect_for_type(type());
auto min_size = 1;
auto min_visible = 1;
if (type() == WindowType::Normal) {
min_size = 50;
if (type() == WindowType::Normal)
min_visible = 30;
}
// Blow up to the appropriate size.
auto new_width = max(min_size, width());
auto new_height = max(min_size, height());
// Push the frame around such that at least `min_visible` pixels of the *frame* are in the desktop rect.
auto old_frame_rect = frame().rect();
Gfx::IntRect new_frame_rect = {
clamp(old_frame_rect.x(), arena.left() + min_visible - new_width, arena.right() - min_visible),
clamp(old_frame_rect.y(), arena.top() + min_visible - new_height, arena.bottom() - min_visible),
old_frame_rect.width() + new_width - width(),
old_frame_rect.height() + new_height - height(),
clamp(old_frame_rect.x(), arena.left() + min_visible - width(), arena.right() - min_visible),
clamp(old_frame_rect.y(), arena.top() + min_visible - height(), arena.bottom() - min_visible),
old_frame_rect.width(),
old_frame_rect.height(),
};
// Make sure that at least half of the titlebar is visible.
@ -209,8 +212,8 @@ void Window::normalize_rect(bool force_titlebar_visible)
Gfx::IntRect new_window_rect = {
x() + new_frame_rect.x() - old_frame_rect.x(),
y() + new_frame_rect.y() - old_frame_rect.y(),
width() + new_frame_rect.width() - old_frame_rect.width(),
height() + new_frame_rect.height() - old_frame_rect.height(),
width(),
height(),
};
set_rect(new_window_rect);
}