瀏覽代碼

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! :^)
Andreas Kling 5 年之前
父節點
當前提交
411058b2a3
共有 50 個文件被更改,包括 525 次插入178 次删除
  1. 1 1
      Applications/IRCClient/IRCAppWindow.cpp
  2. 1 1
      Applications/PaintBrush/PaletteWidget.cpp
  3. 1 1
      Applications/PaintBrush/ToolboxWidget.cpp
  4. 1 1
      Applications/SystemMonitor/NetworkStatisticsWidget.cpp
  5. 2 2
      Applications/SystemMonitor/main.cpp
  6. 1 1
      Applications/Terminal/main.cpp
  7. 3 20
      Base/home/anon/WindowManager.ini
  8. 32 0
      Base/res/themes/Default.ini
  9. 33 0
      Base/res/themes/Xmas.ini
  10. 1 1
      DevTools/HackStudio/FormWidget.cpp
  11. 1 1
      DevTools/VisualBuilder/VBForm.cpp
  12. 1 1
      Games/Minesweeper/Field.cpp
  13. 11 0
      Libraries/LibC/SharedBuffer.cpp
  14. 1 0
      Libraries/LibC/SharedBuffer.h
  15. 0 30
      Libraries/LibCore/CConfigFile.cpp
  16. 0 1
      Libraries/LibCore/CConfigFile.h
  17. 77 0
      Libraries/LibDraw/Color.cpp
  18. 28 1
      Libraries/LibDraw/Color.h
  19. 1 0
      Libraries/LibDraw/Makefile
  20. 26 26
      Libraries/LibDraw/StylePainter.cpp
  21. 1 1
      Libraries/LibDraw/StylePainter.h
  22. 73 0
      Libraries/LibDraw/SystemTheme.cpp
  23. 44 0
      Libraries/LibDraw/SystemTheme.h
  24. 4 4
      Libraries/LibGUI/GAbstractColumnView.cpp
  25. 2 2
      Libraries/LibGUI/GCheckBox.cpp
  26. 1 1
      Libraries/LibGUI/GFilePicker.cpp
  27. 1 1
      Libraries/LibGUI/GGroupBox.cpp
  28. 3 3
      Libraries/LibGUI/GItemView.cpp
  29. 2 2
      Libraries/LibGUI/GListView.cpp
  30. 2 2
      Libraries/LibGUI/GSplitter.cpp
  31. 1 1
      Libraries/LibGUI/GTabWidget.cpp
  32. 3 3
      Libraries/LibGUI/GTableView.cpp
  33. 1 1
      Libraries/LibGUI/GToolBar.cpp
  34. 2 2
      Libraries/LibGUI/GTreeView.cpp
  35. 2 2
      Libraries/LibGUI/GWidget.cpp
  36. 7 0
      Libraries/LibGUI/GWindow.cpp
  37. 6 2
      Libraries/LibGUI/GWindow.h
  38. 15 0
      Libraries/LibGUI/GWindowServerConnection.cpp
  39. 1 0
      Libraries/LibGUI/GWindowServerConnection.h
  40. 2 1
      Servers/WindowServer/WSClientConnection.cpp
  41. 1 1
      Servers/WindowServer/WSCompositor.cpp
  42. 17 7
      Servers/WindowServer/WSMenu.cpp
  43. 3 0
      Servers/WindowServer/WSMenu.h
  44. 8 7
      Servers/WindowServer/WSMenuManager.cpp
  45. 12 12
      Servers/WindowServer/WSWindowFrame.cpp
  46. 67 33
      Servers/WindowServer/WSWindowManager.cpp
  47. 11 0
      Servers/WindowServer/WSWindowManager.h
  48. 2 0
      Servers/WindowServer/WindowClient.ipc
  49. 1 1
      Servers/WindowServer/WindowServer.ipc
  50. 8 1
      Servers/WindowServer/main.cpp

+ 1 - 1
Applications/IRCClient/IRCAppWindow.cpp

@@ -156,7 +156,7 @@ void IRCAppWindow::setup_widgets()
     auto widget = GWidget::construct();
     set_main_widget(widget);
     widget->set_fill_with_background_color(true);
-    widget->set_background_color(Color::WarmGray);
+    widget->set_background_color(SystemColor::Window);
     widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
     widget->layout()->set_spacing(0);
 

+ 1 - 1
Applications/PaintBrush/PaletteWidget.cpp

@@ -51,7 +51,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
     set_frame_shadow(FrameShadow::Raised);
     set_frame_thickness(0);
     set_fill_with_background_color(true);
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
 
     set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
     set_preferred_size(0, 34);

+ 1 - 1
Applications/PaintBrush/ToolboxWidget.cpp

@@ -35,7 +35,7 @@ private:
 ToolboxWidget::ToolboxWidget(GWidget* parent)
     : GFrame(parent)
 {
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
     set_fill_with_background_color(true);
 
     set_frame_thickness(1);

+ 1 - 1
Applications/SystemMonitor/NetworkStatisticsWidget.cpp

@@ -11,7 +11,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GWidget* parent)
         set_layout(make<GBoxLayout>(Orientation::Vertical));
         layout()->set_margins({ 4, 4, 4, 4 });
         set_fill_with_background_color(true);
-        set_background_color(Color::WarmGray);
+        set_background_color(SystemColor::Window);
 
         auto adapters_group_box = GGroupBox::construct("Adapters", this);
         adapters_group_box->set_layout(make<GBoxLayout>(Orientation::Vertical));

+ 2 - 2
Applications/SystemMonitor/main.cpp

@@ -53,7 +53,7 @@ int main(int argc, char** argv)
     auto keeper = GWidget::construct();
     keeper->set_layout(make<GBoxLayout>(Orientation::Vertical));
     keeper->set_fill_with_background_color(true);
-    keeper->set_background_color(Color::WarmGray);
+    keeper->set_background_color(SystemColor::Window);
     keeper->layout()->set_margins({ 4, 4, 4, 4 });
 
     auto tabwidget = GTabWidget::construct(keeper);
