1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 09:27:35 +00:00

WindowServer+LibGUI: Pass the system theme using Core::AnonymousBuffer

This was the last remaining user of shbufs in WindowServer, and so
WindowServer no longer pledges "shared_buffer" :^)
This commit is contained in:
Andreas Kling 2021-01-16 17:20:53 +01:00
parent 9c6c18d9b6
commit 04f95f9160
13 changed files with 51 additions and 56 deletions

View file

@ -189,10 +189,10 @@ void Application::did_delete_last_window(Badge<Window>)
m_event_loop->quit(0); m_event_loop->quit(0);
} }
void Application::set_system_palette(SharedBuffer& buffer) void Application::set_system_palette(Core::AnonymousBuffer& buffer)
{ {
if (!m_system_palette) 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 else
m_system_palette->replace_internal_buffer({}, buffer); m_system_palette->replace_internal_buffer({}, buffer);

View file

@ -71,7 +71,7 @@ public:
Gfx::Palette palette() const; Gfx::Palette palette() const;
void set_palette(const Gfx::Palette&); 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 focus_debugging_enabled() const { return m_focus_debugging_enabled; }
bool dnd_debugging_enabled() const { return m_dnd_debugging_enabled; } bool dnd_debugging_enabled() const { return m_dnd_debugging_enabled; }

View file

@ -56,25 +56,23 @@ WindowServerConnection& WindowServerConnection::the()
return *s_connection; 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); Gfx::set_system_theme(buffer);
ASSERT(system_theme); Application::the()->set_system_palette(buffer);
Gfx::set_system_theme(*system_theme);
Application::the()->set_system_palette(*system_theme);
} }
void WindowServerConnection::handshake() void WindowServerConnection::handshake()
{ {
auto response = send_sync<Messages::WindowServer::Greet>(); auto response = send_sync<Messages::WindowServer::Greet>();
set_my_client_id(response->client_id()); 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()); Desktop::the().did_receive_screen_rect({}, response->screen_rect());
} }
void WindowServerConnection::handle(const Messages::WindowClient::UpdateSystemTheme& message) 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::update_all_windows({});
Window::for_each_window({}, [](auto& window) { Window::for_each_window({}, [](auto& window) {
Core::EventLoop::current().post_event(window, make<ThemeChangeEvent>()); Core::EventLoop::current().post_event(window, make<ThemeChangeEvent>());

View file

@ -31,13 +31,13 @@
namespace Gfx { namespace Gfx {
NonnullRefPtr<PaletteImpl> PaletteImpl::create_with_shared_buffer(SharedBuffer& buffer) NonnullRefPtr<PaletteImpl> PaletteImpl::create_with_anonymous_buffer(Core::AnonymousBuffer buffer)
{ {
return adopt(*new PaletteImpl(buffer)); return adopt(*new PaletteImpl(move(buffer)));
} }
PaletteImpl::PaletteImpl(SharedBuffer& buffer) PaletteImpl::PaletteImpl(Core::AnonymousBuffer buffer)
: m_theme_buffer(buffer) : m_theme_buffer(move(buffer))
{ {
} }
@ -52,7 +52,7 @@ Palette::~Palette()
const SystemTheme& PaletteImpl::theme() const const SystemTheme& PaletteImpl::theme() const
{ {
return *m_theme_buffer->data<SystemTheme>(); return *m_theme_buffer.data<SystemTheme>();
} }
Color PaletteImpl::color(ColorRole role) const Color PaletteImpl::color(ColorRole role) const
@ -75,9 +75,9 @@ String PaletteImpl::path(PathRole role) const
NonnullRefPtr<PaletteImpl> PaletteImpl::clone() const NonnullRefPtr<PaletteImpl> PaletteImpl::clone() const
{ {
auto new_theme_buffer = SharedBuffer::create_with_size(m_theme_buffer->size()); auto new_theme_buffer = Core::AnonymousBuffer::create_with_size(m_theme_buffer.size());
memcpy(new_theme_buffer->data<SystemTheme>(), &theme(), m_theme_buffer->size()); memcpy(new_theme_buffer.data<SystemTheme>(), &theme(), m_theme_buffer.size());
return adopt(*new PaletteImpl(*new_theme_buffer)); return adopt(*new PaletteImpl(move(new_theme_buffer)));
} }
void Palette::set_color(ColorRole role, Color color) void Palette::set_color(ColorRole role, Color color)
@ -109,9 +109,9 @@ PaletteImpl::~PaletteImpl()
{ {
} }
void PaletteImpl::replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer) void PaletteImpl::replace_internal_buffer(Badge<GUI::Application>, Core::AnonymousBuffer buffer)
{ {
m_theme_buffer = buffer; m_theme_buffer = move(buffer);
} }
} }

View file

@ -41,7 +41,7 @@ class PaletteImpl : public RefCounted<PaletteImpl> {
public: public:
~PaletteImpl(); ~PaletteImpl();
static NonnullRefPtr<PaletteImpl> create_with_shared_buffer(SharedBuffer&); static NonnullRefPtr<PaletteImpl> create_with_anonymous_buffer(Core::AnonymousBuffer);
NonnullRefPtr<PaletteImpl> clone() const; NonnullRefPtr<PaletteImpl> clone() const;
Color color(ColorRole) const; Color color(ColorRole) const;
@ -49,12 +49,12 @@ public:
String path(PathRole) const; String path(PathRole) const;
const SystemTheme& theme() const; const SystemTheme& theme() const;
void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer); void replace_internal_buffer(Badge<GUI::Application>, Core::AnonymousBuffer buffer);
private: private:
explicit PaletteImpl(SharedBuffer&); explicit PaletteImpl(Core::AnonymousBuffer);
RefPtr<SharedBuffer> m_theme_buffer; Core::AnonymousBuffer m_theme_buffer;
}; };
class Palette { class Palette {

View file

@ -33,7 +33,7 @@ namespace Gfx {
static SystemTheme dummy_theme; static SystemTheme dummy_theme;
static const SystemTheme* theme_page = &dummy_theme; static const SystemTheme* theme_page = &dummy_theme;
static RefPtr<SharedBuffer> theme_buffer; static Core::AnonymousBuffer theme_buffer;
const SystemTheme& current_system_theme() const SystemTheme& current_system_theme()
{ {
@ -41,24 +41,24 @@ const SystemTheme& current_system_theme()
return *theme_page; return *theme_page;
} }
int current_system_theme_buffer_id() Core::AnonymousBuffer& current_system_theme_buffer()
{ {
ASSERT(theme_buffer); ASSERT(theme_buffer.is_valid());
return theme_buffer->shbuf_id(); return theme_buffer;
} }
void set_system_theme(SharedBuffer& buffer) void set_system_theme(Core::AnonymousBuffer buffer)
{ {
theme_buffer = buffer; theme_buffer = move(buffer);
theme_page = theme_buffer->data<SystemTheme>(); theme_page = theme_buffer.data<SystemTheme>();
} }
RefPtr<SharedBuffer> load_system_theme(const String& path) Core::AnonymousBuffer load_system_theme(const String& path)
{ {
auto file = Core::ConfigFile::open(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<SystemTheme>(); auto* data = buffer.data<SystemTheme>();
auto get_color = [&](auto& name) { auto get_color = [&](auto& name) {
auto color_string = file->read_entry("Colors", name); auto color_string = file->read_entry("Colors", name);
@ -121,9 +121,6 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
DO_PATH(TitleButtonIcons); DO_PATH(TitleButtonIcons);
buffer->seal();
buffer->share_globally();
return buffer; return buffer;
} }

View file

@ -29,6 +29,7 @@
#include <AK/Forward.h> #include <AK/Forward.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <LibCore/AnonymousBuffer.h>
#include <LibGfx/Color.h> #include <LibGfx/Color.h>
namespace Gfx { namespace Gfx {
@ -153,9 +154,9 @@ struct SystemTheme {
}; };
const SystemTheme& current_system_theme(); const SystemTheme& current_system_theme();
int current_system_theme_buffer_id(); Core::AnonymousBuffer& current_system_theme_buffer();
void set_system_theme(SharedBuffer&); void set_system_theme(Core::AnonymousBuffer);
RefPtr<SharedBuffer> load_system_theme(const String& path); Core::AnonymousBuffer load_system_theme(const String& path);
} }

View file

@ -43,7 +43,7 @@ OutOfProcessWebView::OutOfProcessWebView()
set_should_hide_unnecessary_scrollbars(true); set_should_hide_unnecessary_scrollbars(true);
set_focus_policy(GUI::FocusPolicy::StrongFocus); set_focus_policy(GUI::FocusPolicy::StrongFocus);
m_client = WebContentClient::construct(*this); 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() OutOfProcessWebView::~OutOfProcessWebView()
@ -140,7 +140,7 @@ void OutOfProcessWebView::mousemove_event(GUI::MouseEvent& event)
void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event) void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event)
{ {
GUI::ScrollableWidget::theme_change_event(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(); request_repaint();
} }

View file

@ -713,7 +713,7 @@ void ClientConnection::handle(const Messages::WindowServer::WM_SetWindowMinimize
OwnPtr<Messages::WindowServer::GreetResponse> ClientConnection::handle(const Messages::WindowServer::Greet&) OwnPtr<Messages::WindowServer::GreetResponse> ClientConnection::handle(const Messages::WindowServer::Greet&)
{ {
return make<Messages::WindowServer::GreetResponse>(client_id(), Screen::the().rect(), Gfx::current_system_theme_buffer_id()); return make<Messages::WindowServer::GreetResponse>(client_id(), Screen::the().rect(), Gfx::current_system_theme_buffer());
} }
void ClientConnection::handle(const Messages::WindowServer::WM_SetWindowTaskbarRect& message) 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&) void ClientConnection::handle(const Messages::WindowServer::RefreshSystemTheme&)
{ {
// Post the client an UpdateSystemTheme message to refresh its theme. // 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&) void ClientConnection::handle(const Messages::WindowServer::Pong&)

View file

@ -34,7 +34,7 @@ endpoint WindowClient = 4
DragDropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] String text, HashMap<String,ByteBuffer> mime_data) =| DragDropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] String text, HashMap<String,ByteBuffer> mime_data) =|
UpdateSystemTheme(i32 system_theme_buffer_id) =| UpdateSystemTheme(Core::AnonymousBuffer theme_buffer) =|
DisplayLinkNotification() =| DisplayLinkNotification() =|

View file

@ -1404,17 +1404,16 @@ Gfx::IntRect WindowManager::dnd_rect() const
bool WindowManager::update_theme(String theme_path, String theme_name) bool WindowManager::update_theme(String theme_path, String theme_name)
{ {
auto new_theme = Gfx::load_system_theme(theme_path); auto new_theme = Gfx::load_system_theme(theme_path);
if (!new_theme) if (!new_theme.is_valid())
return false; return false;
ASSERT(new_theme); Gfx::set_system_theme(new_theme);
Gfx::set_system_theme(*new_theme); m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme);
m_palette = Gfx::PaletteImpl::create_with_shared_buffer(*new_theme);
Compositor::the().set_background_color(palette().desktop_background().to_string()); Compositor::the().set_background_color(palette().desktop_background().to_string());
HashTable<ClientConnection*> notified_clients; HashTable<ClientConnection*> notified_clients;
for_each_window([&](Window& window) { for_each_window([&](Window& window) {
if (window.client()) { if (window.client()) {
if (!notified_clients.contains(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()); notified_clients.set(window.client());
} }
} }

View file

@ -1,6 +1,6 @@
endpoint WindowServer = 2 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) CreateMenubar() => (i32 menubar_id)
DestroyMenubar(i32 menubar_id) => () DestroyMenubar(i32 menubar_id) => ()

View file

@ -39,7 +39,7 @@
int main(int, char**) 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"); perror("pledge");
return 1; return 1;
} }
@ -78,13 +78,13 @@ int main(int, char**)
auto theme_name = wm_config->read_entry("Theme", "Name", "Default"); auto theme_name = wm_config->read_entry("Theme", "Name", "Default");
auto theme = Gfx::load_system_theme(String::formatted("/res/themes/{}.ini", theme_name)); auto theme = Gfx::load_system_theme(String::formatted("/res/themes/{}.ini", theme_name));
ASSERT(theme); ASSERT(theme.is_valid());
Gfx::set_system_theme(*theme); Gfx::set_system_theme(theme);
auto palette = Gfx::PaletteImpl::create_with_shared_buffer(*theme); auto palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
WindowServer::EventLoop loop; 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"); perror("pledge");
return 1; return 1;
} }