diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index fbd0c7260d..818fe37cd6 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -189,10 +189,10 @@ void Application::did_delete_last_window(Badge) m_event_loop->quit(0); } -void Application::set_system_palette(SharedBuffer& buffer) +void Application::set_system_palette(Core::AnonymousBuffer& buffer) { if (!m_system_palette) - m_system_palette = Gfx::PaletteImpl::create_with_shared_buffer(buffer); + m_system_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(buffer); else m_system_palette->replace_internal_buffer({}, buffer); diff --git a/Userland/Libraries/LibGUI/Application.h b/Userland/Libraries/LibGUI/Application.h index 4114ef631d..32731c8853 100644 --- a/Userland/Libraries/LibGUI/Application.h +++ b/Userland/Libraries/LibGUI/Application.h @@ -71,7 +71,7 @@ public: Gfx::Palette palette() const; void set_palette(const Gfx::Palette&); - void set_system_palette(SharedBuffer&); + void set_system_palette(Core::AnonymousBuffer&); bool focus_debugging_enabled() const { return m_focus_debugging_enabled; } bool dnd_debugging_enabled() const { return m_dnd_debugging_enabled; } diff --git a/Userland/Libraries/LibGUI/WindowServerConnection.cpp b/Userland/Libraries/LibGUI/WindowServerConnection.cpp index 8540a924c8..b3167fff19 100644 --- a/Userland/Libraries/LibGUI/WindowServerConnection.cpp +++ b/Userland/Libraries/LibGUI/WindowServerConnection.cpp @@ -56,25 +56,23 @@ WindowServerConnection& WindowServerConnection::the() return *s_connection; } -static void set_system_theme_from_shbuf_id(int id) +static void set_system_theme_from_anonymous_buffer(Core::AnonymousBuffer buffer) { - auto system_theme = SharedBuffer::create_from_shbuf_id(id); - ASSERT(system_theme); - Gfx::set_system_theme(*system_theme); - Application::the()->set_system_palette(*system_theme); + Gfx::set_system_theme(buffer); + Application::the()->set_system_palette(buffer); } void WindowServerConnection::handshake() { auto response = send_sync(); set_my_client_id(response->client_id()); - set_system_theme_from_shbuf_id(response->system_theme_buffer_id()); + set_system_theme_from_anonymous_buffer(response->theme_buffer()); Desktop::the().did_receive_screen_rect({}, response->screen_rect()); } void WindowServerConnection::handle(const Messages::WindowClient::UpdateSystemTheme& message) { - set_system_theme_from_shbuf_id(message.system_theme_buffer_id()); + set_system_theme_from_anonymous_buffer(message.theme_buffer()); Window::update_all_windows({}); Window::for_each_window({}, [](auto& window) { Core::EventLoop::current().post_event(window, make()); diff --git a/Userland/Libraries/LibGfx/Palette.cpp b/Userland/Libraries/LibGfx/Palette.cpp index de6915d7ba..2616c4d06e 100644 --- a/Userland/Libraries/LibGfx/Palette.cpp +++ b/Userland/Libraries/LibGfx/Palette.cpp @@ -31,13 +31,13 @@ namespace Gfx { -NonnullRefPtr PaletteImpl::create_with_shared_buffer(SharedBuffer& buffer) +NonnullRefPtr PaletteImpl::create_with_anonymous_buffer(Core::AnonymousBuffer buffer) { - return adopt(*new PaletteImpl(buffer)); + return adopt(*new PaletteImpl(move(buffer))); } -PaletteImpl::PaletteImpl(SharedBuffer& buffer) - : m_theme_buffer(buffer) +PaletteImpl::PaletteImpl(Core::AnonymousBuffer buffer) + : m_theme_buffer(move(buffer)) { } @@ -52,7 +52,7 @@ Palette::~Palette() const SystemTheme& PaletteImpl::theme() const { - return *m_theme_buffer->data(); + return *m_theme_buffer.data(); } Color PaletteImpl::color(ColorRole role) const @@ -75,9 +75,9 @@ String PaletteImpl::path(PathRole role) const NonnullRefPtr PaletteImpl::clone() const { - auto new_theme_buffer = SharedBuffer::create_with_size(m_theme_buffer->size()); - memcpy(new_theme_buffer->data(), &theme(), m_theme_buffer->size()); - return adopt(*new PaletteImpl(*new_theme_buffer)); + auto new_theme_buffer = Core::AnonymousBuffer::create_with_size(m_theme_buffer.size()); + memcpy(new_theme_buffer.data(), &theme(), m_theme_buffer.size()); + return adopt(*new PaletteImpl(move(new_theme_buffer))); } void Palette::set_color(ColorRole role, Color color) @@ -109,9 +109,9 @@ PaletteImpl::~PaletteImpl() { } -void PaletteImpl::replace_internal_buffer(Badge, SharedBuffer& buffer) +void PaletteImpl::replace_internal_buffer(Badge, Core::AnonymousBuffer buffer) { - m_theme_buffer = buffer; + m_theme_buffer = move(buffer); } } diff --git a/Userland/Libraries/LibGfx/Palette.h b/Userland/Libraries/LibGfx/Palette.h index dfd47e90ff..65153ce1ba 100644 --- a/Userland/Libraries/LibGfx/Palette.h +++ b/Userland/Libraries/LibGfx/Palette.h @@ -41,7 +41,7 @@ class PaletteImpl : public RefCounted { public: ~PaletteImpl(); - static NonnullRefPtr create_with_shared_buffer(SharedBuffer&); + static NonnullRefPtr create_with_anonymous_buffer(Core::AnonymousBuffer); NonnullRefPtr clone() const; Color color(ColorRole) const; @@ -49,12 +49,12 @@ public: String path(PathRole) const; const SystemTheme& theme() const; - void replace_internal_buffer(Badge, SharedBuffer& buffer); + void replace_internal_buffer(Badge, Core::AnonymousBuffer buffer); private: - explicit PaletteImpl(SharedBuffer&); + explicit PaletteImpl(Core::AnonymousBuffer); - RefPtr m_theme_buffer; + Core::AnonymousBuffer m_theme_buffer; }; class Palette { diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp index 5ccb04256d..7d48311dfa 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.cpp +++ b/Userland/Libraries/LibGfx/SystemTheme.cpp @@ -33,7 +33,7 @@ namespace Gfx { static SystemTheme dummy_theme; static const SystemTheme* theme_page = &dummy_theme; -static RefPtr theme_buffer; +static Core::AnonymousBuffer theme_buffer; const SystemTheme& current_system_theme() { @@ -41,24 +41,24 @@ const SystemTheme& current_system_theme() return *theme_page; } -int current_system_theme_buffer_id() +Core::AnonymousBuffer& current_system_theme_buffer() { - ASSERT(theme_buffer); - return theme_buffer->shbuf_id(); + ASSERT(theme_buffer.is_valid()); + return theme_buffer; } -void set_system_theme(SharedBuffer& buffer) +void set_system_theme(Core::AnonymousBuffer buffer) { - theme_buffer = buffer; - theme_page = theme_buffer->data(); + theme_buffer = move(buffer); + theme_page = theme_buffer.data(); } -RefPtr load_system_theme(const String& path) +Core::AnonymousBuffer load_system_theme(const String& path) { auto file = Core::ConfigFile::open(path); - auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme)); + auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme)); - auto* data = buffer->data(); + auto* data = buffer.data(); auto get_color = [&](auto& name) { auto color_string = file->read_entry("Colors", name); @@ -121,9 +121,6 @@ RefPtr load_system_theme(const String& path) DO_PATH(TitleButtonIcons); - buffer->seal(); - buffer->share_globally(); - return buffer; } diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h index 60e382c65f..7c3fbbabb9 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.h +++ b/Userland/Libraries/LibGfx/SystemTheme.h @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace Gfx { @@ -153,9 +154,9 @@ struct SystemTheme { }; const SystemTheme& current_system_theme(); -int current_system_theme_buffer_id(); -void set_system_theme(SharedBuffer&); -RefPtr load_system_theme(const String& path); +Core::AnonymousBuffer& current_system_theme_buffer(); +void set_system_theme(Core::AnonymousBuffer); +Core::AnonymousBuffer load_system_theme(const String& path); } diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index d30025d678..003571e2e8 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -43,7 +43,7 @@ OutOfProcessWebView::OutOfProcessWebView() set_should_hide_unnecessary_scrollbars(true); set_focus_policy(GUI::FocusPolicy::StrongFocus); m_client = WebContentClient::construct(*this); - client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer_id())); + client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer())); } OutOfProcessWebView::~OutOfProcessWebView() @@ -140,7 +140,7 @@ void OutOfProcessWebView::mousemove_event(GUI::MouseEvent& event) void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event) { GUI::ScrollableWidget::theme_change_event(event); - client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer_id())); + client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer())); request_repaint(); } diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 3c8b10bfe7..482294de57 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -713,7 +713,7 @@ void ClientConnection::handle(const Messages::WindowServer::WM_SetWindowMinimize OwnPtr ClientConnection::handle(const Messages::WindowServer::Greet&) { - return make(client_id(), Screen::the().rect(), Gfx::current_system_theme_buffer_id()); + return make(client_id(), Screen::the().rect(), Gfx::current_system_theme_buffer()); } void ClientConnection::handle(const Messages::WindowServer::WM_SetWindowTaskbarRect& message) @@ -836,7 +836,7 @@ void ClientConnection::handle(const Messages::WindowServer::SetWindowProgress& m void ClientConnection::handle(const Messages::WindowServer::RefreshSystemTheme&) { // Post the client an UpdateSystemTheme message to refresh its theme. - post_message(Messages::WindowClient::UpdateSystemTheme(Gfx::current_system_theme_buffer_id())); + post_message(Messages::WindowClient::UpdateSystemTheme(Gfx::current_system_theme_buffer())); } void ClientConnection::handle(const Messages::WindowServer::Pong&) diff --git a/Userland/Services/WindowServer/WindowClient.ipc b/Userland/Services/WindowServer/WindowClient.ipc index f3d04d5a9c..ad0952ca53 100644 --- a/Userland/Services/WindowServer/WindowClient.ipc +++ b/Userland/Services/WindowServer/WindowClient.ipc @@ -34,7 +34,7 @@ endpoint WindowClient = 4 DragDropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] String text, HashMap mime_data) =| - UpdateSystemTheme(i32 system_theme_buffer_id) =| + UpdateSystemTheme(Core::AnonymousBuffer theme_buffer) =| DisplayLinkNotification() =| diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index ebc4529372..f0080ff427 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1404,17 +1404,16 @@ Gfx::IntRect WindowManager::dnd_rect() const bool WindowManager::update_theme(String theme_path, String theme_name) { auto new_theme = Gfx::load_system_theme(theme_path); - if (!new_theme) + if (!new_theme.is_valid()) return false; - ASSERT(new_theme); - Gfx::set_system_theme(*new_theme); - m_palette = Gfx::PaletteImpl::create_with_shared_buffer(*new_theme); + Gfx::set_system_theme(new_theme); + m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme); Compositor::the().set_background_color(palette().desktop_background().to_string()); HashTable notified_clients; for_each_window([&](Window& window) { if (window.client()) { if (!notified_clients.contains(window.client())) { - window.client()->post_message(Messages::WindowClient::UpdateSystemTheme(Gfx::current_system_theme_buffer_id())); + window.client()->post_message(Messages::WindowClient::UpdateSystemTheme(Gfx::current_system_theme_buffer())); notified_clients.set(window.client()); } } diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 80ad93cdf8..3b528228f1 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -1,6 +1,6 @@ endpoint WindowServer = 2 { - Greet() => (i32 client_id, Gfx::IntRect screen_rect, i32 system_theme_buffer_id) + Greet() => (i32 client_id, Gfx::IntRect screen_rect, Core::AnonymousBuffer theme_buffer) CreateMenubar() => (i32 menubar_id) DestroyMenubar(i32 menubar_id) => () diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp index 8792c37467..1e6a0d8ce2 100644 --- a/Userland/Services/WindowServer/main.cpp +++ b/Userland/Services/WindowServer/main.cpp @@ -39,7 +39,7 @@ int main(int, char**) { - if (pledge("stdio video thread sendfd recvfd shared_buffer accept rpath wpath cpath unix proc fattr sigaction", nullptr) < 0) { + if (pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc fattr sigaction", nullptr) < 0) { perror("pledge"); return 1; } @@ -78,13 +78,13 @@ int main(int, char**) auto theme_name = wm_config->read_entry("Theme", "Name", "Default"); auto theme = Gfx::load_system_theme(String::formatted("/res/themes/{}.ini", theme_name)); - ASSERT(theme); - Gfx::set_system_theme(*theme); - auto palette = Gfx::PaletteImpl::create_with_shared_buffer(*theme); + ASSERT(theme.is_valid()); + Gfx::set_system_theme(theme); + auto palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme); WindowServer::EventLoop loop; - if (pledge("stdio video thread sendfd recvfd shared_buffer accept rpath wpath cpath proc", nullptr) < 0) { + if (pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc", nullptr) < 0) { perror("pledge"); return 1; }