1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:27:35 +00:00

WindowServer: Resize maximised/tiled windows after resolution change

Previously windows would either extend past the screen or stay at their
previous smaller size in the corner, now they are resized to fit the new
resolution.
This commit is contained in:
Chyza 2020-03-13 22:21:24 +00:00 committed by Andreas Kling
parent 23b1d97b0d
commit 7967c80222
3 changed files with 46 additions and 20 deletions

View file

@ -385,33 +385,37 @@ void Window::set_fullscreen(bool fullscreen)
set_rect(new_window_rect);
}
Gfx::Rect Window::tiled_rect(WindowTileType tiled) const
{
int frame_width = (m_frame.rect().width() - m_rect.width()) / 2;
switch (tiled) {
case WindowTileType::None:
return m_untiled_rect;
case WindowTileType::Left:
return Gfx::Rect(0,
WindowManager::the().maximized_window_rect(*this).y(),
Screen::the().width() / 2 - frame_width,
WindowManager::the().maximized_window_rect(*this).height());
case WindowTileType::Right:
return Gfx::Rect(Screen::the().width() / 2 + frame_width,
WindowManager::the().maximized_window_rect(*this).y(),
Screen::the().width() / 2 - frame_width,
WindowManager::the().maximized_window_rect(*this).height());
default :
ASSERT_NOT_REACHED();
}
}
void Window::set_tiled(WindowTileType tiled)
{
if (m_tiled == tiled)
return;
m_tiled = tiled;
auto old_rect = m_rect;
int frame_width = (m_frame.rect().width() - m_rect.width()) / 2;
switch (tiled) {
case WindowTileType::None:
set_rect(m_untiled_rect);
break;
case WindowTileType::Left:
if (tiled != WindowTileType::None)
m_untiled_rect = m_rect;
set_rect(0,
WindowManager::the().maximized_window_rect(*this).y(),
Screen::the().width() / 2 - frame_width,
WindowManager::the().maximized_window_rect(*this).height());
break;
case WindowTileType::Right:
m_untiled_rect = m_rect;
set_rect(Screen::the().width() / 2 + frame_width,
WindowManager::the().maximized_window_rect(*this).y(),
Screen::the().width() / 2 - frame_width,
WindowManager::the().maximized_window_rect(*this).height());
break;
}
set_rect(tiled_rect(tiled));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(old_rect, m_rect));
}
@ -420,4 +424,17 @@ void Window::detach_client(Badge<ClientConnection>)
m_client = nullptr;
}
void Window::recalculate_rect()
{
if (!is_resizable())
return;
auto old_rect = m_rect;
if (m_tiled != WindowTileType::None)
set_rect(tiled_rect(m_tiled));
else if (is_maximized())
set_rect(WindowManager::the().maximized_window_rect(*this));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(old_rect, m_rect));
}
}

View file

@ -218,6 +218,9 @@ public:
void start_minimize_animation() { m_minimize_animation_step = 0; }
void end_minimize_animation() { m_minimize_animation_step = -1; }
Gfx::Rect tiled_rect(WindowTileType) const;
void recalculate_rect();
// For InlineLinkedList.
// FIXME: Maybe make a ListHashSet and then WindowManager can just use that.
Window* m_next { nullptr };

View file

@ -140,6 +140,12 @@ bool WindowManager::set_resolution(int width, int height)
ClientConnection::for_each_client([&](ClientConnection& client) {
client.notify_about_new_screen_rect(Screen::the().rect());
});
if (success) {
for_each_window([](Window& window) {
window.recalculate_rect();
return IterationDecision::Continue;
});
}
if (m_wm_config) {
if (success) {
dbg() << "Saving resolution: " << Gfx::Size(width, height) << " to config file at " << m_wm_config->file_name();