1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 11:04:59 +00:00

WindowServer: Handle latching fix-aspect-ratio window to the screen edge

Double-clicking the edges of a window results in the edge being extended
until it latches to the screen edge. This used to violate the fixed
aspect ratio property of certain windows because of only extending the
window in one dimension.

This commit adds a special case to the latching logic that makes sure to
also extend the other dimension of the window such that the fixed aspect
ratio is maintained.
This commit is contained in:
ronak69 2023-10-13 14:56:32 +00:00 committed by Sam Atkins
parent e09245badd
commit 8d16c7c9b9

View file

@ -986,6 +986,26 @@ void WindowFrame::latch_window_to_screen_edge(ResizeDirection resize_direction)
|| resize_direction == ResizeDirection::DownLeft) || resize_direction == ResizeDirection::DownLeft)
window_rect.inflate(0, 0, 0, frame_rect.left() - screen_rect.left()); window_rect.inflate(0, 0, 0, frame_rect.left() - screen_rect.left());
// If required, maintain fixed aspect ratio by scaling the other dimension appropriately
if (m_window.resize_aspect_ratio().has_value()) {
auto& ratio = m_window.resize_aspect_ratio().value();
if (window_rect.width() == m_window.rect().width()) {
// Up or Down
window_rect.set_width(window_rect.height() * ratio.width() / ratio.height());
} else {
// Left, Right, UpLeft, UpRight, DownLeft or DownRight
window_rect.set_height(window_rect.width() * ratio.height() / ratio.width());
// Match bottom corner of the frame and the screen
if (resize_direction == ResizeDirection::DownLeft
|| resize_direction == ResizeDirection::DownRight) {
auto new_frame_rect = frame_rect_for_window(m_window, window_rect);
window_rect.translate_by(0, screen_rect.bottom() - new_frame_rect.bottom());
}
}
}
m_window.set_rect(window_rect); m_window.set_rect(window_rect);
} }