mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibGUI+WindowServer: Initialize minimum window size to zero
And remove unnecessary workarounds to the old limit of {50, 50} and the cautious but arbitrary limit of {1, 1} for other WindowTypes. Null rects are already the default when calculating minimum window size and are the least restrictive but valid value. Also returns early during minimum size calculations for frameless windows, and verifies against negative minimum sizes and failure to disable widget min size before setting a minimum window size. Layout automatically overrides this setting each relayout otherwise.
This commit is contained in:
parent
8b8cee3172
commit
46d6347035
Notes:
sideshowbarker
2024-07-17 07:47:40 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/46d6347035 Pull-request: https://github.com/SerenityOS/serenity/pull/15009 Issue: https://github.com/SerenityOS/serenity/issues/10970 Issue: https://github.com/SerenityOS/serenity/issues/13036
5 changed files with 14 additions and 33 deletions
|
@ -70,7 +70,7 @@ Window::Window(Core::Object* parent)
|
|||
, m_menubar(Menubar::construct())
|
||||
{
|
||||
all_windows->set(this);
|
||||
m_rect_when_windowless = { -5000, -5000, 140, 140 };
|
||||
m_rect_when_windowless = { -5000, -5000, 0, 0 };
|
||||
m_title_when_windowless = "GUI::Window";
|
||||
|
||||
register_property(
|
||||
|
@ -289,7 +289,8 @@ Gfx::IntSize Window::minimum_size() const
|
|||
|
||||
void Window::set_minimum_size(Gfx::IntSize const& size)
|
||||
{
|
||||
m_minimum_size_modified = true;
|
||||
VERIFY(size.width() >= 0 && size.height() >= 0);
|
||||
VERIFY(!is_obeying_widget_min_size());
|
||||
m_minimum_size_when_windowless = size;
|
||||
|
||||
if (is_visible())
|
||||
|
@ -311,14 +312,6 @@ void Window::center_within(Window const& other)
|
|||
void Window::set_window_type(WindowType window_type)
|
||||
{
|
||||
m_window_type = window_type;
|
||||
|
||||
if (!m_minimum_size_modified) {
|
||||
// Apply minimum size defaults.
|
||||
if (m_window_type == WindowType::Normal || m_window_type == WindowType::ToolWindow)
|
||||
m_minimum_size_when_windowless = { 50, 50 };
|
||||
else
|
||||
m_minimum_size_when_windowless = { 1, 1 };
|
||||
}
|
||||
}
|
||||
|
||||
void Window::make_window_manager(unsigned event_mask)
|
||||
|
@ -1044,7 +1037,10 @@ void Window::update_min_size()
|
|||
main_widget()->do_layout();
|
||||
if (m_obey_widget_min_size) {
|
||||
auto min_size = main_widget()->effective_min_size();
|
||||
set_minimum_size(MUST(min_size.width().shrink_value()), MUST(min_size.height().shrink_value()));
|
||||
Gfx::IntSize size = { MUST(min_size.width().shrink_value()), MUST(min_size.height().shrink_value()) };
|
||||
m_minimum_size_when_windowless = size;
|
||||
if (is_visible())
|
||||
ConnectionToWindowServer::the().async_set_window_minimum_size(m_window_id, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -278,8 +278,7 @@ private:
|
|||
WeakPtr<Widget> m_automatic_cursor_tracking_widget;
|
||||
WeakPtr<Widget> m_hovered_widget;
|
||||
Gfx::IntRect m_rect_when_windowless;
|
||||
Gfx::IntSize m_minimum_size_when_windowless { 50, 50 };
|
||||
bool m_minimum_size_modified { false };
|
||||
Gfx::IntSize m_minimum_size_when_windowless { 0, 0 };
|
||||
String m_title_when_windowless;
|
||||
Vector<Gfx::IntRect, 32> m_pending_paint_event_rects;
|
||||
Gfx::IntSize m_size_increment;
|
||||
|
|
|
@ -470,6 +470,9 @@ Messages::WindowServer::GetWindowRectResponse ConnectionFromClient::get_window_r
|
|||
|
||||
static Gfx::IntSize calculate_minimum_size_for_window(Window const& window)
|
||||
{
|
||||
if (window.is_frameless())
|
||||
return { 0, 0 };
|
||||
|
||||
// NOTE: Windows with a title bar have a minimum size enforced by the system,
|
||||
// because we want to always keep their title buttons accessible.
|
||||
if (window.type() == WindowType::Normal || window.type() == WindowType::ToolWindow) {
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
namespace WindowServer {
|
||||
|
||||
static constexpr Gfx::IntSize s_default_normal_minimum_size = { 50, 50 };
|
||||
|
||||
static String default_window_icon_path()
|
||||
{
|
||||
return "/res/icons/16x16/window.png";
|
||||
|
@ -88,10 +86,6 @@ 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);
|
||||
frame().window_was_constructed({});
|
||||
}
|
||||
|
@ -112,10 +106,6 @@ Window::Window(ConnectionFromClient& client, WindowType window_type, int window_
|
|||
, 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;
|
||||
|
||||
if (parent_window)
|
||||
set_parent_window(*parent_window);
|
||||
WindowManager::the().add_window(*this);
|
||||
|
@ -169,7 +159,7 @@ void Window::set_rect(Gfx::IntRect const& rect)
|
|||
|
||||
void Window::set_rect_without_repaint(Gfx::IntRect const& rect)
|
||||
{
|
||||
VERIFY(!rect.is_empty());
|
||||
VERIFY(rect.width() >= 0 && rect.height() >= 0);
|
||||
if (m_rect == rect)
|
||||
return;
|
||||
auto old_rect = m_rect;
|
||||
|
@ -248,16 +238,9 @@ void Window::nudge_into_desktop(Screen* target_screen, bool force_titlebar_visib
|
|||
|
||||
void Window::set_minimum_size(Gfx::IntSize const& size)
|
||||
{
|
||||
if (size.is_null())
|
||||
return;
|
||||
|
||||
VERIFY(size.width() >= 0 && size.height() >= 0);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -450,7 +450,7 @@ private:
|
|||
float m_alpha_hit_threshold { 0.0f };
|
||||
Gfx::IntSize m_size_increment;
|
||||
Gfx::IntSize m_base_size;
|
||||
Gfx::IntSize m_minimum_size { 1, 1 };
|
||||
Gfx::IntSize m_minimum_size { 0, 0 };
|
||||
NonnullRefPtr<Gfx::Bitmap> m_icon;
|
||||
RefPtr<Cursor> m_cursor;
|
||||
RefPtr<Cursor> m_cursor_override;
|
||||
|
|
Loading…
Reference in a new issue