mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 05:52:53 +00:00
WindowServer: Consolidate tiled and maximized window rects calculation
Calculating tiled and miximized window frame have a lot in common. In fact, we can look at maximized window state as a special case of the tile type. It simplifies the code since there is a lot of cases when we take an action only if the window is maximized or tiled.
This commit is contained in:
parent
06e33788ea
commit
53ff271c6f
Notes:
sideshowbarker
2024-07-17 20:58:35 +09:00
Author: https://github.com/obyknovenius
Commit: 53ff271c6f
Pull-request: https://github.com/SerenityOS/serenity/pull/12386
Reviewed-by: https://github.com/thankyouverycool ✅
5 changed files with 91 additions and 164 deletions
|
@ -84,18 +84,16 @@ void WindowFrame::window_was_constructed(Badge<Window>)
|
|||
m_window.handle_window_menu_action(WindowMenuAction::MaximizeOrRestore);
|
||||
});
|
||||
button->on_middle_click = [&](auto&) {
|
||||
auto& window_screen = Screen::closest_to_location(m_window.rect().location());
|
||||
if (m_window.tile_type() == WindowTileType::VerticallyMaximized)
|
||||
m_window.set_untiled();
|
||||
else
|
||||
m_window.set_tiled(&window_screen, WindowTileType::VerticallyMaximized);
|
||||
m_window.set_tiled(WindowTileType::VerticallyMaximized);
|
||||
};
|
||||
button->on_secondary_click = [&](auto&) {
|
||||
auto& window_screen = Screen::closest_to_location(m_window.rect().location());
|
||||
if (m_window.tile_type() == WindowTileType::HorizontallyMaximized)
|
||||
m_window.set_untiled();
|
||||
else
|
||||
m_window.set_tiled(&window_screen, WindowTileType::HorizontallyMaximized);
|
||||
m_window.set_tiled(WindowTileType::HorizontallyMaximized);
|
||||
};
|
||||
m_maximize_button = button.ptr();
|
||||
m_buttons.append(move(button));
|
||||
|
@ -543,7 +541,7 @@ Gfx::IntRect WindowFrame::rect() const
|
|||
|
||||
Gfx::IntRect WindowFrame::constrained_render_rect_to_screen(const Gfx::IntRect& render_rect) const
|
||||
{
|
||||
if (m_window.is_maximized() || m_window.is_tiled())
|
||||
if (m_window.is_tiled())
|
||||
return render_rect.intersected(Screen::closest_to_rect(rect()).rect());
|
||||
return render_rect;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue