1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +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

@ -37,6 +37,8 @@
namespace WindowServer {
const static Gfx::IntSize s_default_normal_minimum_size = { 50, 50 };
static String default_window_icon_path()
{
return "/res/icons/16x16/window.png";
@ -88,6 +90,10 @@ Window::Window(Core::Object& parent, WindowType type)
, m_icon(default_window_icon())
, m_frame(*this)
{
// Set default minimum size for Normal windows
if (m_type == WindowType::Normal)
m_minimum_size = s_default_normal_minimum_size;
WindowManager::the().add_window(*this);
}
@ -112,6 +118,10 @@ Window::Window(ClientConnection& client, WindowType window_type, int window_id,
m_listens_to_wm_events = true;
}
// Set default minimum size for Normal windows
if (m_type == WindowType::Normal)
m_minimum_size = s_default_normal_minimum_size;
if (parent_window)
set_parent_window(*parent_window);
WindowManager::the().add_window(*this);
@ -176,14 +186,16 @@ void Window::set_rect_without_repaint(const Gfx::IntRect& rect)
m_frame.notify_window_rect_changed(old_rect, rect); // recomputes occlusions
}
void Window::apply_minimum_size(Gfx::IntRect& rect)
bool Window::apply_minimum_size(Gfx::IntRect& rect)
{
Gfx::IntSize minimum_size { 1, 1 };
if (type() == WindowType::Normal)
minimum_size = { 50, 50 };
int new_width = max(m_minimum_size.width(), rect.width());
int new_height = max(m_minimum_size.height(), rect.height());
bool did_size_clamp = new_width != rect.width() || new_height != rect.height();
rect.set_width(max(minimum_size.width(), rect.width()));
rect.set_height(max(minimum_size.height(), rect.height()));
rect.set_width(new_width);
rect.set_height(new_height);
return did_size_clamp;
}
void Window::nudge_into_desktop(bool force_titlebar_visible)
@ -218,6 +230,20 @@ void Window::nudge_into_desktop(bool force_titlebar_visible)
set_rect(new_window_rect);
}
void Window::set_minimum_size(const Gfx::IntSize& size)
{
ASSERT(!size.is_empty());
if (m_minimum_size == size)
return;
// Disallow setting minimum zero widths or heights.
if (size.width() == 0 || size.height() == 0)
return;
m_minimum_size = size;
}
void Window::handle_mouse_event(const MouseEvent& event)
{
set_automatic_cursor_tracking_enabled(event.buttons() != 0);
@ -523,6 +549,11 @@ bool Window::invalidate_no_notify(const Gfx::IntRect& rect, bool with_frame)
return true;
}
void Window::refresh_client_size()
{
client()->post_message(Messages::WindowClient::WindowResized(m_window_id, m_rect));
}
void Window::prepare_dirty_rects()
{
if (m_invalidated_all) {