@@ -355,7 +355,7 @@ NonnullRefPtr<GWidget> build_graphs_tab()
 
     graphs_container->on_first_show = [](auto& self) {
         self.set_fill_with_background_color(true);
-        self.set_background_color(Color::WarmGray);
+        self.set_background_color(SystemColor::Window);
         self.set_layout(make<GBoxLayout>(Orientation::Vertical));
         self.layout()->set_margins({ 4, 4, 4, 4 });
 

+ 1 - 1
Applications/Terminal/main.cpp

@@ -124,7 +124,7 @@ RefPtr<GWindow> create_settings_window(TerminalWidget& terminal, RefPtr<CConfigF
     slider_container->set_preferred_size(100, 50);
     auto slider = GSlider::construct(Orientation::Horizontal, slider_container);
     slider->set_fill_with_background_color(true);
-    slider->set_background_color(Color::WarmGray);
+    slider->set_background_color(SystemColor::Window);
 
     slider->on_value_changed = [&terminal, &config](int value) {
         terminal.set_opacity(value);

+ 3 - 20
Base/home/anon/WindowManager.ini

@@ -2,6 +2,9 @@
 Width=1024
 Height=768
 
+[Theme]
+Name=Default
+
 [Cursor]
 Arrow=/res/cursors/arrow.png
 ResizeH=/res/cursors/resize-horizontal.png
@@ -14,26 +17,6 @@ Move=/res/cursors/move.png
 Hand=/res/cursors/hand.png
 Drag=/res/cursors/drag.png
 
-[Colors]
-Background=50,50,50
-ActiveWindowBorder=110,34,9
-ActiveWindowBorder2=244,202,158
-ActiveWindowTitle=255,255,255
-
-InactiveWindowBorder=128,128,128
-InactiveWindowBorder2=192,192,192
-InactiveWindowTitle=213,208,199
-
-MovingWindowBorder=161,50,13
-MovingWindowBorder2=250,220,187
-MovingWindowTitle=255,255,255
-
-HighlightWindowBorder=161,13,13
-HighlightWindowBorder2=250,187,187
-HighlightWindowTitle=255,255,255
-
-MenuSelectionColor=132,53,26
-
 [Input]
 DoubleClickSpeed=250
 

+ 32 - 0
Base/res/themes/Default.ini

@@ -0,0 +1,32 @@
+[Colors]
+DesktopBackground=#404040
+
+ActiveWindowBorder1=#6e2209
+ActiveWindowBorder2=#f4ca9e
+ActiveWindowTitle=white
+
+InactiveWindowBorder1=#808080
+InactiveWindowBorder2=#c0c0c0
+InactiveWindowTitle=#d5d0c7
+
+MovingWindowBorder1=#a1320d
+MovingWindowBorder2=#fadcbb
+MovingWindowTitle=white
+
+HighlightWindowBorder1=#a10d0d
+HighlightWindowBorder2=#fabbbb
+HighlightWindowTitle=white
+
+MenuBase=white
+MenuStripe=#bbb7b0
+MenuSelection=#ad714f
+
+Window=#d4d0c8
+Text=black
+Base=white
+
+ThreedHighlight=white
+ThreedShadow1=#808080
+ThreedShadow2=#404040
+
+HoverHighlight=#e3dfdb

+ 33 - 0
Base/res/themes/Xmas.ini

@@ -0,0 +1,33 @@
+[Colors]
+DesktopBackground=#313819
+
+ActiveWindowBorder1=#731013
+ActiveWindowBorder2=#ee3532
+ActiveWindowTitle=white
+
+InactiveWindowBorder1=#734546
+InactiveWindowBorder2=#ee908f
+InactiveWindowTitle=white
+
+MovingWindowBorder1=#a76f24
+MovingWindowBorder2=#eec666
+MovingWindowTitle=white
+
+HighlightWindowBorder1=#a76f24
+HighlightWindowBorder2=#eec666
+HighlightWindowTitle=white
+
+MenuBase=#57691f
+MenuStripe=#2b3018
+MenuSelection=#ff8742
+
+Window=#d46c64
+Text=black
+Base=#d3d7c4
+
+ThreedHighlight=#e69e99
+ThreedShadow1=#a24841
+ThreedShadow2=#882d26
+
+HoverHighlight=#e6e5e2
+

+ 1 - 1
DevTools/HackStudio/FormWidget.cpp

@@ -7,7 +7,7 @@ FormWidget::FormWidget(FormEditorWidget& parent)
     : GWidget(&parent)
 {
     set_fill_with_background_color(true);
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
     set_relative_rect(5, 5, 400, 300);
 
     set_greedy_for_hits(true);

+ 1 - 1
DevTools/VisualBuilder/VBForm.cpp

@@ -25,7 +25,7 @@ VBForm::VBForm(const String& name, GWidget* parent)
 {
     s_current = this;
     set_fill_with_background_color(true);
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
     set_greedy_for_hits(true);
 
     m_context_menu = GMenu::construct();

+ 1 - 1
Games/Minesweeper/Field.cpp

@@ -121,7 +121,7 @@ Field::Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidg
         m_number_bitmap[i] = GraphicsBitmap::load_from_file(String::format("/res/icons/minesweeper/%u.png", i + 1));
 
     set_fill_with_background_color(true);
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
     reset();
 
     m_face_button.on_click = [this](auto&) { reset(); };

+ 11 - 0
Libraries/LibC/SharedBuffer.cpp

@@ -25,6 +25,17 @@ bool SharedBuffer::share_with(pid_t peer)
     return true;
 }
 
+bool SharedBuffer::share_globally()
+{
+    int ret = share_buffer_globally(shared_buffer_id());
+    if (ret < 0) {
+        perror("share_buffer_globally");
+        return false;
+    }
+    return true;
+}
+
+
 RefPtr<SharedBuffer> SharedBuffer::create_from_shared_buffer_id(int shared_buffer_id)
 {
     void* data = get_shared_buffer(shared_buffer_id);

+ 1 - 0
Libraries/LibC/SharedBuffer.h

@@ -9,6 +9,7 @@ public:
     static RefPtr<SharedBuffer> create_from_shared_buffer_id(int);
     ~SharedBuffer();
 
+    bool share_globally();
     bool share_with(pid_t);
     int shared_buffer_id() const { return m_shared_buffer_id; }
     void seal();

+ 0 - 30
Libraries/LibCore/CConfigFile.cpp

@@ -110,36 +110,6 @@ int CConfigFile::read_num_entry(const String& group, const String& key, int defa
     return value;
 }
 
-Color CConfigFile::read_color_entry(const String& group, const String& key, Color default_value) const
-{
-    if (!has_key(group, key)) {
-        const_cast<CConfigFile&>(*this).write_color_entry(group, key, default_value);
-        return default_value;
-    }
-
-    auto shades = read_entry(group, key).split(',');
-    if (shades.size() < 3)
-        return default_value;
-    bool ok1 = true,
-         ok2 = true,
-         ok3 = true,
-         ok4 = true;
-    Color value;
-    if (shades.size() == 3) {
-        value = Color(shades[0].to_uint(ok1),
-            shades[1].to_uint(ok2),
-            shades[2].to_uint(ok3));
-    } else {
-        value = Color(shades[0].to_uint(ok1),
-            shades[1].to_uint(ok2),
-            shades[2].to_uint(ok3),
-            shades[3].to_uint(ok4));
-    }
-    if (!(ok1 && ok2 && ok3 && ok4))
-        return default_value;
-    return value;
-}
-
 bool CConfigFile::read_bool_entry(const String& group, const String& key, bool default_value) const
 {
     return read_entry(group, key, default_value ? "1" : "0") == "1";

+ 0 - 1
Libraries/LibCore/CConfigFile.h

@@ -23,7 +23,6 @@ public:
     String read_entry(const String& group, const String& key, const String& default_vaule = String()) const;
     int read_num_entry(const String& group, const String& key, int default_value = 0) const;
     bool read_bool_entry(const String& group, const String& key, bool default_value = false) const;
-    Color read_color_entry(const String& group, const String& key, Color default_value) const;
 
     void write_entry(const String& group, const String& key, const String& value);
     void write_num_entry(const String& group, const String& key, int value);

+ 77 - 0
Libraries/LibDraw/Color.cpp

@@ -1,8 +1,85 @@
 #include <AK/Assertions.h>
 #include <LibDraw/Color.h>
+#include <LibDraw/SystemTheme.h>
 #include <ctype.h>
 #include <stdio.h>
 
+Color::Color(SystemColor system_color)
+{
+    auto& theme = current_system_theme();
+    switch (system_color) {
+    case SystemColor::Window:
+        m_value = theme.window.value();
+        break;
+    case SystemColor::Text:
+        m_value = theme.text.value();
+        break;
+    case SystemColor::Base:
+        m_value = theme.base.value();
+        break;
+    case SystemColor::ThreedShadow1:
+        m_value = theme.threed_shadow1.value();
+        break;
+    case SystemColor::ThreedShadow2:
+        m_value = theme.threed_shadow2.value();
+        break;
+    case SystemColor::ThreedHighlight:
+        m_value = theme.threed_highlight.value();
+        break;
+    case SystemColor::HoverHighlight:
+        m_value = theme.hover_highlight.value();
+        break;
+    case SystemColor::DesktopBackground:
+        m_value = theme.desktop_background.value();
+        break;
+    case SystemColor::ActiveWindowBorder1:
+        m_value = theme.active_window_border1.value();
+        break;
+    case SystemColor::ActiveWindowBorder2:
+        m_value = theme.active_window_border2.value();
+        break;
+    case SystemColor::ActiveWindowTitle:
+        m_value = theme.active_window_title.value();
+        break;
+    case SystemColor::InactiveWindowBorder1:
+        m_value = theme.inactive_window_border1.value();
+        break;
+    case SystemColor::InactiveWindowBorder2:
+        m_value = theme.inactive_window_border2.value();
+        break;
+    case SystemColor::InactiveWindowTitle:
+        m_value = theme.inactive_window_title.value();
+        break;
+    case SystemColor::MovingWindowBorder1:
+        m_value = theme.moving_window_border1.value();
+        break;
+    case SystemColor::MovingWindowBorder2:
+        m_value = theme.moving_window_border2.value();
+        break;
+    case SystemColor::MovingWindowTitle:
+        m_value = theme.moving_window_title.value();
+        break;
+    case SystemColor::HighlightWindowBorder1:
+        m_value = theme.highlight_window_border1.value();
+        break;
+    case SystemColor::HighlightWindowBorder2:
+        m_value = theme.highlight_window_border2.value();
+        break;
+    case SystemColor::HighlightWindowTitle:
+        m_value = theme.highlight_window_title.value();
+        break;
+    case SystemColor::MenuStripe:
+        m_value = theme.menu_stripe.value();
+        break;
+    case SystemColor::MenuBase:
+        m_value = theme.menu_base.value();
+        break;
+    case SystemColor::MenuSelection:
+        m_value = theme.menu_selection.value();
+        break;
+    }
+}
+
 Color::Color(NamedColor named)
 {
     struct {

+ 28 - 1
Libraries/LibDraw/Color.h

@@ -1,7 +1,7 @@
 #pragma once
 
-#include <AK/String.h>
 #include <AK/Optional.h>
+#include <AK/String.h>
 #include <AK/Types.h>
 
 typedef u32 RGBA32;
@@ -11,6 +11,32 @@ inline constexpr u32 make_rgb(u8 r, u8 g, u8 b)
     return ((r << 16) | (g << 8) | b);
 }
 
+enum class SystemColor {
+    DesktopBackground,
+    ActiveWindowBorder1,
+    ActiveWindowBorder2,
+    ActiveWindowTitle,
+    InactiveWindowBorder1,
+    InactiveWindowBorder2,
+    InactiveWindowTitle,
+    MovingWindowBorder1,
+    MovingWindowBorder2,
+    MovingWindowTitle,
+    HighlightWindowBorder1,
+    HighlightWindowBorder2,
+    HighlightWindowTitle,
+    MenuStripe,
+    MenuBase,
+    MenuSelection,
+    Window,
+    Text,
+    Base,
+    ThreedHighlight,
+    ThreedShadow1,
+    ThreedShadow2,
+    HoverHighlight,
+};
+
 class Color {
 public:
     enum NamedColor {
@@ -39,6 +65,7 @@ public:
 
     Color() {}
     Color(NamedColor);
+    Color(SystemColor);
     Color(u8 r, u8 g, u8 b)
         : m_value(0xff000000 | (r << 16) | (g << 8) | b)
     {

+ 1 - 0
Libraries/LibDraw/Makefile

@@ -10,6 +10,7 @@ OBJS = \
     ImageDecoder.o \
     Rect.o \
     StylePainter.o \
+    SystemTheme.o \
     Emoji.o
 
 LIBRARY = libdraw.a

+ 26 - 26
Libraries/LibDraw/StylePainter.cpp

@@ -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);

+ 1 - 1
Libraries/LibDraw/StylePainter.h

@@ -32,5 +32,5 @@ public:
     static void paint_window_frame(Painter&, const Rect&);
     static void paint_progress_bar(Painter&, const Rect&, int min, int max, int value, const StringView& text = {});
 
-    static Color hover_highlight_color() { return Color::from_rgb(0xe6e5e2); }
+    static Color hover_highlight_color() { return SystemColor::HoverHighlight; }
 };

+ 73 - 0
Libraries/LibDraw/SystemTheme.cpp

@@ -0,0 +1,73 @@
+#include <LibCore/CConfigFile.h>
+#include <LibDraw/SystemTheme.h>
+
+static SystemTheme dummy_theme;
+static const SystemTheme* theme_page = &dummy_theme;
+static RefPtr<SharedBuffer> theme_buffer;
+
+const SystemTheme& current_system_theme()
+{
+    ASSERT(theme_page);
+    return *theme_page;
+}
+
+int current_system_theme_buffer_id()
+{
+    ASSERT(theme_buffer);
+    return theme_buffer->shared_buffer_id();
+}
+
+void set_system_theme(SharedBuffer& buffer)
+{
+    theme_buffer = buffer;
+    theme_page = (SystemTheme*)theme_buffer->data();
+}
+
+RefPtr<SharedBuffer> load_system_theme(const String& path)
+{
+    auto file = CConfigFile::open(path);
+    auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme));
+
+    dbg() << "Created shared buffer with id " << buffer->shared_buffer_id();
+
+    auto* data = (SystemTheme*)buffer->data();
+
+    auto get = [&](auto& name) {
+        auto color_string = file->read_entry("Colors", name);
+        auto color = Color::from_string(color_string);
+        if (!color.has_value())
+            return Color(Color::Black);
+        dbg() << "Parsed system color '" << name << "' = " << color.value();
+        return color.value();
+    };
+
+    data->desktop_background = get("DesktopBackground");
+    data->threed_highlight = get("ThreedHighlight");
+    data->threed_shadow1 = get("ThreedShadow1");
+    data->threed_shadow2 = get("ThreedShadow2");
+    data->hover_highlight = get("HoverHighlight");
+    data->window = get("Window");
+    data->text = get("Text");
+    data->base = get("Base");
+    data->desktop_background = get("DesktopBackground");
+    data->active_window_border1 = get("ActiveWindowBorder1");
+    data->active_window_border2 = get("ActiveWindowBorder2");
+    data->active_window_title = get("ActiveWindowTitle");
+    data->inactive_window_border1 = get("InactiveWindowBorder1");
+    data->inactive_window_border2 = get("InactiveWindowBorder2");
+    data->inactive_window_title = get("InactiveWindowTitle");
+    data->moving_window_border1 = get("MovingWindowBorder1");
+    data->moving_window_border2 = get("MovingWindowBorder2");
+    data->moving_window_title = get("MovingWindowTitle");
+    data->highlight_window_border1 = get("HighlightWindowBorder1");
+    data->highlight_window_border2 = get("HighlightWindowBorder2");
+    data->highlight_window_title = get("HighlightWindowTitle");
+    data->menu_stripe = get("MenuStripe");
+    data->menu_base = get("MenuBase");
+    data->menu_selection = get("MenuSelection");
+
+    buffer->seal();
+    buffer->share_globally();
+
+    return buffer;
+}

+ 44 - 0
Libraries/LibDraw/SystemTheme.h

@@ -0,0 +1,44 @@
+#pragma once
+
+#include <AK/Types.h>
+#include <LibC/SharedBuffer.h>
+#include <LibDraw/Color.h>
+
+struct SystemTheme {
+    Color desktop_background;
+
+    Color active_window_border1;
+    Color active_window_border2;
+    Color active_window_title;
+
+    Color inactive_window_border1;
+    Color inactive_window_border2;
+    Color inactive_window_title;
+
+    Color moving_window_border1;
+    Color moving_window_border2;
+    Color moving_window_title;
+
+    Color highlight_window_border1;
+    Color highlight_window_border2;
+    Color highlight_window_title;
+
+    Color menu_stripe;
+    Color menu_base;
+    Color menu_selection;
+
+    Color window;
+    Color text;
+    Color base;
+
+    Color threed_highlight;
+    Color threed_shadow1;
+    Color threed_shadow2;
+
+    Color hover_highlight;
+};
+
+const SystemTheme& current_system_theme();
+int current_system_theme_buffer_id();
+void set_system_theme(SharedBuffer&);
+RefPtr<SharedBuffer> load_system_theme(const String& path);

+ 4 - 4
Libraries/LibGUI/GAbstractColumnView.cpp

@@ -99,9 +99,9 @@ void GAbstractColumnView::paint_headers(GPainter& painter)
     if (!headers_visible())
         return;
     int exposed_width = max(content_size().width(), width());
-    painter.fill_rect({ 0, 0, exposed_width, header_height() }, Color::WarmGray);
-    painter.draw_line({ 0, 0 }, { exposed_width - 1, 0 }, Color::White);
-    painter.draw_line({ 0, header_height() - 1 }, { exposed_width - 1, header_height() - 1 }, Color::MidGray);
+    painter.fill_rect({ 0, 0, exposed_width, header_height() }, SystemColor::Window);
+    painter.draw_line({ 0, 0 }, { exposed_width - 1, 0 }, SystemColor::ThreedHighlight);
+    painter.draw_line({ 0, header_height() - 1 }, { exposed_width - 1, header_height() - 1 }, SystemColor::ThreedShadow1);
     int x_offset = 0;
     int column_count = model()->column_count();
     for (int column_index = 0; column_index < column_count; ++column_index) {
@@ -129,7 +129,7 @@ void GAbstractColumnView::paint_headers(GPainter& painter)
         auto text_rect = cell_rect.translated(horizontal_padding(), 0);
         if (pressed)
             text_rect.move_by(1, 1);
-        painter.draw_text(text_rect, text, header_font(), TextAlignment::CenterLeft, Color::Black);
+        painter.draw_text(text_rect, text, header_font(), TextAlignment::CenterLeft, SystemColor::Text);
         x_offset += column_width + horizontal_padding() * 2;
     }
 }

+ 2 - 2
Libraries/LibGUI/GCheckBox.cpp

@@ -54,7 +54,7 @@ void GCheckBox::paint_event(GPaintEvent& event)
         0, height() / 2 - s_box_height / 2 - 1,
         s_box_width, s_box_height
     };
-    painter.fill_rect(box_rect, Color::White);
+    painter.fill_rect(box_rect, SystemColor::Base);
     StylePainter::paint_frame(painter, box_rect, FrameShape::Container, FrameShadow::Sunken, 2);
 
     if (is_being_pressed())
@@ -63,7 +63,7 @@ void GCheckBox::paint_event(GPaintEvent& event)
     if (is_checked()) {
         if (!s_checked_bitmap)
             s_checked_bitmap = &CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref();
-        painter.draw_bitmap(box_rect.shrunken(4, 4).location(), *s_checked_bitmap, foreground_color());
+        painter.draw_bitmap(box_rect.shrunken(4, 4).location(), *s_checked_bitmap, SystemColor::Text);
     }
 
     paint_text(painter, text_rect, font(), TextAlignment::TopLeft);

+ 1 - 1
Libraries/LibGUI/GFilePicker.cpp

@@ -58,7 +58,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
     horizontal_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
     horizontal_container->layout()->set_margins({ 4, 4, 4, 4 });
     horizontal_container->set_fill_with_background_color(true);
-    horizontal_container->set_background_color(Color::WarmGray);
+    horizontal_container->set_background_color(SystemColor::Window);
 
     auto vertical_container = GWidget::construct(horizontal_container.ptr());
     vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));

+ 1 - 1
Libraries/LibGUI/GGroupBox.cpp

@@ -12,7 +12,7 @@ GGroupBox::GGroupBox(const StringView& title, GWidget* parent)
     , m_title(title)
 {
     set_fill_with_background_color(true);
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
 }
 
 GGroupBox::~GGroupBox()

+ 3 - 3
Libraries/LibGUI/GItemView.cpp

@@ -191,7 +191,7 @@ void GItemView::paint_event(GPaintEvent& event)
     GPainter painter(*this);
     painter.add_clip_rect(widget_inner_rect());
     painter.add_clip_rect(event.rect());
-    painter.fill_rect(event.rect(), Color::White);
+    painter.fill_rect(event.rect(), SystemColor::Base);
     painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
 
     auto column_metadata = model()->column_metadata(m_model_column);
@@ -203,7 +203,7 @@ void GItemView::paint_event(GPaintEvent& event)
         if (is_selected_item) {
             background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060);
         } else {
-            background_color = Color::White;
+            background_color = SystemColor::Base;
         }
 
         Rect item_rect = this->item_rect(item_index);
@@ -230,7 +230,7 @@ void GItemView::paint_event(GPaintEvent& event)
         if (is_selected_item)
             text_color = Color::White;
         else
-            text_color = model()->data(model_index, GModel::Role::ForegroundColor).to_color(Color::Black);
+            text_color = model()->data(model_index, GModel::Role::ForegroundColor).to_color(SystemColor::Text);
         painter.fill_rect(text_rect, background_color);
         painter.draw_text(text_rect, item_text.to_string(), font, TextAlignment::Center, text_color, TextElision::Right);
     };

+ 2 - 2
Libraries/LibGUI/GListView.cpp

@@ -109,7 +109,7 @@ void GListView::paint_event(GPaintEvent& event)
             if (alternating_row_colors() && (painted_item_index % 2))
                 background_color = Color(210, 210, 210);
             else
-                background_color = Color::White;
+                background_color = SystemColor::Base;
         }
 
         auto column_metadata = model()->column_metadata(m_model_column);
@@ -140,7 +140,7 @@ void GListView::paint_event(GPaintEvent& event)
     };
 
     Rect unpainted_rect(0, painted_item_index * item_height(), exposed_width, height());
-    painter.fill_rect(unpainted_rect, Color::White);
+    painter.fill_rect(unpainted_rect, SystemColor::Base);
 }
 
 int GListView::item_count() const

+ 2 - 2
Libraries/LibGUI/GSplitter.cpp

@@ -8,7 +8,7 @@ GSplitter::GSplitter(Orientation orientation, GWidget* parent)
 {
     set_layout(make<GBoxLayout>(orientation));
     set_fill_with_background_color(true);
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
     layout()->set_spacing(3);
 }
 
@@ -25,7 +25,7 @@ void GSplitter::enter_event(CEvent&)
 
 void GSplitter::leave_event(CEvent&)
 {
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
     if (!m_resizing)
         window()->set_override_cursor(GStandardCursor::None);
     update();

+ 1 - 1
Libraries/LibGUI/GTabWidget.cpp

@@ -7,7 +7,7 @@ GTabWidget::GTabWidget(GWidget* parent)
     : GWidget(parent)
 {
     set_fill_with_background_color(true);
-    set_background_color(Color::WarmGray);
+    set_background_color(SystemColor::Window);
 }
 
 GTabWidget::~GTabWidget()

+ 3 - 3
Libraries/LibGUI/GTableView.cpp

@@ -25,7 +25,7 @@ void GTableView::paint_event(GPaintEvent& event)
     GPainter painter(*this);
     painter.add_clip_rect(frame_inner_rect());
     painter.add_clip_rect(event.rect());
-    painter.fill_rect(event.rect(), Color::White);
+    painter.fill_rect(event.rect(), SystemColor::Base);
     painter.translate(frame_thickness(), frame_thickness());
     painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
 
@@ -60,7 +60,7 @@ void GTableView::paint_event(GPaintEvent& event)
                 background_color = Color(220, 220, 220);
                 key_column_background_color = Color(200, 200, 200);
             } else {
-                background_color = Color::White;
+                background_color = SystemColor::Base;
                 key_column_background_color = Color(220, 220, 220);
             }
         }
@@ -105,7 +105,7 @@ void GTableView::paint_event(GPaintEvent& event)
     };
 
     Rect unpainted_rect(0, header_height() + painted_item_index * item_height(), exposed_width, height());
-    painter.fill_rect(unpainted_rect, Color::White);
+    painter.fill_rect(unpainted_rect, SystemColor::Base);
 
     // Untranslate the painter vertically and do the column headers.
     painter.translate(0, vertical_scrollbar().value());

+ 1 - 1
Libraries/LibGUI/GToolBar.cpp

@@ -93,5 +93,5 @@ void GToolBar::paint_event(GPaintEvent& event)
     if (m_has_frame)
         StylePainter::paint_surface(painter, rect(), x() != 0, y() != 0);
     else
-        painter.fill_rect(event.rect(), Color::WarmGray);
+        painter.fill_rect(event.rect(), background_color());
 }

+ 2 - 2
Libraries/LibGUI/GTreeView.cpp

@@ -146,7 +146,7 @@ void GTreeView::paint_event(GPaintEvent& event)
     GPainter painter(*this);
     painter.add_clip_rect(frame_inner_rect());
     painter.add_clip_rect(event.rect());
-    painter.fill_rect(event.rect(), Color::White);
+    painter.fill_rect(event.rect(), SystemColor::Base);
 
     if (!model())
         return;
@@ -192,7 +192,7 @@ void GTreeView::paint_event(GPaintEvent& event)
                 background_color = Color(220, 220, 220);
                 key_column_background_color = Color(200, 200, 200);
             } else {
-                background_color = Color::White;
+                background_color = SystemColor::Base;
                 key_column_background_color = Color(220, 220, 220);
             }
         }

+ 2 - 2
Libraries/LibGUI/GWidget.cpp

@@ -68,8 +68,8 @@ GWidget::GWidget(GWidget* parent)
     : CObject(parent, true)
     , m_font(Font::default_font())
 {
-    m_background_color = Color::WarmGray;
-    m_foreground_color = Color::Black;
+    m_background_color = SystemColor::Window;
+    m_foreground_color = SystemColor::Text;
 }
 
 GWidget::~GWidget()

+ 7 - 0
Libraries/LibGUI/GWindow.cpp

@@ -686,3 +686,10 @@ void GWindow::schedule_relayout()
         m_layout_pending = false;
     });
 }
+
+void GWindow::update_all_windows(Badge<GWindowServerConnection>)
+{
+    for (auto* window : all_windows) {
+        window->update();
+    }
+}

+ 6 - 2
Libraries/LibGUI/GWindow.h

@@ -1,15 +1,17 @@
 #pragma once
 
-#include <AK/String.h>
+#include <AK/Badge.h>
 #include <AK/HashMap.h>
+#include <AK/String.h>
 #include <AK/WeakPtr.h>
 #include <LibCore/CObject.h>
 #include <LibDraw/GraphicsBitmap.h>
 #include <LibDraw/Rect.h>
 #include <LibGUI/GWindowType.h>
 
-class GWidget;
 class GWMEvent;
+class GWidget;
+class GWindowServerConnection;
 
 enum class GStandardCursor {
     None = 0,
@@ -133,6 +135,8 @@ public:
 
     void schedule_relayout();
 
+    static void update_all_windows(Badge<GWindowServerConnection>);
+
 protected:
     GWindow(CObject* parent = nullptr);
     virtual void wm_event(GWMEvent&);

+ 15 - 0
Libraries/LibGUI/GWindowServerConnection.cpp

@@ -1,3 +1,4 @@
+#include <LibDraw/SystemTheme.h>
 #include <LibGUI/GAction.h>
 #include <LibGUI/GApplication.h>
 #include <LibGUI/GClipboard.h>
@@ -19,13 +20,27 @@ GWindowServerConnection& GWindowServerConnection::the()
     return *s_connection;
 }
 
+static void set_system_theme_from_shared_buffer_id(int id)
+{
+    auto system_theme = SharedBuffer::create_from_shared_buffer_id(id);
+    ASSERT(system_theme);
+    set_system_theme(*system_theme);
+}
+
 void GWindowServerConnection::handshake()
 {
     auto response = send_sync<WindowServer::Greet>();
     set_my_client_id(response->client_id());
+    set_system_theme_from_shared_buffer_id(response->system_theme_buffer_id());
     GDesktop::the().did_receive_screen_rect({}, response->screen_rect());
 }
 
