From 3474d7c88e88434534384e132bdddc4222cc4925 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 18 Apr 2020 19:56:56 +0100 Subject: [PATCH] WindowServer/LibGUI: Enforce minimum window size --- Libraries/LibGUI/Window.cpp | 8 ++++---- Servers/WindowServer/ClientConnection.cpp | 22 +++++++++++++++++----- Servers/WindowServer/WindowServer.ipc | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp index 87a1e25ab81..ead7ba78fa0 100644 --- a/Libraries/LibGUI/Window.cpp +++ b/Libraries/LibGUI/Window.cpp @@ -167,13 +167,13 @@ void Window::set_rect(const Gfx::Rect& a_rect) m_main_widget->resize(m_rect_when_windowless.size()); return; } - WindowServerConnection::the().send_sync(m_window_id, a_rect); - if (m_back_bitmap && m_back_bitmap->size() != a_rect.size()) + auto window_rect = WindowServerConnection::the().send_sync(m_window_id, a_rect)->rect(); + if (m_back_bitmap && m_back_bitmap->size() != window_rect.size()) m_back_bitmap = nullptr; - if (m_front_bitmap && m_front_bitmap->size() != a_rect.size()) + if (m_front_bitmap && m_front_bitmap->size() != window_rect.size()) m_front_bitmap = nullptr; if (m_main_widget) - m_main_widget->resize(a_rect.size()); + m_main_widget->resize(window_rect.size()); } void Window::set_window_type(WindowType window_type) diff --git a/Servers/WindowServer/ClientConnection.cpp b/Servers/WindowServer/ClientConnection.cpp index 03663d5ff11..9f28a77a879 100644 --- a/Servers/WindowServer/ClientConnection.cpp +++ b/Servers/WindowServer/ClientConnection.cpp @@ -50,6 +50,15 @@ namespace WindowServer { HashMap>* s_connections; +static Gfx::Rect normalize_window_rect(Gfx::Rect rect, WindowType window_type) +{ + auto min_size = 1; + if (window_type == WindowType::Normal) + min_size = 50; + Gfx::Rect normalized_rect = { rect.x(), rect.y(), max(rect.width(), min_size), max(rect.height(), min_size) }; + return normalized_rect; +} + void ClientConnection::for_each_client(Function callback) { if (!s_connections) @@ -388,9 +397,10 @@ OwnPtr ClientConnection::handle(c dbg() << "ClientConnection: Ignoring SetWindowRect request for fullscreen window"; return nullptr; } - window.set_rect(message.rect()); - window.request_update(message.rect()); - return make(); + auto normalized_rect = normalize_window_rect(message.rect(), window.type()); + window.set_rect(normalized_rect); + window.request_update(normalized_rect); + return make(normalized_rect); } OwnPtr ClientConnection::handle(const Messages::WindowServer::GetWindowRect& message) @@ -444,8 +454,10 @@ OwnPtr ClientConnection::handle(co auto window = Window::construct(*this, (WindowType)message.type(), window_id, message.modal(), message.minimizable(), message.resizable(), message.fullscreen()); window->set_has_alpha_channel(message.has_alpha_channel()); window->set_title(message.title()); - if (!message.fullscreen()) - window->set_rect(message.rect()); + if (!message.fullscreen()) { + auto normalized_rect = normalize_window_rect(message.rect(), window->type()); + window->set_rect(normalized_rect); + } if (window->type() == WindowType::Desktop) { window->set_rect(WindowManager::the().desktop_rect()); window->recalculate_rect(); diff --git a/Servers/WindowServer/WindowServer.ipc b/Servers/WindowServer/WindowServer.ipc index a163615ef89..82348778ebc 100644 --- a/Servers/WindowServer/WindowServer.ipc +++ b/Servers/WindowServer/WindowServer.ipc @@ -48,7 +48,7 @@ endpoint WindowServer = 2 SetWindowTitle(i32 window_id, String title) => () GetWindowTitle(i32 window_id) => (String title) - SetWindowRect(i32 window_id, Gfx::Rect rect) => () + SetWindowRect(i32 window_id, Gfx::Rect rect) => (Gfx::Rect rect) GetWindowRect(i32 window_id) => (Gfx::Rect rect) InvalidateRect(i32 window_id, Vector rects, bool ignore_occlusion) =|