1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:37:44 +00:00

WindowServer: Count titlebar towards visible/grabbable area

This had lead to some surprising asymmetry at the bottom of the screen.
This commit is contained in:
Ben Wiederhake 2021-01-28 20:53:59 +01:00 committed by Andreas Kling
parent 3fd5aec187
commit e200824125

View file

@ -178,28 +178,41 @@ void Window::set_rect_without_repaint(const Gfx::IntRect& rect)
void Window::normalize_rect() void Window::normalize_rect()
{ {
Gfx::IntRect arena = WindowManager::the().arena_rect_for_type(type());
auto min_size = 1; auto min_size = 1;
// Must be -1 to allow windows just outside the desktop rect. auto min_visible = 1;
// For example, the windows that make the desktop rect smaller
// than the display resolution (e.g. the TaskBar).
auto min_visible = -1;
auto desktop = WindowManager::the().arena_rect_for_type(type())
auto min_y = 0;
if (type() == WindowType::Normal) { if (type() == WindowType::Normal) {
min_size = 50; min_size = 50;
min_visible = 50; min_visible = 30;
// 5 pixels is the amount of frame decoration that can be sacrificed before starting to become an issue.
min_y = desktop.top() - 5;
} }
auto new_width = max(width(), min_size);
auto new_height = max(height(), min_size); // Blow up to the appropriate size.
Gfx::IntRect normalized_rect = { auto new_width = max(min_size, width());
clamp(x(), -new_width + min_visible, desktop.width() - min_visible), auto new_height = max(min_size, height());
clamp(y(), min_y, desktop.bottom() - min_visible),
new_width, // Push the frame around such that at least `min_visible` pixels of the *frame* are in the desktop rect.
new_height, 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(),
}; };
set_rect(normalized_rect);
// Make sure that at least half of the titlebar is visible.
auto min_frame_y = arena.top() - (y() - old_frame_rect.y()) / 2;
if (new_frame_rect.y() < min_frame_y) {
new_frame_rect.set_y(min_frame_y);
}
// Deduce new window rect:
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(),
};
set_rect(new_window_rect);
} }
void Window::handle_mouse_event(const MouseEvent& event) void Window::handle_mouse_event(const MouseEvent& event)