From 8d16c7c9b9c5ccdd33768b51e84f7f50972ef086 Mon Sep 17 00:00:00 2001 From: ronak69 Date: Fri, 13 Oct 2023 14:56:32 +0000 Subject: [PATCH] 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. --- .../Services/WindowServer/WindowFrame.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index 71ad99ae68..9909708988 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -986,6 +986,26 @@ void WindowFrame::latch_window_to_screen_edge(ResizeDirection resize_direction) || resize_direction == ResizeDirection::DownLeft) 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); }