1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:55:08 +00:00

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.
This commit is contained in:
Andreas Kling 2019-09-21 18:53:17 +02:00
parent 7584480f62
commit 870bc2a4d1
3 changed files with 11 additions and 10 deletions

View file

@ -31,7 +31,6 @@ GComboBox::GComboBox(GWidget* parent)
m_list_window = GWindow::construct(this); 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. // 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_window_type(GWindowType::Tooltip);
m_list_window->set_should_destroy_on_close(false);
m_list_view = GListView::construct(nullptr); m_list_view = GListView::construct(nullptr);
m_list_view->horizontal_scrollbar().set_visible(false); m_list_view->horizontal_scrollbar().set_visible(false);

View file

@ -38,15 +38,11 @@ GWindow::~GWindow()
{ {
all_windows.remove(this); all_windows.remove(this);
hide(); hide();
if (all_windows.is_empty()) {
GApplication::the().did_delete_last_window({});
}
} }
void GWindow::close() void GWindow::close()
{ {
if (should_destroy_on_close()) hide();
delete_later();
} }
void GWindow::move_to_front() void GWindow::move_to_front()
@ -104,6 +100,16 @@ void GWindow::hide()
m_pending_paint_event_rects.clear(); m_pending_paint_event_rects.clear();
m_back_bitmap = nullptr; m_back_bitmap = nullptr;
m_front_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) void GWindow::set_title(const StringView& title)

View file

@ -53,9 +53,6 @@ public:
Color background_color() const { return m_background_color; } Color background_color() const { return m_background_color; }
void set_background_color(Color color) { m_background_color = 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 { enum class CloseRequestDecision {
StayOpen, StayOpen,
Close, Close,
@ -167,7 +164,6 @@ private:
Color m_background_color { Color::WarmGray }; Color m_background_color { Color::WarmGray };
GWindowType m_window_type { GWindowType::Normal }; GWindowType m_window_type { GWindowType::Normal };
bool m_is_active { false }; bool m_is_active { false };
bool m_destroy_on_close { true };
bool m_has_alpha_channel { false }; bool m_has_alpha_channel { false };
bool m_double_buffering_enabled { true }; bool m_double_buffering_enabled { true };
bool m_modal { false }; bool m_modal { false };