mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +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:
parent
7c8bbea995
commit
411058b2a3
50 changed files with 525 additions and 178 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue