Userland+Base: Make the window titlebar font configurable separately

Instead of defaulting to "bold variant of the system default font",
let's allow the user to set any font they want as the titlebar font.
This commit is contained in:
Andreas Kling 2022-07-31 18:41:07 +02:00
parent 419e986dcc
commit 548081ea23
20 changed files with 107 additions and 21 deletions

View file

@ -12,6 +12,7 @@ ScaleFactor=1
[Fonts]
Default=Katica 10 400 0
WindowTitle=Katica 10 700 0
FixedWidth=Csilla 10 400 0
[Theme]

View file

@ -33,6 +33,34 @@
}
}
@GUI::Widget {
preferred_height: "fit"
layout: @GUI::HorizontalBoxLayout {
spacing: 6
}
@GUI::Label {
fixed_width: 100
text: "Window title font:"
text_alignment: "CenterLeft"
}
@GUI::Label {
background_role: "Base"
shadow: "Sunken"
shape: "Container"
thickness: 2
fill_with_background_color: true
name: "window_title_font_label"
}
@GUI::Button {
text: "..."
name: "window_title_font_button"
fixed_width: 30
}
}
@GUI::Widget {
preferred_height: "fit"
layout: @GUI::HorizontalBoxLayout {

View file

@ -34,6 +34,19 @@ FontSettingsWidget::FontSettingsWidget()
}
};
auto& window_title_font = Gfx::FontDatabase::window_title_font();
m_window_title_font_label = *find_descendant_of_type_named<GUI::Label>("window_title_font_label");
update_label_with_font(*m_window_title_font_label, window_title_font);
auto& window_title_font_button = *find_descendant_of_type_named<GUI::Button>("window_title_font_button");
window_title_font_button.on_click = [this](auto) {
auto font_picker = GUI::FontPicker::construct(window(), &m_window_title_font_label->font(), false);
if (font_picker->exec() == GUI::Dialog::ExecResult::OK) {
update_label_with_font(*m_window_title_font_label, *font_picker->font());
set_modified(true);
}
};
auto& default_fixed_width_font = Gfx::FontDatabase::default_fixed_width_font();
m_fixed_width_font_label = *find_descendant_of_type_named<GUI::Label>("fixed_width_font_label");
update_label_with_font(*m_fixed_width_font_label, default_fixed_width_font);
@ -56,7 +69,10 @@ static void update_label_with_font(GUI::Label& label, Gfx::Font const& font)
void FontSettingsWidget::apply_settings()
{
GUI::ConnectionToWindowServer::the().set_system_fonts(m_default_font_label->font().qualified_name(), m_fixed_width_font_label->font().qualified_name());
GUI::ConnectionToWindowServer::the().set_system_fonts(
m_default_font_label->font().qualified_name(),
m_fixed_width_font_label->font().qualified_name(),
m_window_title_font_label->font().qualified_name());
}
}

View file

@ -24,6 +24,7 @@ private:
FontSettingsWidget();
RefPtr<GUI::Label> m_default_font_label;
RefPtr<GUI::Label> m_window_title_font_label;
RefPtr<GUI::Label> m_fixed_width_font_label;
};

View file

