mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
LibGUI: Use NeverDestroyed<T> for the global GWindow tables
We don't need these to be destroyed on exit, since that would race with the destruction of static global RefPtr<GWindow>'s. Fixes #900.
This commit is contained in:
parent
f607cab235
commit
43da941de5
1 changed files with 11 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
|
#include <AK/NeverDestroyed.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibC/SharedBuffer.h>
|
#include <LibC/SharedBuffer.h>
|
||||||
#include <LibC/stdio.h>
|
#include <LibC/stdio.h>
|
||||||
|
@ -15,13 +16,13 @@
|
||||||
|
|
||||||
//#define UPDATE_COALESCING_DEBUG
|
//#define UPDATE_COALESCING_DEBUG
|
||||||
|
|
||||||
static HashTable<GWindow*> all_windows;
|
static NeverDestroyed<HashTable<GWindow*>> all_windows;
|
||||||
static HashMap<int, GWindow*> reified_windows;
|
static NeverDestroyed<HashMap<int, GWindow*>> reified_windows;
|
||||||
|
|
||||||
GWindow* GWindow::from_window_id(int window_id)
|
GWindow* GWindow::from_window_id(int window_id)
|
||||||
{
|
{
|
||||||
auto it = reified_windows.find(window_id);
|
auto it = reified_windows->find(window_id);
|
||||||
if (it != reified_windows.end())
|
if (it != reified_windows->end())
|
||||||
return (*it).value;
|
return (*it).value;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -29,14 +30,14 @@ GWindow* GWindow::from_window_id(int window_id)
|
||||||
GWindow::GWindow(CObject* parent)
|
GWindow::GWindow(CObject* parent)
|
||||||
: CObject(parent)
|
: CObject(parent)
|
||||||
{
|
{
|
||||||
all_windows.set(this);
|
all_windows->set(this);
|
||||||
m_rect_when_windowless = { 100, 400, 140, 140 };
|
m_rect_when_windowless = { 100, 400, 140, 140 };
|
||||||
m_title_when_windowless = "GWindow";
|
m_title_when_windowless = "GWindow";
|
||||||
}
|
}
|
||||||
|
|
||||||
GWindow::~GWindow()
|
GWindow::~GWindow()
|
||||||
{
|
{
|
||||||
all_windows.remove(this);
|
all_windows->remove(this);
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ void GWindow::show()
|
||||||
|
|
||||||
apply_icon();
|
apply_icon();
|
||||||
|
|
||||||
reified_windows.set(m_window_id, this);
|
reified_windows->set(m_window_id, this);
|
||||||
GApplication::the().did_create_window({});
|
GApplication::the().did_create_window({});
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -83,7 +84,7 @@ void GWindow::hide()
|
||||||
{
|
{
|
||||||
if (!m_window_id)
|
if (!m_window_id)
|
||||||
return;
|
return;
|
||||||
reified_windows.remove(m_window_id);
|
reified_windows->remove(m_window_id);
|
||||||
GWindowServerConnection::the().send_sync<WindowServer::DestroyWindow>(m_window_id);
|
GWindowServerConnection::the().send_sync<WindowServer::DestroyWindow>(m_window_id);
|
||||||
m_window_id = 0;
|
m_window_id = 0;
|
||||||
m_pending_paint_event_rects.clear();
|
m_pending_paint_event_rects.clear();
|
||||||
|
@ -91,7 +92,7 @@ void GWindow::hide()
|
||||||
m_front_bitmap = nullptr;
|
m_front_bitmap = nullptr;
|
||||||
|
|
||||||
bool app_has_visible_windows = false;
|
bool app_has_visible_windows = false;
|
||||||
for (auto& window : all_windows) {
|
for (auto& window : *all_windows) {
|
||||||
if (window->is_visible()) {
|
if (window->is_visible()) {
|
||||||
app_has_visible_windows = true;
|
app_has_visible_windows = true;
|
||||||
break;
|
break;
|
||||||
|
@ -689,7 +690,7 @@ void GWindow::schedule_relayout()
|
||||||
|
|
||||||
void GWindow::update_all_windows(Badge<GWindowServerConnection>)
|
void GWindow::update_all_windows(Badge<GWindowServerConnection>)
|
||||||
{
|
{
|
||||||
for (auto* window : all_windows) {
|
for (auto* window : *all_windows) {
|
||||||
window->update();
|
window->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue