From 870bc2a4d1a86b9c889461a3981ee359ff45c15c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 21 Sep 2019 18:53:17 +0200 Subject: [PATCH] LibGUI: Get rid of GWindow's destroy-on-close mechanism Since we're moving to a world of ref-counting, we can't have weird behaviors like "windows delete themselves when you close them." The "close app when there are no more windows" mechanism is moved to GWindow::hide(). Now, we close the app when it has no more windows on screen. --- Libraries/LibGUI/GComboBox.cpp | 1 - Libraries/LibGUI/GWindow.cpp | 16 +++++++++++----- Libraries/LibGUI/GWindow.h | 4 ---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Libraries/LibGUI/GComboBox.cpp b/Libraries/LibGUI/GComboBox.cpp index 8a984c7099..541a73ce35 100644 --- a/Libraries/LibGUI/GComboBox.cpp +++ b/Libraries/LibGUI/GComboBox.cpp @@ -31,7 +31,6 @@ GComboBox::GComboBox(GWidget* parent) m_list_window = GWindow::construct(this); // FIXME: This is obviously not a tooltip window, but it's the closest thing to what we want atm. m_list_window->set_window_type(GWindowType::Tooltip); - m_list_window->set_should_destroy_on_close(false); m_list_view = GListView::construct(nullptr); m_list_view->horizontal_scrollbar().set_visible(false); diff --git a/Libraries/LibGUI/GWindow.cpp b/Libraries/LibGUI/GWindow.cpp index 1c340ae42c..59fe675d07 100644 --- a/Libraries/LibGUI/GWindow.cpp +++ b/Libraries/LibGUI/GWindow.cpp @@ -38,15 +38,11 @@ GWindow::~GWindow() { all_windows.remove(this); hide(); - if (all_windows.is_empty()) { - GApplication::the().did_delete_last_window({}); - } } void GWindow::close() { - if (should_destroy_on_close()) - delete_later(); + hide(); } void GWindow::move_to_front() @@ -104,6 +100,16 @@ void GWindow::hide() m_pending_paint_event_rects.clear(); m_back_bitmap = nullptr; m_front_bitmap = nullptr; + + bool app_has_visible_windows = false; + for (auto& window : all_windows) { + if (window->is_visible()) { + app_has_visible_windows = true; + break; + } + } + if (!app_has_visible_windows) + GApplication::the().did_delete_last_window({}); } void GWindow::set_title(const StringView& title) diff --git a/Libraries/LibGUI/GWindow.h b/Libraries/LibGUI/GWindow.h index 3150fc3528..abbe7a1de6 100644 --- a/Libraries/LibGUI/GWindow.h +++ b/Libraries/LibGUI/GWindow.h @@ -53,9 +53,6 @@ public: Color background_color() const { return m_background_color; } void set_background_color(Color color) { m_background_color = color; } - bool should_destroy_on_close() { return m_destroy_on_close; } - void set_should_destroy_on_close(bool b) { m_destroy_on_close = b; } - enum class CloseRequestDecision { StayOpen, Close, @@ -167,7 +164,6 @@ private: Color m_background_color { Color::WarmGray }; GWindowType m_window_type { GWindowType::Normal }; bool m_is_active { false }; - bool m_destroy_on_close { true }; bool m_has_alpha_channel { false }; bool m_double_buffering_enabled { true }; bool m_modal { false };