From 24aa43f3fd9a778c6ca40103e84c8a2d25d08f68 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 21 Sep 2023 21:24:10 +0100 Subject: [PATCH] LibGUI: Use floating rect when saving window state on exit Previously, exiting a fullscreen application when `save_size_and_position_on_close()` was used would lead to the application having an unexpectedly large size when it was reopened. Exiting a maximized application would lead to the restore button not working as expected when the application was reopened. --- Userland/Libraries/LibGUI/Window.cpp | 20 ++++++++++++++++---- Userland/Libraries/LibGUI/Window.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index df4c7c491c..732958c9a2 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -81,6 +81,7 @@ Window::Window(Core::EventReceiver* parent) all_windows->set(this); m_rect_when_windowless = { -5000, -5000, 0, 0 }; + m_floating_rect = { -5000, -5000, 0, 0 }; m_title_when_windowless = "GUI::Window"; register_property( @@ -220,6 +221,7 @@ void Window::hide() return; m_rect_when_windowless = rect(); + m_floating_rect = floating_rect(); auto destroyed_window_ids = ConnectionToWindowServer::the().destroy_window(m_window_id); server_did_destroy(); @@ -271,6 +273,13 @@ Gfx::IntRect Window::rect() const return ConnectionToWindowServer::the().get_window_rect(m_window_id); } +Gfx::IntRect Window::floating_rect() const +{ + if (!is_visible()) + return m_floating_rect; + return ConnectionToWindowServer::the().get_window_floating_rect(m_window_id); +} + void Window::set_rect(Gfx::IntRect const& a_rect) { if (a_rect.location() != m_rect_when_windowless.location()) { @@ -278,6 +287,8 @@ void Window::set_rect(Gfx::IntRect const& a_rect) } m_rect_when_windowless = a_rect; + m_floating_rect = a_rect; + if (!is_visible()) { if (m_main_widget) m_main_widget->resize(m_rect_when_windowless.size()); @@ -548,10 +559,11 @@ void Window::restore_size_and_position(StringView domain, StringView group, Opti void Window::save_size_and_position(StringView domain, StringView group) const { - Config::write_i32(domain, group, "X"sv, x()); - Config::write_i32(domain, group, "Y"sv, y()); - Config::write_i32(domain, group, "Width"sv, width()); - Config::write_i32(domain, group, "Height"sv, height()); + auto rect_to_save = floating_rect(); + Config::write_i32(domain, group, "X"sv, rect_to_save.x()); + Config::write_i32(domain, group, "Y"sv, rect_to_save.y()); + Config::write_i32(domain, group, "Width"sv, rect_to_save.width()); + Config::write_i32(domain, group, "Height"sv, rect_to_save.height()); Config::write_bool(domain, group, "Maximized"sv, is_maximized()); } diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index c5e4f68f3a..9ee070275b 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -109,6 +109,7 @@ public: int height() const { return rect().height(); } Gfx::IntRect rect() const; + Gfx::IntRect floating_rect() const; Gfx::IntRect applet_rect_on_screen() const; Gfx::IntSize size() const { return rect().size(); } void set_rect(Gfx::IntRect const&); @@ -300,6 +301,7 @@ private: WeakPtr m_hovered_widget; Gfx::IntRect m_rect_when_windowless; Gfx::IntSize m_minimum_size_when_windowless { 0, 0 }; + Gfx::IntRect m_floating_rect; DeprecatedString m_title_when_windowless; Vector m_pending_paint_event_rects; Gfx::IntSize m_size_increment;