+void GWindowServerConnection::handle(const WindowClient::UpdateSystemTheme& message)
+{
+    set_system_theme_from_shared_buffer_id(message.system_theme_buffer_id());
+    GWindow::update_all_windows({});
+}
+
 void GWindowServerConnection::handle(const WindowClient::Paint& message)
 {
 #ifdef GEVENTLOOP_DEBUG

+ 1 - 0
Libraries/LibGUI/GWindowServerConnection.h

@@ -44,4 +44,5 @@ private:
     virtual void handle(const WindowClient::DragDropped&) override;
     virtual void handle(const WindowClient::DragAccepted&) override;
     virtual void handle(const WindowClient::DragCancelled&) override;
+    virtual void handle(const WindowClient::UpdateSystemTheme&) override;
 };

+ 2 - 1
Servers/WindowServer/WSClientConnection.cpp

@@ -1,5 +1,6 @@
 #include <LibC/SharedBuffer.h>
 #include <LibDraw/GraphicsBitmap.h>
+#include <LibDraw/SystemTheme.h>
 #include <SharedBuffer.h>
 #include <WindowServer/WSClientConnection.h>
 #include <WindowServer/WSClipboard.h>
@@ -605,7 +606,7 @@ void WSClientConnection::handle(const WindowServer::WM_SetWindowMinimized& messa
 
 OwnPtr<WindowServer::GreetResponse> WSClientConnection::handle(const WindowServer::Greet&)
 {
-    return make<WindowServer::GreetResponse>(client_id(), WSScreen::the().rect());
+    return make<WindowServer::GreetResponse>(client_id(), WSScreen::the().rect(), current_system_theme_buffer_id());
 }
 
 bool WSClientConnection::is_showing_modal_window() const

+ 1 - 1
Servers/WindowServer/WSCompositor.cpp

@@ -113,7 +113,7 @@ void WSCompositor::compose()
         if (wm.any_opaque_window_contains_rect(dirty_rect))
             continue;
         // FIXME: If the wallpaper is opaque, no need to fill with color!
-        m_back_painter->fill_rect(dirty_rect, wm.m_background_color);
+        m_back_painter->fill_rect(dirty_rect, SystemColor::DesktopBackground);
         if (m_wallpaper) {
             if (m_wallpaper_mode == WallpaperMode::Simple) {
                 m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);

+ 17 - 7
Servers/WindowServer/WSMenu.cpp

@@ -126,12 +126,14 @@ WSWindow& WSMenu::ensure_menu_window()
 
 void WSMenu::draw()
 {
+    m_theme_index_at_last_paint = WSWindowManager::the().theme_index();
+
     ASSERT(menu_window());
     ASSERT(menu_window()->backing_store());
     Painter painter(*menu_window()->backing_store());
 
     Rect rect { {}, menu_window()->size() };
-    painter.fill_rect(rect.shrunken(6, 6), Color::White);
+    painter.fill_rect(rect.shrunken(6, 6), SystemColor::MenuBase);
     StylePainter::paint_window_frame(painter, rect);
     int width = this->width();
 
@@ -146,15 +148,15 @@ void WSMenu::draw()
     }
 
     Rect stripe_rect { frame_thickness(), frame_thickness(), s_stripe_width, height() - frame_thickness() * 2 };
-    painter.fill_rect(stripe_rect, Color::WarmGray);
-    painter.draw_line(stripe_rect.top_right(), stripe_rect.bottom_right(), Color::from_rgb(0xbbb7b0));
+    painter.fill_rect(stripe_rect, SystemColor::MenuStripe);
+    painter.draw_line(stripe_rect.top_right(), stripe_rect.bottom_right(), Color(SystemColor::MenuStripe).darkened());
 
     for (auto& item : m_items) {
         if (item.type() == WSMenuItem::Text) {
             Color text_color = Color::Black;
             if (&item == m_hovered_item && item.is_enabled()) {
-                painter.fill_rect(item.rect(), Color::from_rgb(0xad714f));
-                painter.draw_rect(item.rect(), Color::from_rgb(0x793016));
+                painter.fill_rect(item.rect(), SystemColor::MenuSelection);
+                painter.draw_rect(item.rect(), Color(SystemColor::MenuSelection).darkened());
                 text_color = Color::White;
             } else if (!item.is_enabled()) {
                 text_color = Color::MidGray;
@@ -164,10 +166,10 @@ void WSMenu::draw()
                 Rect checkmark_rect { item.rect().x() + 7, 0, s_checked_bitmap_width, s_checked_bitmap_height };
                 checkmark_rect.center_vertically_within(text_rect);
                 Rect checkbox_rect = checkmark_rect.inflated(4, 4);
-                painter.fill_rect(checkbox_rect, Color::White);
+                painter.fill_rect(checkbox_rect, SystemColor::Base);
                 StylePainter::paint_frame(painter, checkbox_rect, FrameShape::Container, FrameShadow::Sunken, 2);
                 if (item.is_checked()) {
-                    painter.draw_bitmap(checkmark_rect.location(), *s_checked_bitmap, Color::Black);
+                    painter.draw_bitmap(checkmark_rect.location(), *s_checked_bitmap, SystemColor::Text);
                 }
             } else if (item.icon()) {
                 Rect icon_rect { item.rect().x() + 3, 0, s_item_icon_width, s_item_icon_width };
@@ -274,11 +276,19 @@ void WSMenu::close()
     WSWindowManager::the().menu_manager().close_menu_and_descendants(*this);
 }
 
+void WSMenu::redraw_if_theme_changed()
+{
+    if (m_theme_index_at_last_paint != WSWindowManager::the().theme_index())
+        redraw();
+}
+
 void WSMenu::popup(const Point& position, bool is_submenu)
 {
     ASSERT(!is_empty());
 
     auto& window = ensure_menu_window();
+    redraw_if_theme_changed();
+
     const int margin = 30;
     Point adjusted_pos = position;
     if (adjusted_pos.x() + window.width() >= WSScreen::the().width() - margin) {

+ 3 - 0
Servers/WindowServer/WSMenu.h

@@ -78,6 +78,8 @@ public:
 
     bool is_menu_ancestor_of(const WSMenu&) const;
 
+    void redraw_if_theme_changed();
+
 private:
     virtual void event(CEvent&) override;
 
@@ -92,4 +94,5 @@ private:
     WSMenuItem* m_hovered_item { nullptr };
     NonnullOwnPtrVector<WSMenuItem> m_items;
     RefPtr<WSWindow> m_menu_window;
+    int m_theme_index_at_last_paint { -1 };
 };

+ 8 - 7
Servers/WindowServer/WSMenuManager.cpp

@@ -83,14 +83,14 @@ void WSMenuManager::draw()
 
     Painter painter(*window().backing_store());
 
-    painter.fill_rect(menubar_rect, Color::WarmGray);
-    painter.draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, Color::MidGray);
+    painter.fill_rect(menubar_rect, SystemColor::Window);
+    painter.draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, SystemColor::ThreedShadow1);
     int index = 0;
     wm.for_each_active_menubar_menu([&](WSMenu& menu) {
-        Color text_color = Color::Black;
+        Color text_color = SystemColor::Text;
         if (is_open(menu)) {
-            painter.fill_rect(menu.rect_in_menubar(), Color::from_rgb(0xad714f));
-            painter.draw_rect(menu.rect_in_menubar(), Color::from_rgb(0x793016));
+            painter.fill_rect(menu.rect_in_menubar(), SystemColor::MenuSelection);
+            painter.draw_rect(menu.rect_in_menubar(), Color(SystemColor::MenuSelection).darkened());
             text_color = Color::White;
         }
         painter.draw_text(
@@ -103,7 +103,7 @@ void WSMenuManager::draw()
         return IterationDecision::Continue;
     });
 
-    painter.draw_text(m_username_rect, m_username, Font::default_bold_font(), TextAlignment::CenterRight, Color::Black);
+    painter.draw_text(m_username_rect, m_username, Font::default_bold_font(), TextAlignment::CenterRight, SystemColor::Text);
 
     time_t now = time(nullptr);
     auto* tm = localtime(&now);
@@ -115,7 +115,7 @@ void WSMenuManager::draw()
         tm->tm_min,
         tm->tm_sec);
 
-    painter.draw_text(m_time_rect, time_text, wm.font(), TextAlignment::CenterRight, Color::Black);
+    painter.draw_text(m_time_rect, time_text, wm.font(), TextAlignment::CenterRight, SystemColor::Text);
 
     for (auto& applet : m_applets) {
         if (!applet)
@@ -182,6 +182,7 @@ void WSMenuManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& ev
             return;
         close_everyone();
         if (!menu.is_empty()) {
+            menu.redraw_if_theme_changed();
             auto& menu_window = menu.ensure_menu_window();
             menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() + 2 });
             menu_window.set_visible(true);

+ 12 - 12
Servers/WindowServer/WSWindowFrame.cpp

@@ -170,21 +170,21 @@ void WSWindowFrame::paint(Painter& painter)
     auto& wm = WSWindowManager::the();
 
     if (&window == wm.m_highlight_window) {
-        border_color = wm.m_highlight_window_border_color;
-        border_color2 = wm.m_highlight_window_border_color2;
-        title_color = wm.m_highlight_window_title_color;
+        border_color = SystemColor::HighlightWindowBorder1;
+        border_color2 = SystemColor::HighlightWindowBorder2;
+        title_color = SystemColor::HighlightWindowTitle;
     } else if (&window == wm.m_move_window) {
-        border_color = wm.m_moving_window_border_color;
-        border_color2 = wm.m_moving_window_border_color2;
-        title_color = wm.m_moving_window_title_color;
+        border_color = SystemColor::MovingWindowBorder1;
+        border_color2 = SystemColor::MovingWindowBorder2;
+        title_color = SystemColor::MovingWindowTitle;
     } else if (&window == wm.m_active_window) {
-        border_color = wm.m_active_window_border_color;
-        border_color2 = wm.m_active_window_border_color2;
-        title_color = wm.m_active_window_title_color;
+        border_color = SystemColor::ActiveWindowBorder1;
+        border_color2 = SystemColor::ActiveWindowBorder2;
+        title_color = SystemColor::ActiveWindowTitle;
     } else {
-        border_color = wm.m_inactive_window_border_color;
-        border_color2 = wm.m_inactive_window_border_color2;
-        title_color = wm.m_inactive_window_title_color;
+        border_color = SystemColor::InactiveWindowBorder1;
+        border_color2 = SystemColor::InactiveWindowBorder2;
+        title_color = SystemColor::InactiveWindowTitle;
     }
 
     StylePainter::paint_window_frame(painter, outer_rect);

+ 67 - 33
Servers/WindowServer/WSWindowManager.cpp

@@ -6,6 +6,7 @@
 #include "WSMenuItem.h"
 #include "WSScreen.h"
 #include "WSWindow.h"
+#include <AK/FileSystemPath.h>
 #include <AK/LogStream.h>
 #include <AK/QuickSort.h>
 #include <AK/StdLibExtras.h>
@@ -17,6 +18,7 @@
 #include <LibDraw/PNGLoader.h>
 #include <LibDraw/Painter.h>
 #include <LibDraw/StylePainter.h>
+#include <LibDraw/SystemTheme.h>
 #include <WindowServer/WSButton.h>
 #include <WindowServer/WSClientConnection.h>
 #include <WindowServer/WSCursor.h>
@@ -47,19 +49,21 @@ WSWindowManager::WSWindowManager()
     reload_config(false);
 
     HashTable<String> seen_app_categories;
-    CDirIterator dt("/res/apps", CDirIterator::SkipDots);
-    while (dt.has_next()) {
-        auto af_name = dt.next_path();
-        auto af_path = String::format("/res/apps/%s", af_name.characters());
-        auto af = CConfigFile::open(af_path);
-        if (!af->has_key("App", "Name") || !af->has_key("App", "Executable"))
-            continue;
-        auto app_name = af->read_entry("App", "Name");
-        auto app_executable = af->read_entry("App", "Executable");
-        auto app_category = af->read_entry("App", "Category");
-        auto app_icon_path = af->read_entry("Icons", "16x16");
-        m_apps.append({ app_executable, app_name, app_icon_path, app_category });
-        seen_app_categories.set(app_category);
+    {
+        CDirIterator dt("/res/apps", CDirIterator::SkipDots);
+        while (dt.has_next()) {
+            auto af_name = dt.next_path();
+            auto af_path = String::format("/res/apps/%s", af_name.characters());
+            auto af = CConfigFile::open(af_path);
+            if (!af->has_key("App", "Name") || !af->has_key("App", "Executable"))
+                continue;
+            auto app_name = af->read_entry("App", "Name");
+            auto app_executable = af->read_entry("App", "Executable");
+            auto app_category = af->read_entry("App", "Category");
+            auto app_icon_path = af->read_entry("Icons", "16x16");
+            m_apps.append({ app_executable, app_name, app_icon_path, app_category });
+            seen_app_categories.set(app_category);
+        }
     }
 
     Vector<String> sorted_app_categories;
@@ -98,8 +102,56 @@ WSWindowManager::WSWindowManager()
         parent_menu->add_item(make<WSMenuItem>(*m_system_menu, app_identifier++, app.name, String(), true, false, false, load_png(app.icon_path)));
     }
 
+    m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
+
+    m_themes_menu = WSMenu::construct(nullptr, 9000, "Themes");
+
+    auto themes_menu_item = make<WSMenuItem>(*m_system_menu, 100, "Themes");
+    themes_menu_item->set_submenu_id(m_themes_menu->menu_id());
+    m_system_menu->add_item(move(themes_menu_item));
+
+    {
+        CDirIterator dt("/res/themes", CDirIterator::SkipDots);
+        while (dt.has_next()) {
+            auto theme_name = dt.next_path();
+            auto theme_path = String::format("/res/themes/%s", theme_name.characters());
+            m_themes.append({ FileSystemPath(theme_name).title(), theme_path });
+        }
+        quick_sort(m_themes.begin(), m_themes.end(), [](auto& a, auto& b) { return a.name < b.name; });
+    }
+
+    {
+        int theme_identifier = 9000;
+        for (auto& theme : m_themes) {
+            m_themes_menu->add_item(make<WSMenuItem>(*m_themes_menu, theme_identifier++, theme.name));
+        }
+    }
+
+    m_themes_menu->on_item_activation = [this](WSMenuItem& item) {
+        auto& theme = m_themes[(int)item.identifier() - 9000];
+        auto new_theme = load_system_theme(theme.path);
+        ASSERT(new_theme);
+        set_system_theme(*new_theme);
+        HashTable<WSClientConnection*> notified_clients;
+        for_each_window([&](WSWindow& window) {
+            if (window.client()) {
+                if (!notified_clients.contains(window.client())) {
+                    window.client()->post_message(WindowClient::UpdateSystemTheme(current_system_theme_buffer_id()));
+                    notified_clients.set(window.client());
+                }
+            }
+            return IterationDecision::Continue;
+        });
+        ++m_theme_index;
+        auto wm_config = CConfigFile::get_for_app("WindowManager");
+        wm_config->write_entry("Theme", "Name", theme.name);
+        wm_config->sync();
+        invalidate();
+    };
+
     m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
     m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 100, "Reload WM Config File"));
+
     m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
     m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 200, "About...", String(), true, false, false, load_png("/res/icons/16x16/ladybug.png")));
     m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
