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:
parent
9c6c18d9b6
commit
04f95f9160
Notes:
sideshowbarker
2024-07-18 23:10:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/04f95f91601
13 changed files with 51 additions and 56 deletions
|
@ -189,10 +189,10 @@ void Application::did_delete_last_window(Badge<Window>)
|
|||
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);
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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<Messages::WindowServer::Greet>();
|
||||
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<ThemeChangeEvent>());
|
||||
|
|
|
@ -31,13 +31,13 @@
|
|||
|
||||
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)
|
||||
: 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<SystemTheme>();
|
||||
return *m_theme_buffer.data<SystemTheme>();
|
||||
}
|
||||
|
||||
Color PaletteImpl::color(ColorRole role) const
|
||||
|
@ -75,9 +75,9 @@ String PaletteImpl::path(PathRole role) const
|
|||
|
||||
NonnullRefPtr<PaletteImpl> PaletteImpl::clone() const
|
||||
{
|
||||
auto new_theme_buffer = SharedBuffer::create_with_size(m_theme_buffer->size());
|
||||
memcpy(new_theme_buffer->data<SystemTheme>(), &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<SystemTheme>(), &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<GUI::Application>, SharedBuffer& buffer)
|
||||
void PaletteImpl::replace_internal_buffer(Badge<GUI::Application>, Core::AnonymousBuffer buffer)
|
||||
{
|
||||
m_theme_buffer = buffer;
|
||||
m_theme_buffer = move(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class PaletteImpl : public RefCounted<PaletteImpl> {
|
|||
|
||||
public:
|
||||
~PaletteImpl();
|
||||
static NonnullRefPtr<PaletteImpl> create_with_shared_buffer(SharedBuffer&);
|
||||
static NonnullRefPtr<PaletteImpl> create_with_anonymous_buffer(Core::AnonymousBuffer);
|
||||
NonnullRefPtr<PaletteImpl> clone() const;
|
||||
|
||||
Color color(ColorRole) const;
|
||||
|
@ -49,12 +49,12 @@ public:
|
|||
String path(PathRole) 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:
|
||||
explicit PaletteImpl(SharedBuffer&);
|
||||
explicit PaletteImpl(Core::AnonymousBuffer);
|
||||
|
||||
RefPtr<SharedBuffer> m_theme_buffer;
|
||||
Core::AnonymousBuffer m_theme_buffer;
|
||||
};
|
||||
|
||||
class Palette {
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace Gfx {
|
|||
|
||||
static SystemTheme dummy_theme;
|
||||
static const SystemTheme* theme_page = &dummy_theme;
|
||||
static RefPtr<SharedBuffer> 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<SystemTheme>();
|
||||
theme_buffer = move(buffer);
|
||||
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 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 color_string = file->read_entry("Colors", name);
|
||||
|
@ -121,9 +121,6 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|||
|
||||
DO_PATH(TitleButtonIcons);
|
||||
|
||||
buffer->seal();
|
||||
buffer->share_globally();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Forward.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCore/AnonymousBuffer.h>
|
||||
#include <LibGfx/Color.h>
|
||||
|
||||
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<SharedBuffer> 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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -713,7 +713,7 @@ void ClientConnection::handle(const Messages::WindowServer::WM_SetWindowMinimize
|
|||
|
||||
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)
|
||||
|
@ -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&)
|
||||
|
|
|
@ -34,7 +34,7 @@ endpoint WindowClient = 4
|
|||
|
||||
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() =|
|
||||
|
||||
|
|
|
@ -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<ClientConnection*> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) => ()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue