1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

WindowServer+LibGUI: Implement basic color theming

Color themes are loaded from .ini files in /res/themes/
The theme can be switched from the "Themes" section in the system menu.

The basic mechanism is that WindowServer broadcasts a SharedBuffer with
all of the color values of the current theme. Clients receive this with
the response to their initial WindowServer::Greet handshake.

When the theme is changed, WindowServer tells everyone by sending out
an UpdateSystemTheme message with a new SharedBuffer to use.

This does feel somewhat bloated somehow, but I'm sure we can iterate on
it over time and improve things.

To get one of the theme colors, use the Color(SystemColor) constructor:

    painter.fill_rect(rect, SystemColor::HoverHighlight);

Some things don't work 100% right without a reboot. Specifically, when
constructing a GWidget, it will set its own background and foreground
colors based on the current SystemColor::Window and SystemColor::Text.
The widget is then stuck with these values, and they don't update on
system theme change, only on app restart.

All in all though, this is pretty cool. Merry Christmas! :^)
This commit is contained in:
Andreas Kling 2019-12-23 20:24:26 +01:00
parent 7c8bbea995
commit 411058b2a3
50 changed files with 525 additions and 178 deletions

View file

@ -3,10 +3,10 @@
void StylePainter::paint_tab_button(Painter& painter, const Rect& rect, bool active, bool hovered, bool enabled)
{
Color base_color = Color::WarmGray;
Color highlight_color2 = Color::from_rgb(0xe8e7e4);
Color shadow_color1 = Color::from_rgb(0x808080);
Color shadow_color2 = Color::from_rgb(0x404040);
Color base_color = SystemColor::Window;
Color highlight_color2 = SystemColor::ThreedHighlight;
Color shadow_color1 = SystemColor::ThreedShadow1;
Color shadow_color2 = SystemColor::ThreedShadow2;
if (hovered && enabled && !active)
base_color = StylePainter::hover_highlight_color();
@ -44,16 +44,16 @@ void StylePainter::paint_tab_button(Painter& painter, const Rect& rect, bool act
static void paint_button_new(Painter& painter, const Rect& rect, bool pressed, bool checked, bool hovered, bool enabled)
{
Color button_color = Color::WarmGray;
Color highlight_color2 = Color::from_rgb(0xe8e7e4);
Color shadow_color1 = Color::from_rgb(0x808080);
Color shadow_color2 = Color::from_rgb(0x404040);
Color button_color = SystemColor::Window;
Color highlight_color2 = SystemColor::ThreedHighlight;
Color shadow_color1 = SystemColor::ThreedShadow1;
Color shadow_color2 = SystemColor::ThreedShadow2;
if (checked && enabled) {
if (hovered)
button_color = Color::from_rgb(0xe3dfdb);
button_color = SystemColor::HoverHighlight;
else
button_color = Color::from_rgb(0xd6d2ce);
button_color = SystemColor::Window;
} else if (hovered && enabled)
button_color = StylePainter::hover_highlight_color();
@ -92,7 +92,7 @@ void StylePainter::paint_button(Painter& painter, const Rect& rect, ButtonStyle
if (button_style == ButtonStyle::Normal)
return paint_button_new(painter, rect, pressed, checked, hovered, enabled);
Color button_color = checked ? Color::from_rgb(0xd6d2ce) : Color::WarmGray;
Color button_color = SystemColor::Window;
Color highlight_color = Color::White;
Color shadow_color = Color(96, 96, 96);
@ -129,12 +129,12 @@ void StylePainter::paint_button(Painter& painter, const Rect& rect, ButtonStyle
void StylePainter::paint_surface(Painter& painter, const Rect& rect, bool paint_vertical_lines, bool paint_top_line)
{
painter.fill_rect({ rect.x(), rect.y() + 1, rect.width(), rect.height() - 2 }, Color::WarmGray);
painter.draw_line(rect.top_left(), rect.top_right(), paint_top_line ? Color::White : Color::WarmGray);
painter.draw_line(rect.bottom_left(), rect.bottom_right(), Color::MidGray);
painter.fill_rect({ rect.x(), rect.y() + 1, rect.width(), rect.height() - 2 }, SystemColor::Window);
painter.draw_line(rect.top_left(), rect.top_right(), paint_top_line ? SystemColor::ThreedHighlight : SystemColor::Window);
painter.draw_line(rect.bottom_left(), rect.bottom_right(), SystemColor::ThreedShadow1);
if (paint_vertical_lines) {
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), Color::White);
painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), Color::MidGray);
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), SystemColor::ThreedHighlight);
painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), SystemColor::ThreedShadow1);
}
}
@ -142,12 +142,12 @@ void StylePainter::paint_frame(Painter& painter, const Rect& rect, FrameShape sh
{
Color top_left_color;
Color bottom_right_color;
Color dark_shade = Color::from_rgb(0x808080);
Color light_shade = Color::from_rgb(0xffffff);
Color dark_shade = SystemColor::ThreedShadow1;
Color light_shade = SystemColor::ThreedHighlight;
if (shape == FrameShape::Container && thickness >= 2) {
if (shadow == FrameShadow::Raised) {
dark_shade = Color::from_rgb(0x404040);
dark_shade = SystemColor::ThreedShadow2;
}
}
@ -175,10 +175,10 @@ void StylePainter::paint_frame(Painter& painter, const Rect& rect, FrameShape sh
if (shape == FrameShape::Container && thickness >= 2) {
Color top_left_color;
Color bottom_right_color;
Color dark_shade = Color::from_rgb(0x404040);
Color light_shade = Color::WarmGray;
Color dark_shade = SystemColor::ThreedShadow2;
Color light_shade = SystemColor::Window;
if (shadow == FrameShadow::Raised) {
dark_shade = Color::from_rgb(0x808080);
dark_shade = SystemColor::ThreedShadow1;
top_left_color = light_shade;
bottom_right_color = dark_shade;
} else if (shadow == FrameShadow::Sunken) {
@ -207,10 +207,10 @@ void StylePainter::paint_frame(Painter& painter, const Rect& rect, FrameShape sh
void StylePainter::paint_window_frame(Painter& painter, const Rect& rect)
{
Color base_color = Color::WarmGray;
Color dark_shade = Color::from_rgb(0x404040);
Color mid_shade = Color::from_rgb(0x808080);
Color light_shade = Color::from_rgb(0xffffff);
Color base_color = SystemColor::Window;
Color dark_shade = SystemColor::ThreedShadow2;
Color mid_shade = SystemColor::ThreedShadow1;
Color light_shade = SystemColor::ThreedHighlight;
painter.draw_line(rect.top_left(), rect.top_right(), base_color);
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left(), base_color);