1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-08-10 16:47:35 +00:00

LibGfx+WindowServer: Have WindowServer broadcast system font settings

Instead of everybody getting their system fonts from Gfx::FontDatabase
(where it's all hardcoded), they now get it from WindowServer.

These are then plumbed into the usual Gfx::FontDatabase places so that
the old default_font() and default_fixed_width_font() APIs keep working.
This commit is contained in:
Andreas Kling 2021-05-21 18:10:23 +02:00
parent 66ad739934
commit bb23e61fbf
11 changed files with 76 additions and 15 deletions

View file

@ -21,6 +21,7 @@
#include <LibGUI/Window.h>
#include <LibGUI/WindowServerConnection.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/FontDatabase.h>
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
@ -47,9 +48,11 @@ void WindowServerConnection::handshake()
auto message = wait_for_specific_message<Messages::WindowClient::FastGreet>();
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<Gfx::IntRect> const& rects)
{
if (auto* window = Window::from_window_id(window_id))

View file

@ -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<Gfx::IntRect> const&) override;
virtual void mouse_move(i32, Gfx::IntPoint const&, u32, u32, u32, i32, bool, Vector<String> 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;

View file

@ -24,24 +24,55 @@ FontDatabase& FontDatabase::the()
return *s_the;
}
static RefPtr<Font> s_default_font;
static String s_default_font_query;
static RefPtr<Font> 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 {

View file

@ -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<Gfx::Font> get(const String& family, unsigned size, unsigned weight);
RefPtr<Gfx::Font> get(const String& family, const String& variant, unsigned size);
RefPtr<Gfx::Font> get_by_name(const StringView&);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -15,6 +15,7 @@
#include <LibGUI/Painter.h>
#include <LibGUI/Scrollbar.h>
#include <LibGUI/Window.h>
#include <LibGfx/FontDatabase.h>
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
@ -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());
}