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:
Vitaly Dyachkov 2022-02-09 16:26:46 +01:00 committed by Andreas Kling
parent 06e33788ea
commit 53ff271c6f
Notes: sideshowbarker 2024-07-17 20:58:35 +09:00
5 changed files with 91 additions and 164 deletions

View file

@ -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;
}