1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

WindowServer: New title bar vars for themes

The theming system can now control title bar height, title button
size, title stripe color and the title text shadow color.
The implemented theme metrics system could be later extended to LibGUI
to allow themes to change widget padding, border width, etc.
This commit is contained in:
Nullspeak 2020-07-17 10:27:55 +10:00 committed by Andreas Kling
parent 8e364b9780
commit 51b2b0d5e5
7 changed files with 142 additions and 10 deletions

View file

@ -61,6 +61,12 @@ Color PaletteImpl::color(ColorRole role) const
return theme().color[(int)role];
}
int PaletteImpl::metric(MetricRole role) const
{
ASSERT((int)role < (int)MetricRole::__Count);
return theme().metric[(int)role];
}
NonnullRefPtr<PaletteImpl> PaletteImpl::clone() const
{
auto new_theme_buffer = SharedBuffer::create_with_size(m_theme_buffer->size());
@ -76,6 +82,14 @@ void Palette::set_color(ColorRole role, Color color)
theme.color[(int)role] = color;
}
void Palette::set_metric(MetricRole role, int value)
{
if (m_impl->ref_count() != 1)
m_impl = m_impl->clone();
auto& theme = const_cast<SystemTheme&>(impl().theme());
theme.metric[(int)role] = value;
}
PaletteImpl::~PaletteImpl()
{
}

View file

@ -44,6 +44,7 @@ public:
NonnullRefPtr<PaletteImpl> clone() const;
Color color(ColorRole) const;
int metric(MetricRole) const;
const SystemTheme& theme() const;
void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer);
@ -79,6 +80,8 @@ public:
Color highlight_window_border1() const { return color(ColorRole::HighlightWindowBorder1); }
Color highlight_window_border2() const { return color(ColorRole::HighlightWindowBorder2); }
Color highlight_window_title() const { return color(ColorRole::HighlightWindowTitle); }
Color window_title_stripes() const { return color(ColorRole::WindowTitleStripes); }
Color window_title_shadow() const { return color(ColorRole::WindowTitleShadow); }
Color menu_stripe() const { return color(ColorRole::MenuStripe); }
Color menu_base() const { return color(ColorRole::MenuBase); }
Color menu_base_text() const { return color(ColorRole::MenuBaseText); }
@ -117,9 +120,15 @@ public:
Color syntax_preprocessor_statement() const { return color(ColorRole::SyntaxPreprocessorStatement); }
Color syntax_preprocessor_value() const { return color(ColorRole::SyntaxPreprocessorValue); }
int window_title_height() const { return metric(MetricRole::TitleHeight); }
int window_title_button_width() const { return metric(MetricRole::TitleButtonWidth); }
int window_title_button_height() const { return metric(MetricRole::TitleButtonHeight); }
Color color(ColorRole role) const { return m_impl->color(role); }
int metric(MetricRole role) const { return m_impl->metric(role); }
void set_color(ColorRole, Color);
void set_metric(MetricRole, int);
const SystemTheme& theme() const { return m_impl->theme(); }

View file

@ -67,6 +67,24 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
return color.value();
};
auto get_metric = [&](auto& name, auto role) {
int metric = file->read_num_entry("Metrics", name, -1);
if (metric == -1) {
switch (role) {
case (int)MetricRole::TitleHeight:
return 19;
case (int)MetricRole::TitleButtonHeight:
return 15;
case (int)MetricRole::TitleButtonWidth:
return 15;
default:
dbg() << "Metric " << name << " has no fallback value!";
return 16;
}
}
return metric;
};
#define DO_COLOR(x) \
data->color[(int)ColorRole::x] = get_color(#x)
@ -98,6 +116,8 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
DO_COLOR(HighlightWindowBorder1);
DO_COLOR(HighlightWindowBorder2);
DO_COLOR(HighlightWindowTitle);
DO_COLOR(WindowTitleShadow);
DO_COLOR(WindowTitleStripes);
DO_COLOR(MenuStripe);
DO_COLOR(MenuBase);
DO_COLOR(MenuBaseText);
@ -126,6 +146,13 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
DO_COLOR(SyntaxPreprocessorStatement);
DO_COLOR(SyntaxPreprocessorValue);
#define DO_METRIC(x) \
data->metric[(int)MetricRole::x] = get_metric(#x, (int)MetricRole::x)
DO_METRIC(TitleHeight);
DO_METRIC(TitleButtonWidth);
DO_METRIC(TitleButtonHeight);
buffer->seal();
buffer->share_globally();

View file

@ -47,6 +47,8 @@ enum class ColorRole {
HighlightWindowBorder1,
HighlightWindowBorder2,
HighlightWindowTitle,
WindowTitleShadow,
WindowTitleStripes,
MenuStripe,
MenuBase,
MenuBaseText,
@ -95,8 +97,17 @@ enum class ColorRole {
DisabledText = ThreedShadow1,
};
enum class MetricRole {
NoRole,
TitleHeight,
TitleButtonWidth,
TitleButtonHeight,
__Count,
};
struct SystemTheme {
Color color[(int)ColorRole::__Count];
int metric[(int)MetricRole::__Count];
};
const SystemTheme& current_system_theme();