mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
WindowServer+LibGUI: Add an IPC API to change the current system fonts
This patch adds a set_system_fonts() IPC API that takes the two main font queries as parameters. We'll probably expand this with additional queries when we figure out what they should be. Note that changing the system fonts on a live system mostly takes effect in newly launched programs. This is because GUI::Widget will currently cache a pointer to the Gfx::FontDatabase::default_font() when first constructed. This is something we'll have to fix somehow. Also note that the settings are not yet persisted.
This commit is contained in:
parent
bb23e61fbf
commit
c778130d63
6 changed files with 39 additions and 8 deletions
|
@ -70,6 +70,7 @@ void WindowServerConnection::update_system_fonts(const String& default_font_quer
|
||||||
{
|
{
|
||||||
Gfx::FontDatabase::set_default_font_query(default_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_fixed_width_font_query(fixed_width_font_query);
|
||||||
|
Window::update_all_windows({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowServerConnection::paint(i32 window_id, Gfx::IntSize const& window_size, Vector<Gfx::IntRect> const& rects)
|
void WindowServerConnection::paint(i32 window_id, Gfx::IntSize const& window_size, Vector<Gfx::IntRect> const& rects)
|
||||||
|
|
|
@ -706,6 +706,27 @@ Messages::WindowServer::GetSystemThemeResponse ClientConnection::get_system_them
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Messages::WindowServer::SetSystemFontsResponse ClientConnection::set_system_fonts(String const& default_font_query, String const& fixed_width_font_query)
|
||||||
|
{
|
||||||
|
if (!Gfx::FontDatabase::the().get_by_name(default_font_query)
|
||||||
|
|| !Gfx::FontDatabase::the().get_by_name(fixed_width_font_query)) {
|
||||||
|
dbgln("Received unusable font queries: '{}' and '{}'", default_font_query, fixed_width_font_query);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln("Updating fonts: '{}' and '{}'", default_font_query, fixed_width_font_query);
|
||||||
|
|
||||||
|
Gfx::FontDatabase::set_default_font_query(default_font_query);
|
||||||
|
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
|
||||||
|
|
||||||
|
ClientConnection::for_each_client([&](auto& client) {
|
||||||
|
client.async_update_system_fonts(default_font_query, fixed_width_font_query);
|
||||||
|
});
|
||||||
|
|
||||||
|
WindowManager::the().invalidate_after_theme_or_font_change();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ClientConnection::set_window_base_size_and_size_increment(i32 window_id, Gfx::IntSize const& base_size, Gfx::IntSize const& size_increment)
|
void ClientConnection::set_window_base_size_and_size_increment(i32 window_id, Gfx::IntSize const& base_size, Gfx::IntSize const& size_increment)
|
||||||
{
|
{
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
|
|
|
@ -133,6 +133,7 @@ private:
|
||||||
virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap<String, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
|
virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap<String, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
|
||||||
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(String const&, String const&) override;
|
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(String const&, String const&) override;
|
||||||
virtual Messages::WindowServer::GetSystemThemeResponse get_system_theme() override;
|
virtual Messages::WindowServer::GetSystemThemeResponse get_system_theme() override;
|
||||||
|
virtual Messages::WindowServer::SetSystemFontsResponse set_system_fonts(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_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 set_window_resize_aspect_ratio(i32, Optional<Gfx::IntSize> const&) override;
|
||||||
virtual void enable_display_link() override;
|
virtual void enable_display_link() override;
|
||||||
|
|
|
@ -1543,13 +1543,8 @@ Gfx::IntRect WindowManager::dnd_rect() const
|
||||||
return Gfx::IntRect(location, { width, height }).inflated(16, 8);
|
return Gfx::IntRect(location, { width, height }).inflated(16, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowManager::update_theme(String theme_path, String theme_name)
|
void WindowManager::invalidate_after_theme_or_font_change()
|
||||||
{
|
{
|
||||||
auto new_theme = Gfx::load_system_theme(theme_path);
|
|
||||||
if (!new_theme.is_valid())
|
|
||||||
return false;
|
|
||||||
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());
|
Compositor::the().set_background_color(palette().desktop_background().to_string());
|
||||||
HashTable<ClientConnection*> notified_clients;
|
HashTable<ClientConnection*> notified_clients;
|
||||||
WindowFrame::reload_config();
|
WindowFrame::reload_config();
|
||||||
|
@ -1565,11 +1560,21 @@ bool WindowManager::update_theme(String theme_path, String theme_name)
|
||||||
});
|
});
|
||||||
MenuManager::the().did_change_theme();
|
MenuManager::the().did_change_theme();
|
||||||
AppletManager::the().did_change_theme();
|
AppletManager::the().did_change_theme();
|
||||||
|
Compositor::the().invalidate_occlusions();
|
||||||
|
Compositor::the().invalidate_screen();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowManager::update_theme(String theme_path, String theme_name)
|
||||||
|
{
|
||||||
|
auto new_theme = Gfx::load_system_theme(theme_path);
|
||||||
|
if (!new_theme.is_valid())
|
||||||
|
return false;
|
||||||
|
Gfx::set_system_theme(new_theme);
|
||||||
|
m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme);
|
||||||
auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini");
|
auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini");
|
||||||
wm_config->write_entry("Theme", "Name", theme_name);
|
wm_config->write_entry("Theme", "Name", theme_name);
|
||||||
wm_config->sync();
|
wm_config->sync();
|
||||||
Compositor::the().invalidate_occlusions();
|
invalidate_after_theme_or_font_change();
|
||||||
Compositor::the().invalidate_screen();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update_theme(String theme_path, String theme_name);
|
bool update_theme(String theme_path, String theme_name);
|
||||||
|
void invalidate_after_theme_or_font_change();
|
||||||
|
|
||||||
bool set_hovered_window(Window*);
|
bool set_hovered_window(Window*);
|
||||||
void deliver_mouse_event(Window& window, MouseEvent& event, bool process_double_click);
|
void deliver_mouse_event(Window& window, MouseEvent& event, bool process_double_click);
|
||||||
|
|
|
@ -104,6 +104,8 @@ endpoint WindowServer
|
||||||
get_system_theme() => ([UTF8] String theme_name)
|
get_system_theme() => ([UTF8] String theme_name)
|
||||||
refresh_system_theme() =|
|
refresh_system_theme() =|
|
||||||
|
|
||||||
|
set_system_fonts(String default_font_query, String fixed_width_font_query) => (bool success)
|
||||||
|
|
||||||
set_window_base_size_and_size_increment(i32 window_id, Gfx::IntSize base_size, Gfx::IntSize size_increment) =|
|
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) =|
|
set_window_resize_aspect_ratio(i32 window_id, Optional<Gfx::IntSize> resize_aspect_ratio) =|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue