diff --git a/Userland/Libraries/LibGUI/WindowServerConnection.cpp b/Userland/Libraries/LibGUI/WindowServerConnection.cpp index ac9ff33b5a..4b4e699d07 100644 --- a/Userland/Libraries/LibGUI/WindowServerConnection.cpp +++ b/Userland/Libraries/LibGUI/WindowServerConnection.cpp @@ -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_fixed_width_font_query(fixed_width_font_query); + Window::update_all_windows({}); } void WindowServerConnection::paint(i32 window_id, Gfx::IntSize const& window_size, Vector const& rects) diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 8537c21124..5fda635acb 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -706,6 +706,27 @@ Messages::WindowServer::GetSystemThemeResponse ClientConnection::get_system_them 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) { auto it = m_windows.find(window_id); diff --git a/Userland/Services/WindowServer/ClientConnection.h b/Userland/Services/WindowServer/ClientConnection.h index 46e69bed5f..d762784299 100644 --- a/Userland/Services/WindowServer/ClientConnection.h +++ b/Userland/Services/WindowServer/ClientConnection.h @@ -133,6 +133,7 @@ private: virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap const&, Gfx::ShareableBitmap 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::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_resize_aspect_ratio(i32, Optional const&) override; virtual void enable_display_link() override; diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 6ccdae3799..329de51146 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1543,13 +1543,8 @@ Gfx::IntRect WindowManager::dnd_rect() const 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()); HashTable notified_clients; WindowFrame::reload_config(); @@ -1565,11 +1560,21 @@ bool WindowManager::update_theme(String theme_path, String theme_name) }); MenuManager::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"); wm_config->write_entry("Theme", "Name", theme_name); wm_config->sync(); - Compositor::the().invalidate_occlusions(); - Compositor::the().invalidate_screen(); + invalidate_after_theme_or_font_change(); return true; } diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index f5bd3032d1..36b7378e40 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -182,6 +182,7 @@ public: } bool update_theme(String theme_path, String theme_name); + void invalidate_after_theme_or_font_change(); bool set_hovered_window(Window*); void deliver_mouse_event(Window& window, MouseEvent& event, bool process_double_click); diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index bb8b70dd90..fcfe88d9ed 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -104,6 +104,8 @@ endpoint WindowServer get_system_theme() => ([UTF8] String theme_name) 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_resize_aspect_ratio(i32 window_id, Optional resize_aspect_ratio) =|