@@ -186,26 +238,6 @@ void WSWindowManager::reload_config(bool set_screen)
     m_disallowed_cursor = get_cursor("Disallowed");
     m_move_cursor = get_cursor("Move");
     m_drag_cursor = get_cursor("Drag");
-
-    m_background_color = m_wm_config->read_color_entry("Colors", "Background", Color::Red);
-
-    m_active_window_border_color = m_wm_config->read_color_entry("Colors", "ActiveWindowBorder", Color::Red);
-    m_active_window_border_color2 = m_wm_config->read_color_entry("Colors", "ActiveWindowBorder2", Color::Red);
-    m_active_window_title_color = m_wm_config->read_color_entry("Colors", "ActiveWindowTitle", Color::Red);
-
-    m_inactive_window_border_color = m_wm_config->read_color_entry("Colors", "InactiveWindowBorder", Color::Red);
-    m_inactive_window_border_color2 = m_wm_config->read_color_entry("Colors", "InactiveWindowBorder2", Color::Red);
-    m_inactive_window_title_color = m_wm_config->read_color_entry("Colors", "InactiveWindowTitle", Color::Red);
-
-    m_moving_window_border_color = m_wm_config->read_color_entry("Colors", "MovingWindowBorder", Color::Red);
-    m_moving_window_border_color2 = m_wm_config->read_color_entry("Colors", "MovingWindowBorder2", Color::Red);
-    m_moving_window_title_color = m_wm_config->read_color_entry("Colors", "MovingWindowTitle", Color::Red);
-
-    m_highlight_window_border_color = m_wm_config->read_color_entry("Colors", "HighlightWindowBorder", Color::Red);
-    m_highlight_window_border_color2 = m_wm_config->read_color_entry("Colors", "HighlightWindowBorder2", Color::Red);
-    m_highlight_window_title_color = m_wm_config->read_color_entry("Colors", "HighlightWindowTitle", Color::Red);
-
-    m_menu_selection_color = m_wm_config->read_color_entry("Colors", "MenuSelectionColor", Color::Red);
 }
 
 const Font& WSWindowManager::font() const