@ -52,10 +52,11 @@ ConnectionToWindowServer::ConnectionToWindowServer(NonnullOwnPtr<Core::Stream::L
Desktop::the().did_receive_screen_rects({}, message->screen_rects(), message->main_screen_index(), message->workspace_rows(), message->workspace_columns());
Gfx::FontDatabase::set_default_font_query(message->default_font_query());
Gfx::FontDatabase::set_fixed_width_font_query(message->fixed_width_font_query());
Gfx::FontDatabase::set_window_title_font_query(message->window_title_font_query());
m_client_id = message->client_id();
}
void ConnectionToWindowServer::fast_greet(Vector<Gfx::IntRect> const&, u32, u32, u32, Core::AnonymousBuffer const&, String const&, String const&, i32)
void ConnectionToWindowServer::fast_greet(Vector<Gfx::IntRect> const&, u32, u32, u32, Core::AnonymousBuffer const&, String const&, String const&, String const&, i32)
{
// NOTE: This message is handled in the constructor.
}
@ -71,10 +72,11 @@ void ConnectionToWindowServer::update_system_theme(Core::AnonymousBuffer const&
Application::the()->dispatch_event(*make<ThemeChangeEvent>());
}
void ConnectionToWindowServer::update_system_fonts(String const& default_font_query, String const& fixed_width_font_query)
void ConnectionToWindowServer::update_system_fonts(String const& default_font_query, String const& fixed_width_font_query, String const& window_title_font_query)
{
Gfx::FontDatabase::set_default_font_query(default_font_query);
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
Gfx::FontDatabase::set_window_title_font_query(window_title_font_query);
Window::update_all_windows({});
Window::for_each_window({}, [](auto& window) {
Core::EventLoop::current().post_event(window, make<FontsChangeEvent>());

View file

@ -24,7 +24,7 @@ public:
private:
ConnectionToWindowServer(NonnullOwnPtr<Core::Stream::LocalSocket>);
virtual void fast_greet(Vector<Gfx::IntRect> const&, u32, u32, u32, Core::AnonymousBuffer const&, String const&, String const&, i32) override;
virtual void fast_greet(Vector<Gfx::IntRect> const&, u32, u32, u32, Core::AnonymousBuffer const&, String const&, String const&, String const&, i32) 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, i32, i32, i32, bool, Vector<String> const&) override;
virtual void mouse_down(i32, Gfx::IntPoint const&, u32, u32, u32, i32, i32, i32, i32) override;
@ -52,7 +52,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 update_system_fonts(String const&, String const&, String const&) override;
virtual void window_state_changed(i32, bool, bool, bool) override;
virtual void display_link_notification() override;
virtual void track_mouse_move(Gfx::IntPoint const&) override;

View file

@ -51,7 +51,7 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
frame_rect.set_location({ 0, 0 });
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
auto titlebar_rect = this->titlebar_rect(WindowType::Normal, window_rect, palette);
auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_rect, palette);
@ -118,7 +118,7 @@ void ClassicWindowTheme::paint_tool_window_frame(Painter& painter, WindowState w
frame_rect.set_location({ 0, 0 });
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
auto titlebar_rect = this->titlebar_rect(WindowType::ToolWindow, window_rect, palette);
auto titlebar_inner_rect = titlebar_text_rect(WindowType::ToolWindow, window_rect, palette);
@ -152,7 +152,7 @@ IntRect ClassicWindowTheme::menubar_rect(WindowType window_type, IntRect const&
IntRect ClassicWindowTheme::titlebar_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const
{
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
auto window_titlebar_height = titlebar_height(window_type, palette);
// FIXME: The top of the titlebar doesn't get redrawn properly if this padding is different
int total_vertical_padding = title_font.glyph_height() - 1;
@ -254,7 +254,7 @@ Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, IntRe
int ClassicWindowTheme::titlebar_height(WindowType window_type, Palette const& palette) const
{
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
switch (window_type) {
case WindowType::Normal:
case WindowType::Notification:

View file

@ -25,8 +25,13 @@ FontDatabase& FontDatabase::the()
static RefPtr<Font> s_default_font;
static String s_default_font_query;
static RefPtr<Font> s_window_title_font;
static String s_window_title_font_query;
static RefPtr<Font> s_fixed_width_font;
static String s_fixed_width_font_query;
static String s_default_fonts_lookup_path = "/res/fonts";
void FontDatabase::set_default_font_query(String query)
@ -42,6 +47,19 @@ String FontDatabase::default_font_query()
return s_default_font_query;
}
void FontDatabase::set_window_title_font_query(String query)
{
if (s_window_title_font_query == query)
return;
s_window_title_font_query = move(query);
s_window_title_font = nullptr;
}
String FontDatabase::window_title_font_query()
{
return s_window_title_font_query;
}
void FontDatabase::set_default_fonts_lookup_path(String path)
{
if (s_default_fonts_lookup_path == path)
@ -64,6 +82,16 @@ Font& FontDatabase::default_font()
return *s_default_font;
}
Font& FontDatabase::window_title_font()
{
if (!s_window_title_font) {
VERIFY(!s_window_title_font_query.is_empty());
s_window_title_font = FontDatabase::the().get_by_name(s_window_title_font_query);
VERIFY(s_window_title_font);
}
return *s_window_title_font;
}
void FontDatabase::set_fixed_width_font_query(String query)
{
if (s_fixed_width_font_query == query)

View file

@ -36,11 +36,15 @@ public:
static Font& default_font();
static Font& default_fixed_width_font();
static Font& window_title_font();
static String default_font_query();
static String window_title_font_query();
static String fixed_width_font_query();
static String default_fonts_lookup_path();
static void set_default_font_query(String);
static void set_window_title_font_query(String);
static void set_fixed_width_font_query(String);
static void set_default_fonts_lookup_path(String);

View file

@ -69,7 +69,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_system_fonts(Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query(), Gfx::FontDatabase::window_title_font_query());
client().async_update_screen_rects(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index());
}

View file

@ -65,10 +65,11 @@ void ConnectionFromClient::update_system_theme(Core::AnonymousBuffer const& them
m_page_host->set_palette_impl(*impl);
}
void ConnectionFromClient::update_system_fonts(String const& default_font_query, String const& fixed_width_font_query)
void ConnectionFromClient::update_system_fonts(String const& default_font_query, String const& fixed_width_font_query, String const& window_title_font_query)
{
Gfx::FontDatabase::set_default_font_query(default_font_query);
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
Gfx::FontDatabase::set_window_title_font_query(window_title_font_query);
}
void ConnectionFromClient::update_screen_rects(Vector<Gfx::IntRect> const& rects, u32 main_screen)

View file

@ -41,7 +41,7 @@ private:
Web::Page const& page() const;
virtual void update_system_theme(Core::AnonymousBuffer const&) override;
virtual void update_system_fonts(String const&, String const&) override;
virtual void update_system_fonts(String const&, String const&, String const&) override;
virtual void update_screen_rects(Vector<Gfx::IntRect> const&, u32) override;
virtual void load_url(URL const&) override;
virtual void load_html(String const&, URL const&) override;

View file

@ -8,7 +8,7 @@
endpoint WebContentServer
{
update_system_theme(Core::AnonymousBuffer theme_buffer) =|
update_system_fonts(String default_font_query, String fixed_width_font_query) =|
update_system_fonts(String default_font_query, String fixed_width_font_query, String window_title_font_query) =|
update_screen_rects(Vector<Gfx::IntRect> rects, u32 main_screen_index) =|
load_url(URL url) =|

View file

@ -53,7 +53,7 @@ ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSock
s_connections->set(client_id, *this);
auto& wm = WindowManager::the();
async_fast_greet(Screen::rects(), Screen::main().index(), wm.window_stack_rows(), wm.window_stack_columns(), Gfx::current_system_theme_buffer(), Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query(), client_id);
async_fast_greet(Screen::rects(), Screen::main().index(), wm.window_stack_rows(), wm.window_stack_columns(), Gfx::current_system_theme_buffer(), Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query(), Gfx::FontDatabase::window_title_font_query(), client_id);
}
ConnectionFromClient::~ConnectionFromClient()
@ -891,7 +891,7 @@ Messages::WindowServer::GetCursorThemeResponse ConnectionFromClient::get_cursor_
return name;
}
Messages::WindowServer::SetSystemFontsResponse ConnectionFromClient::set_system_fonts(String const& default_font_query, String const& fixed_width_font_query)
Messages::WindowServer::SetSystemFontsResponse ConnectionFromClient::set_system_fonts(String const& default_font_query, String const& fixed_width_font_query, String const& window_title_font_query)
{
if (!Gfx::FontDatabase::the().get_by_name(default_font_query)
|| !Gfx::FontDatabase::the().get_by_name(fixed_width_font_query)) {
@ -903,9 +903,10 @@ Messages::WindowServer::SetSystemFontsResponse ConnectionFromClient::set_system_
Gfx::FontDatabase::set_default_font_query(default_font_query);
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
Gfx::FontDatabase::set_window_title_font_query(window_title_font_query);
ConnectionFromClient::for_each_client([&](auto& client) {
client.async_update_system_fonts(default_font_query, fixed_width_font_query);
client.async_update_system_fonts(default_font_query, fixed_width_font_query, window_title_font_query);
});
WindowManager::the().invalidate_after_theme_or_font_change();
@ -918,6 +919,7 @@ Messages::WindowServer::SetSystemFontsResponse ConnectionFromClient::set_system_
auto wm_config = wm_config_or_error.release_value();
wm_config->write_entry("Fonts", "Default", default_font_query);
wm_config->write_entry("Fonts", "FixedWidth", fixed_width_font_query);
wm_config->write_entry("Fonts", "WindowTitle", window_title_font_query);
return true;
}

View file

@ -154,7 +154,7 @@ private:
virtual void set_cursor_highlight_color(Gfx::Color const& color) override;
virtual Messages::WindowServer::GetCursorHighlightColorResponse get_cursor_highlight_color() override;
virtual Messages::WindowServer::GetCursorThemeResponse get_cursor_theme() override;
virtual Messages::WindowServer::SetSystemFontsResponse set_system_fonts(String const&, String const&) override;
virtual Messages::WindowServer::SetSystemFontsResponse set_system_fonts(String const&, String const&, String const&) override;
virtual void set_window_base_size_and_size_increment(i32, Gfx::IntSize const&, Gfx::IntSize const&) override;
virtual void set_window_resize_aspect_ratio(i32, Optional<Gfx::IntSize> const&) override;
virtual void enable_display_link() override;

View file

@ -3,7 +3,7 @@
endpoint WindowClient
{
fast_greet(Vector<Gfx::IntRect> screen_rects, u32 main_screen_index, u32 workspace_rows, u32 workspace_columns, Core::AnonymousBuffer theme_buffer, String default_font_query, String fixed_width_font_query, i32 client_id) =|
fast_greet(Vector<Gfx::IntRect> screen_rects, u32 main_screen_index, u32 workspace_rows, u32 workspace_columns, Core::AnonymousBuffer theme_buffer, String default_font_query, String fixed_width_font_query, String window_title_font_query, i32 client_id) =|
paint(i32 window_id, Gfx::IntSize window_size, Vector<Gfx::IntRect> rects) =|
mouse_move(i32 window_id, Gfx::IntPoint mouse_position, u32 button, u32 buttons, u32 modifiers, i32 wheel_delta_x, i32 wheel_delta_y, i32 wheel_raw_delta_x, i32 wheel_raw_delta_y, bool is_drag, Vector<String> mime_types) =|
@ -40,7 +40,7 @@ endpoint WindowClient
drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] String text, HashMap<String,ByteBuffer> mime_data) =|
update_system_theme(Core::AnonymousBuffer theme_buffer) =|
update_system_fonts(String default_font_query, String fixed_width_font_query) =|
update_system_fonts(String default_font_query, String fixed_width_font_query, String window_title_font_query) =|
display_link_notification() =|

View file

@ -110,7 +110,7 @@ Gfx::Font const& WindowManager::font() const
Gfx::Font const& WindowManager::window_title_font() const
{
return Gfx::FontDatabase::default_font().bold_variant();
return Gfx::FontDatabase::window_title_font();
}
bool WindowManager::set_screen_layout(ScreenLayout&& screen_layout, bool save, String& error_msg)

View file

@ -143,7 +143,7 @@ endpoint WindowServer
set_cursor_highlight_color(Gfx::Color color) =|
get_cursor_highlight_color() => (Gfx::Color color)
set_system_fonts(String default_font_query, String fixed_width_font_query) => (bool success)
set_system_fonts(String default_font_query, String fixed_width_font_query, String window_title_font_query) => (bool success)
set_window_base_size_and_size_increment(i32 window_id, Gfx::IntSize base_size, Gfx::IntSize size_increment) =|
set_window_resize_aspect_ratio(i32 window_id, Optional<Gfx::IntSize> resize_aspect_ratio) =|

View file

@ -47,9 +47,11 @@ ErrorOr<int> serenity_main(Main::Arguments)
auto default_font_query = wm_config->read_entry("Fonts", "Default", "Katica 10 400 0");
auto fixed_width_font_query = wm_config->read_entry("Fonts", "FixedWidth", "Csilla 10 400 0");
auto window_title_font_query = wm_config->read_entry("Fonts", "WindowTitle", "Katica 10 700 0");
Gfx::FontDatabase::set_default_font_query(default_font_query);
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
Gfx::FontDatabase::set_window_title_font_query(window_title_font_query);
{
// FIXME: Map switched tty from screens.

View file

@ -689,6 +689,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
Gfx::FontDatabase::set_default_font_query("Katica 10 400 0");
Gfx::FontDatabase::set_window_title_font_query("Katica 10 700 0");
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");
if (!error_page_url.is_empty())