1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00:00

WindowServer, LibGUI: Variable minimum window sizes

Minimum window size can now be customised and set at runtime via the
SetWindowMinimumSize WindowServer message and the set_minimum_size
LibGUI::Window method. The default minimum size remains at 50x50.

Some behind-the-scenes mechanics had to be added to LibGUI::Window to
ensure that the minimum size is remembered if set before the window is
shown. WindowServer sends a resize event to the client if it requests a
size on create that's smaller than it's minimum size.
This commit is contained in:
Nick Vella 2021-02-16 00:59:43 +11:00 committed by Andreas Kling
parent dea0d22ab3
commit 15c1f7a40d
7 changed files with 130 additions and 8 deletions

View file

@ -413,6 +413,48 @@ OwnPtr<Messages::WindowServer::GetWindowRectResponse> ClientConnection::handle(c
return make<Messages::WindowServer::GetWindowRectResponse>(it->value->rect());
}
OwnPtr<Messages::WindowServer::SetWindowMinimumSizeResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowMinimumSize& message)
{
int window_id = message.window_id();
auto it = m_windows.find(window_id);
if (it == m_windows.end()) {
did_misbehave("SetWindowMinimumSize: Bad window ID");
return {};
}
auto& window = *(*it).value;
if (window.is_fullscreen()) {
dbgln("ClientConnection: Ignoring SetWindowMinimumSize request for fullscreen window");
return {};
}
window.set_minimum_size(message.size());
if (window.width() < window.minimum_size().width() || window.height() < window.minimum_size().height()) {
// New minimum size is larger than the current window size, resize accordingly.
auto new_rect = window.rect();
bool did_size_clamp = window.apply_minimum_size(new_rect);
window.set_rect(new_rect);
window.nudge_into_desktop();
window.request_update(window.rect());
if (did_size_clamp)
window.refresh_client_size();
}
return make<Messages::WindowServer::SetWindowMinimumSizeResponse>();
}
OwnPtr<Messages::WindowServer::GetWindowMinimumSizeResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowMinimumSize& message)
{
int window_id = message.window_id();
auto it = m_windows.find(window_id);
if (it == m_windows.end()) {
did_misbehave("GetWindowMinimumSize: Bad window ID");
return {};
}
return make<Messages::WindowServer::GetWindowMinimumSizeResponse>(it->value->minimum_size());
}
OwnPtr<Messages::WindowServer::GetWindowRectInMenubarResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowRectInMenubar& message)
{
int window_id = message.window_id();
@ -454,9 +496,13 @@ OwnPtr<Messages::WindowServer::CreateWindowResponse> ClientConnection::handle(co
rect = { WindowManager::the().get_recommended_window_position({ 100, 100 }), message.rect().size() };
window->set_default_positioned(true);
}
window->apply_minimum_size(rect);
window->set_minimum_size(message.minimum_size());
bool did_size_clamp = window->apply_minimum_size(rect);
window->set_rect(rect);
window->nudge_into_desktop();
if (did_size_clamp)
window->refresh_client_size();
}
if (window->type() == WindowType::Desktop) {
window->set_rect(WindowManager::the().desktop_rect());