@@ -1183,6 +1215,8 @@ Rect WSWindowManager::maximized_window_rect(const WSWindow& window) const
 
 WSMenu* WSWindowManager::find_internal_menu_by_id(int menu_id)
 {
+    if (m_themes_menu->menu_id() == menu_id)
+        return m_themes_menu.ptr();
     for (auto& it : m_app_category_menus) {
         if (menu_id == it.value->menu_id())
             return it.value;

+ 11 - 0
Servers/WindowServer/WSWindowManager.h

@@ -159,6 +159,8 @@ public:
 
     WSMenu* find_internal_menu_by_id(int);
 
+    int theme_index() const { return m_theme_index; }
+
 private:
     NonnullRefPtr<WSCursor> get_cursor(const String& name);
     NonnullRefPtr<WSCursor> get_cursor(const String& name, const Point& hotspot);
@@ -266,6 +268,8 @@ private:
     Color m_menu_selection_color;
     WeakPtr<WSMenuBar> m_current_menubar;
 
+    int m_theme_index { 0 };
+
     WSWindowSwitcher m_switcher;
     WSMenuManager m_menu_manager;
 
@@ -283,6 +287,13 @@ private:
     Vector<AppMetadata> m_apps;
     HashMap<String, NonnullRefPtr<WSMenu>> m_app_category_menus;
 
+    struct ThemeMetadata {
+        String name;
+        String path;
+    };
+    Vector<ThemeMetadata> m_themes;
+    RefPtr<WSMenu> m_themes_menu;
+
     WeakPtr<WSClientConnection> m_dnd_client;
     String m_dnd_text;
     String m_dnd_data_type;

+ 2 - 0
Servers/WindowServer/WindowClient.ipc

@@ -32,4 +32,6 @@ endpoint WindowClient = 4
     DragCancelled() =|
 
     DragDropped(i32 window_id, Point mouse_position, String text, String data_type, String data) =|
+
+    UpdateSystemTheme(i32 system_theme_buffer_id) =|
 }

+ 1 - 1
Servers/WindowServer/WindowServer.ipc

@@ -1,6 +1,6 @@
 endpoint WindowServer = 2
 {
-    Greet() => (i32 client_id, Rect screen_rect)
+    Greet() => (i32 client_id, Rect screen_rect, i32 system_theme_buffer_id)
 
     CreateMenubar() => (i32 menubar_id)
     DestroyMenubar(i32 menubar_id) => ()

+ 8 - 1
Servers/WindowServer/main.cpp

@@ -1,4 +1,5 @@
 #include <LibCore/CConfigFile.h>
+#include <LibDraw/SystemTheme.h>
 #include <WindowServer/WSCompositor.h>
 #include <WindowServer/WSEventLoop.h>
 #include <WindowServer/WSScreen.h>
@@ -18,9 +19,15 @@ int main(int, char**)
         return 1;
     }
 
+    auto wm_config = CConfigFile::get_for_app("WindowManager");
+    auto theme_name = wm_config->read_entry("Theme", "Name", "Default");
+
+    auto theme = load_system_theme(String::format("/res/themes/%s.ini", theme_name.characters()));
+    ASSERT(theme);
+    set_system_theme(*theme);
+
     WSEventLoop loop;
 
-    auto wm_config = CConfigFile::get_for_app("WindowManager");
     WSScreen screen(wm_config->read_num_entry("Screen", "Width", 1024),
         wm_config->read_num_entry("Screen", "Height", 768));
     WSCompositor::the();