mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 11:09:05 +03:00
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.
This commit is contained in:
parent
50d0d6e710
commit
24aa43f3fd
Notes:
sideshowbarker
2024-07-16 20:39:14 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/24aa43f3fd Pull-request: https://github.com/SerenityOS/serenity/pull/21181 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/bplaat ✅
@ -81,6 +81,7 @@ Window::Window(Core::EventReceiver* parent)
|
|||||||
|
|
||||||
all_windows->set(this);
|
all_windows->set(this);
|
||||||
m_rect_when_windowless = { -5000, -5000, 0, 0 };
|
m_rect_when_windowless = { -5000, -5000, 0, 0 };
|
||||||
|
m_floating_rect = { -5000, -5000, 0, 0 };
|
||||||
m_title_when_windowless = "GUI::Window";
|
m_title_when_windowless = "GUI::Window";
|
||||||
|
|
||||||
register_property(
|
register_property(
|
||||||
@ -220,6 +221,7 @@ void Window::hide()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_rect_when_windowless = rect();
|
m_rect_when_windowless = rect();
|
||||||
|
m_floating_rect = floating_rect();
|
||||||
|
|
||||||
auto destroyed_window_ids = ConnectionToWindowServer::the().destroy_window(m_window_id);
|
auto destroyed_window_ids = ConnectionToWindowServer::the().destroy_window(m_window_id);
|
||||||
server_did_destroy();
|
server_did_destroy();
|
||||||
@ -271,6 +273,13 @@ Gfx::IntRect Window::rect() const
|
|||||||
return ConnectionToWindowServer::the().get_window_rect(m_window_id);
|
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)
|
void Window::set_rect(Gfx::IntRect const& a_rect)
|
||||||
{
|
{
|
||||||
if (a_rect.location() != m_rect_when_windowless.location()) {
|
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_rect_when_windowless = a_rect;
|
||||||
|
m_floating_rect = a_rect;
|
||||||
|
|
||||||
if (!is_visible()) {
|
if (!is_visible()) {
|
||||||
if (m_main_widget)
|
if (m_main_widget)
|
||||||
m_main_widget->resize(m_rect_when_windowless.size());
|
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
|
void Window::save_size_and_position(StringView domain, StringView group) const
|
||||||
{
|
{
|
||||||
Config::write_i32(domain, group, "X"sv, x());
|
auto rect_to_save = floating_rect();
|
||||||
Config::write_i32(domain, group, "Y"sv, y());
|
Config::write_i32(domain, group, "X"sv, rect_to_save.x());
|
||||||
Config::write_i32(domain, group, "Width"sv, width());
|
Config::write_i32(domain, group, "Y"sv, rect_to_save.y());
|
||||||
Config::write_i32(domain, group, "Height"sv, height());
|
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());
|
Config::write_bool(domain, group, "Maximized"sv, is_maximized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ public:
|
|||||||
int height() const { return rect().height(); }
|
int height() const { return rect().height(); }
|
||||||
|
|
||||||
Gfx::IntRect rect() const;
|
Gfx::IntRect rect() const;
|
||||||
|
Gfx::IntRect floating_rect() const;
|
||||||
Gfx::IntRect applet_rect_on_screen() const;
|
Gfx::IntRect applet_rect_on_screen() const;
|
||||||
Gfx::IntSize size() const { return rect().size(); }
|
Gfx::IntSize size() const { return rect().size(); }
|
||||||
void set_rect(Gfx::IntRect const&);
|
void set_rect(Gfx::IntRect const&);
|
||||||
@ -300,6 +301,7 @@ private:
|
|||||||
WeakPtr<Widget> m_hovered_widget;
|
WeakPtr<Widget> m_hovered_widget;
|
||||||
Gfx::IntRect m_rect_when_windowless;
|
Gfx::IntRect m_rect_when_windowless;
|
||||||
Gfx::IntSize m_minimum_size_when_windowless { 0, 0 };
|
Gfx::IntSize m_minimum_size_when_windowless { 0, 0 };
|
||||||
|
Gfx::IntRect m_floating_rect;
|
||||||
DeprecatedString m_title_when_windowless;
|
DeprecatedString m_title_when_windowless;
|
||||||
Vector<Gfx::IntRect, 32> m_pending_paint_event_rects;
|
Vector<Gfx::IntRect, 32> m_pending_paint_event_rects;
|
||||||
Gfx::IntSize m_size_increment;
|
Gfx::IntSize m_size_increment;
|
||||||
|
Loading…
Reference in New Issue
Block a user