mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +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
|
@ -31,15 +31,26 @@ void set_system_theme(Core::AnonymousBuffer buffer)
|
|||
theme_page = theme_buffer.data<SystemTheme>();
|
||||
}
|
||||
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file, Optional<DeprecatedString> const& color_scheme)
|
||||
{
|
||||
auto buffer = TRY(Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme)));
|
||||
|
||||
auto* data = buffer.data<SystemTheme>();
|
||||
|
||||
auto get_color = [&](auto& name) {
|
||||
if (color_scheme.has_value()) {
|
||||
if (color_scheme.value().length() > 255)
|
||||
return Error::from_string_literal("Passed an excessively long color scheme pathname");
|
||||
if (color_scheme.value() != "Custom"sv)
|
||||
memcpy(data->path[(int)PathRole::ColorScheme], color_scheme.value().characters(), color_scheme.value().length());
|
||||
else
|
||||
memcpy(buffer.data<SystemTheme>(), theme_buffer.data<SystemTheme>(), sizeof(SystemTheme));
|
||||
}
|
||||
|
||||
auto get_color = [&](auto& name) -> Optional<Color> {
|
||||
auto color_string = file.read_entry("Colors", name);
|
||||
auto color = Color::from_string(color_string);
|
||||
if (color_scheme.has_value() && color_scheme.value() == "Custom"sv)
|
||||
return color;
|
||||
if (!color.has_value()) {
|
||||
auto maybe_color_config = Core::ConfigFile::open(data->path[(int)PathRole::ColorScheme]);
|
||||
if (maybe_color_config.is_error())
|
||||
|
@ -135,11 +146,16 @@ ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
|||
ENCODE_PATH(TaskbarShadow, true);
|
||||
ENCODE_PATH(MenuShadow, true);
|
||||
ENCODE_PATH(TooltipShadow, true);
|
||||
ENCODE_PATH(ColorScheme, true);
|
||||
if (!color_scheme.has_value())
|
||||
ENCODE_PATH(ColorScheme, true);
|
||||
|
||||
#undef __ENUMERATE_COLOR_ROLE
|
||||
#define __ENUMERATE_COLOR_ROLE(role) \
|
||||
data->color[(int)ColorRole::role] = get_color(#role).value();
|
||||
#define __ENUMERATE_COLOR_ROLE(role) \
|
||||
{ \
|
||||
Optional<Color> result = get_color(#role); \
|
||||
if (result.has_value()) \
|
||||
data->color[(int)ColorRole::role] = result.value().value(); \
|
||||
}
|
||||
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
|
||||
#undef __ENUMERATE_COLOR_ROLE
|
||||
|
||||
|
@ -150,8 +166,11 @@ ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
|||
#undef __ENUMERATE_ALIGNMENT_ROLE
|
||||
|
||||
#undef __ENUMERATE_FLAG_ROLE
|
||||
#define __ENUMERATE_FLAG_ROLE(role) \
|
||||
data->flag[(int)FlagRole::role] = get_flag(#role);
|
||||
#define __ENUMERATE_FLAG_ROLE(role) \
|
||||
{ \
|
||||
if (#role != "BoldTextAsBright"sv) \
|
||||
data->flag[(int)FlagRole::role] = get_flag(#role); \
|
||||
}
|
||||
ENUMERATE_FLAG_ROLES(__ENUMERATE_FLAG_ROLE)
|
||||
#undef __ENUMERATE_FLAG_ROLE
|
||||
|
||||
|
@ -161,20 +180,21 @@ ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
|||
ENUMERATE_METRIC_ROLES(__ENUMERATE_METRIC_ROLE)
|
||||
#undef __ENUMERATE_METRIC_ROLE
|
||||
|
||||
data->flag[(int)FlagRole::BoldTextAsBright] = true;
|
||||
auto maybe_color_config = Core::ConfigFile::open(data->path[(int)PathRole::ColorScheme]);
|
||||
if (!maybe_color_config.is_error()) {
|
||||
auto color_config = maybe_color_config.release_value();
|
||||
data->flag[(int)FlagRole::BoldTextAsBright] = color_config->read_bool_entry("Options", "ShowBoldTextAsBright", true);
|
||||
if (!color_scheme.has_value() || color_scheme.value() != "Custom"sv) {
|
||||
auto maybe_color_config = Core::ConfigFile::open(data->path[(int)PathRole::ColorScheme]);
|
||||
if (!maybe_color_config.is_error()) {
|
||||
auto color_config = maybe_color_config.release_value();
|
||||
data->flag[(int)FlagRole::BoldTextAsBright] = color_config->read_bool_entry("Options", "ShowBoldTextAsBright", true);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(DeprecatedString const& path)
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(DeprecatedString const& path, Optional<DeprecatedString> const& color_scheme)
|
||||
{
|
||||
auto config_file = TRY(Core::ConfigFile::open(path));
|
||||
return TRY(load_system_theme(config_file));
|
||||
return TRY(load_system_theme(config_file, color_scheme));
|
||||
}
|
||||
|
||||
ErrorOr<Vector<SystemThemeMetaData>> list_installed_system_themes()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue