mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:17:34 +00:00
Everywhere: Support overriding the system color scheme
This commit is contained in:
parent
fba0cee622
commit
e9e4baee77
15 changed files with 161 additions and 30 deletions
|
@ -865,9 +865,9 @@ void ConnectionFromClient::set_accepts_drag(bool accepts)
|
|||
wm.set_accepts_drag(accepts);
|
||||
}
|
||||
|
||||
Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(DeprecatedString const& theme_path, DeprecatedString const& theme_name, bool keep_desktop_background)
|
||||
Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(DeprecatedString const& theme_path, DeprecatedString const& theme_name, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path)
|
||||
{
|
||||
bool success = WindowManager::the().update_theme(theme_path, theme_name, keep_desktop_background);
|
||||
bool success = WindowManager::the().update_theme(theme_path, theme_name, keep_desktop_background, color_scheme_path);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -897,6 +897,11 @@ Messages::WindowServer::IsSystemThemeOverriddenResponse ConnectionFromClient::is
|
|||
return WindowManager::the().is_theme_overridden();
|
||||
}
|
||||
|
||||
Messages::WindowServer::GetPreferredColorSchemeResponse ConnectionFromClient::get_preferred_color_scheme()
|
||||
{
|
||||
return WindowManager::the().get_preferred_color_scheme();
|
||||
}
|
||||
|
||||
void ConnectionFromClient::apply_cursor_theme(DeprecatedString const& name)
|
||||
{
|
||||
WindowManager::the().apply_cursor_theme(name);
|
||||
|
|
|
@ -145,12 +145,13 @@ private:
|
|||
virtual void set_window_icon_bitmap(i32, Gfx::ShareableBitmap const&) override;
|
||||
virtual Messages::WindowServer::StartDragResponse start_drag(DeprecatedString const&, HashMap<DeprecatedString, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
|
||||
virtual void set_accepts_drag(bool) override;
|
||||
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(DeprecatedString const&, DeprecatedString const&, bool keep_desktop_background) override;
|
||||
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(DeprecatedString const&, DeprecatedString const&, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path) override;
|
||||
virtual Messages::WindowServer::GetSystemThemeResponse get_system_theme() override;
|
||||
virtual Messages::WindowServer::SetSystemThemeOverrideResponse set_system_theme_override(Core::AnonymousBuffer const&) override;
|
||||
virtual Messages::WindowServer::GetSystemThemeOverrideResponse get_system_theme_override() override;
|
||||
virtual void clear_system_theme_override() override;
|
||||
virtual Messages::WindowServer::IsSystemThemeOverriddenResponse is_system_theme_overridden() override;
|
||||
virtual Messages::WindowServer::GetPreferredColorSchemeResponse get_preferred_color_scheme() override;
|
||||
virtual void apply_cursor_theme(DeprecatedString const&) override;
|
||||
virtual void set_cursor_highlight_radius(int radius) override;
|
||||
virtual Messages::WindowServer::GetCursorHighlightRadiusResponse get_cursor_highlight_radius() override;
|
||||
|
|
|
@ -2077,9 +2077,9 @@ void WindowManager::invalidate_after_theme_or_font_change()
|
|||
Compositor::the().invalidate_after_theme_or_font_change();
|
||||
}
|
||||
|
||||
bool WindowManager::update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background)
|
||||
bool WindowManager::update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path)
|
||||
{
|
||||
auto error_or_new_theme = Gfx::load_system_theme(theme_path);
|
||||
auto error_or_new_theme = Gfx::load_system_theme(theme_path, color_scheme_path);
|
||||
if (error_or_new_theme.is_error()) {
|
||||
dbgln("WindowManager: Updating theme failed, error {}", error_or_new_theme.error());
|
||||
return false;
|
||||
|
@ -2089,6 +2089,15 @@ bool WindowManager::update_theme(DeprecatedString theme_path, DeprecatedString t
|
|||
Gfx::set_system_theme(new_theme);
|
||||
m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme);
|
||||
g_config->write_entry("Theme", "Name", theme_name);
|
||||
if (color_scheme_path.has_value() && color_scheme_path.value() != "Custom"sv) {
|
||||
g_config->write_bool_entry("Theme", "LoadCustomColorScheme", true);
|
||||
g_config->write_entry("Theme", "CustomColorSchemePath", color_scheme_path.value());
|
||||
m_preferred_color_scheme = color_scheme_path.value();
|
||||
} else if (!color_scheme_path.has_value()) {
|
||||
g_config->write_bool_entry("Theme", "LoadCustomColorScheme", false);
|
||||
g_config->remove_entry("Theme", "CustomColorSchemePath");
|
||||
m_preferred_color_scheme = OptionalNone();
|
||||
}
|
||||
if (!keep_desktop_background)
|
||||
g_config->remove_entry("Background", "Color");
|
||||
if (!sync_config_to_disk())
|
||||
|
@ -2119,7 +2128,7 @@ void WindowManager::clear_theme_override()
|
|||
{
|
||||
m_theme_overridden = false;
|
||||
auto previous_theme_name = g_config->read_entry("Theme", "Name");
|
||||
auto previous_theme = MUST(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", previous_theme_name)));
|
||||
auto previous_theme = MUST(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", previous_theme_name), m_preferred_color_scheme));
|
||||
Gfx::set_system_theme(previous_theme);
|
||||
m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(previous_theme);
|
||||
invalidate_after_theme_or_font_change();
|
||||
|
|
|
@ -201,13 +201,14 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background);
|
||||
bool update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path);
|
||||
void invalidate_after_theme_or_font_change();
|
||||
|
||||
bool set_theme_override(Core::AnonymousBuffer const& theme_override);
|
||||
Optional<Core::AnonymousBuffer> get_theme_override() const;
|
||||
void clear_theme_override();
|
||||
bool is_theme_overridden() { return m_theme_overridden; }
|
||||
Optional<DeprecatedString> get_preferred_color_scheme() { return m_preferred_color_scheme; }
|
||||
|
||||
bool set_hovered_window(Window*);
|
||||
void deliver_mouse_event(Window&, MouseEvent const&);
|
||||
|
@ -439,6 +440,7 @@ private:
|
|||
bool m_mouse_buttons_switched { false };
|
||||
bool m_natural_scroll { false };
|
||||
bool m_theme_overridden { false };
|
||||
Optional<DeprecatedString> m_preferred_color_scheme { OptionalNone() };
|
||||
|
||||
WeakPtr<Window> m_hovered_window;
|
||||
WeakPtr<Window> m_highlight_window;
|
||||
|
|
|
@ -130,7 +130,7 @@ endpoint WindowServer
|
|||
start_drag([UTF8] DeprecatedString text, HashMap<DeprecatedString,ByteBuffer> mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started)
|
||||
set_accepts_drag(bool accepts) =|
|
||||
|
||||
set_system_theme(DeprecatedString theme_path, [UTF8] DeprecatedString theme_name, bool keep_desktop_background) => (bool success)
|
||||
set_system_theme(DeprecatedString theme_path, [UTF8] DeprecatedString theme_name, bool keep_desktop_background, Optional<DeprecatedString> color_scheme_path) => (bool success)
|
||||
get_system_theme() => ([UTF8] DeprecatedString theme_name)
|
||||
refresh_system_theme() =|
|
||||
|
||||
|
@ -139,6 +139,8 @@ endpoint WindowServer
|
|||
clear_system_theme_override() =|
|
||||
is_system_theme_overridden() => (bool overridden)
|
||||
|
||||
get_preferred_color_scheme() => (Optional<DeprecatedString> path)
|
||||
|
||||
apply_cursor_theme(DeprecatedString name) =|
|
||||
get_cursor_theme() => (DeprecatedString name)
|
||||
|
||||
|
|
|
@ -47,7 +47,11 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
|||
WindowServer::g_config = TRY(Core::ConfigFile::open("/etc/WindowServer.ini", Core::ConfigFile::AllowWriting::Yes));
|
||||
auto theme_name = WindowServer::g_config->read_entry("Theme", "Name", "Default");
|
||||
|
||||
auto theme = TRY(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", theme_name)));
|
||||
Optional<DeprecatedString> custom_color_scheme_path = OptionalNone();
|
||||
if (WindowServer::g_config->read_bool_entry("Theme", "LoadCustomColorScheme", false))
|
||||
custom_color_scheme_path = WindowServer::g_config->read_entry("Theme", "CustomColorSchemePath");
|
||||
|
||||
auto theme = TRY(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", theme_name), custom_color_scheme_path));
|
||||
Gfx::set_system_theme(theme);
|
||||
auto palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue