diff --git a/Userland/Libraries/LibGUI/WindowServerConnection.cpp b/Userland/Libraries/LibGUI/WindowServerConnection.cpp index d51d57d1e3..ac9ff33b5a 100644 --- a/Userland/Libraries/LibGUI/WindowServerConnection.cpp +++ b/Userland/Libraries/LibGUI/WindowServerConnection.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -47,9 +48,11 @@ void WindowServerConnection::handshake() auto message = wait_for_specific_message(); set_system_theme_from_anonymous_buffer(message->theme_buffer()); Desktop::the().did_receive_screen_rect({}, message->screen_rect()); + Gfx::FontDatabase::set_default_font_query(message->default_font_query()); + Gfx::FontDatabase::set_fixed_width_font_query(message->fixed_width_font_query()); } -void WindowServerConnection::fast_greet(Gfx::IntRect const&, Core::AnonymousBuffer const&) +void WindowServerConnection::fast_greet(Gfx::IntRect const&, Core::AnonymousBuffer const&, String const&, String const&) { // NOTE: This message is handled in handshake(). } @@ -63,6 +66,12 @@ void WindowServerConnection::update_system_theme(Core::AnonymousBuffer const& th }); } +void WindowServerConnection::update_system_fonts(const String& default_font_query, const String& fixed_width_font_query) +{ + Gfx::FontDatabase::set_default_font_query(default_font_query); + Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query); +} + void WindowServerConnection::paint(i32 window_id, Gfx::IntSize const& window_size, Vector const& rects) { if (auto* window = Window::from_window_id(window_id)) diff --git a/Userland/Libraries/LibGUI/WindowServerConnection.h b/Userland/Libraries/LibGUI/WindowServerConnection.h index 38b2a3db9f..6c7e4d2d5c 100644 --- a/Userland/Libraries/LibGUI/WindowServerConnection.h +++ b/Userland/Libraries/LibGUI/WindowServerConnection.h @@ -27,7 +27,7 @@ public: static WindowServerConnection& the(); private: - virtual void fast_greet(Gfx::IntRect const&, Core::AnonymousBuffer const&) override; + virtual void fast_greet(Gfx::IntRect const&, Core::AnonymousBuffer const&, String const&, String const&) override; virtual void paint(i32, Gfx::IntSize const&, Vector const&) override; virtual void mouse_move(i32, Gfx::IntPoint const&, u32, u32, u32, i32, bool, Vector const&) override; virtual void mouse_down(i32, Gfx::IntPoint const&, u32, u32, u32, i32) override; @@ -54,6 +54,7 @@ private: virtual void drag_accepted() override; virtual void drag_cancelled() override; virtual void update_system_theme(Core::AnonymousBuffer const&) override; + virtual void update_system_fonts(String const&, String const&) override; virtual void window_state_changed(i32, bool, bool) override; virtual void display_link_notification() override; virtual void ping() override; diff --git a/Userland/Libraries/LibGfx/FontDatabase.cpp b/Userland/Libraries/LibGfx/FontDatabase.cpp index d059de5f94..76d4517b80 100644 --- a/Userland/Libraries/LibGfx/FontDatabase.cpp +++ b/Userland/Libraries/LibGfx/FontDatabase.cpp @@ -24,24 +24,55 @@ FontDatabase& FontDatabase::the() return *s_the; } +static RefPtr s_default_font; +static String s_default_font_query; +static RefPtr s_fixed_width_font; +static String s_fixed_width_font_query; + +void FontDatabase::set_default_font_query(String query) +{ + if (s_default_font_query == query) + return; + s_default_font_query = move(query); + s_default_font = nullptr; +} + +String FontDatabase::default_font_query() +{ + return s_default_font_query; +} + Font& FontDatabase::default_font() { - static Font* font; - if (!font) { - font = FontDatabase::the().get_by_name("Katica 10 400"); - VERIFY(font); + if (!s_default_font) { + VERIFY(!s_default_font_query.is_empty()); + s_default_font = FontDatabase::the().get_by_name(s_default_font_query); + VERIFY(s_default_font); } - return *font; + return *s_default_font; +} + +void FontDatabase::set_fixed_width_font_query(String query) +{ + if (s_fixed_width_font_query == query) + return; + s_fixed_width_font_query = move(query); + s_fixed_width_font = nullptr; +} + +String FontDatabase::fixed_width_font_query() +{ + return s_fixed_width_font_query; } Font& FontDatabase::default_fixed_width_font() { - static Font* font; - if (!font) { - font = FontDatabase::the().get_by_name("Csilla 10 400"); - VERIFY(font); + if (!s_fixed_width_font) { + VERIFY(!s_fixed_width_font_query.is_empty()); + s_fixed_width_font = FontDatabase::the().get_by_name(s_fixed_width_font_query); + VERIFY(s_fixed_width_font); } - return *font; + return *s_fixed_width_font; } struct FontDatabase::Private { diff --git a/Userland/Libraries/LibGfx/FontDatabase.h b/Userland/Libraries/LibGfx/FontDatabase.h index 7ad5f8b691..4f75ee5c88 100644 --- a/Userland/Libraries/LibGfx/FontDatabase.h +++ b/Userland/Libraries/LibGfx/FontDatabase.h @@ -37,6 +37,11 @@ public: static Font& default_font(); static Font& default_fixed_width_font(); + static String default_font_query(); + static String fixed_width_font_query(); + static void set_default_font_query(String); + static void set_fixed_width_font_query(String); + RefPtr get(const String& family, unsigned size, unsigned weight); RefPtr get(const String& family, const String& variant, unsigned size); RefPtr get_by_name(const StringView&); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index d3c339811a..a3a76b7266 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -69,6 +70,7 @@ void OutOfProcessWebView::create_client() }; client().async_update_system_theme(Gfx::current_system_theme_buffer()); + client().async_update_system_fonts(Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query()); client().async_update_screen_rect(GUI::Desktop::the().rect()); } diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp index 4936eb6061..87289fe07a 100644 --- a/Userland/Services/WebContent/ClientConnection.cpp +++ b/Userland/Services/WebContent/ClientConnection.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,12 @@ void ClientConnection::update_system_theme(const Core::AnonymousBuffer& theme_bu m_page_host->set_palette_impl(*impl); } +void ClientConnection::update_system_fonts(String const& default_font_query, String const& fixed_width_font_query) +{ + Gfx::FontDatabase::set_default_font_query(default_font_query); + Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query); +} + void ClientConnection::update_screen_rect(const Gfx::IntRect& rect) { m_page_host->set_screen_rect(rect); diff --git a/Userland/Services/WebContent/ClientConnection.h b/Userland/Services/WebContent/ClientConnection.h index 3657b3dd1b..2fd7642bb5 100644 --- a/Userland/Services/WebContent/ClientConnection.h +++ b/Userland/Services/WebContent/ClientConnection.h @@ -34,6 +34,7 @@ private: virtual void greet() override; virtual void update_system_theme(Core::AnonymousBuffer const&) override; + virtual void update_system_fonts(String const&, String const&) override; virtual void update_screen_rect(Gfx::IntRect const&) override; virtual void load_url(URL const&) override; virtual void load_html(String const&, URL const&) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index 836af2815d..f144dd8c7d 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -3,6 +3,7 @@ endpoint WebContentServer greet() => () update_system_theme(Core::AnonymousBuffer theme_buffer) =| + update_system_fonts(String default_font_query, String fixed_width_font_query) =| update_screen_rect(Gfx::IntRect rect) =| load_url(URL url) =| diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 0132c3a872..8537c21124 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -54,7 +54,7 @@ ClientConnection::ClientConnection(NonnullRefPtr client_socke s_connections = new HashMap>; s_connections->set(client_id, *this); - async_fast_greet(Screen::the().rect(), Gfx::current_system_theme_buffer()); + async_fast_greet(Screen::the().rect(), Gfx::current_system_theme_buffer(), Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query()); } ClientConnection::~ClientConnection() diff --git a/Userland/Services/WindowServer/WindowClient.ipc b/Userland/Services/WindowServer/WindowClient.ipc index b4dfe9548c..f54b0fccd3 100644 --- a/Userland/Services/WindowServer/WindowClient.ipc +++ b/Userland/Services/WindowServer/WindowClient.ipc @@ -1,6 +1,6 @@ endpoint WindowClient { - fast_greet(Gfx::IntRect screen_rect, Core::AnonymousBuffer theme_buffer) =| + fast_greet(Gfx::IntRect screen_rect, Core::AnonymousBuffer theme_buffer, String default_font_query, String fixed_width_font_query) =| paint(i32 window_id, Gfx::IntSize window_size, Vector rects) =| mouse_move(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta, bool is_drag, Vector mime_types) =| @@ -35,6 +35,7 @@ endpoint WindowClient drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] String text, HashMap mime_data) =| update_system_theme(Core::AnonymousBuffer theme_buffer) =| + update_system_fonts(String default_font_query, String fixed_width_font_query) =| display_link_notification() =| diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp index 57c4f0fe7f..8d61225218 100644 --- a/Userland/Services/WindowServer/main.cpp +++ b/Userland/Services/WindowServer/main.cpp @@ -62,6 +62,9 @@ int main(int, char**) Gfx::set_system_theme(theme); auto palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme); + Gfx::FontDatabase::set_default_font_query("Katica 10 400"); + Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400"); + WindowServer::EventLoop loop; if (pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc", nullptr) < 0) {