2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-02-14 22:02:47 +00:00
|
|
|
#include <AK/SharedBuffer.h>
|
2020-02-06 14:04:03 +00:00
|
|
|
#include <LibCore/ConfigFile.h>
|
2020-02-06 11:04:00 +00:00
|
|
|
#include <LibGfx/SystemTheme.h>
|
2019-12-23 19:24:26 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
namespace Gfx {
|
|
|
|
|
2019-12-23 19:24:26 +00:00
|
|
|
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);
|
2020-02-28 10:45:19 +00:00
|
|
|
return theme_buffer->shbuf_id();
|
2019-12-23 19:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_system_theme(SharedBuffer& buffer)
|
|
|
|
{
|
|
|
|
theme_buffer = buffer;
|
|
|
|
theme_page = (SystemTheme*)theme_buffer->data();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|
|
|
{
|
2020-02-02 11:34:39 +00:00
|
|
|
auto file = Core::ConfigFile::open(path);
|
2019-12-23 19:24:26 +00:00
|
|
|
auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme));
|
|
|
|
|
|
|
|
auto* data = (SystemTheme*)buffer->data();
|
|
|
|
|
2020-01-05 23:47:55 +00:00
|
|
|
auto get_color = [&](auto& name) {
|
2019-12-23 19:24:26 +00:00
|
|
|
auto color_string = file->read_entry("Colors", name);
|
|
|
|
auto color = Color::from_string(color_string);
|
|
|
|
if (!color.has_value())
|
|
|
|
return Color(Color::Black);
|
|
|
|
return color.value();
|
|
|
|
};
|
|
|
|
|
2020-07-17 00:27:55 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-07-29 20:09:04 +00:00
|
|
|
auto get_path = [&](auto& name, auto role) {
|
|
|
|
auto path = file->read_entry("Paths", name);
|
|
|
|
if (path.is_empty()) {
|
|
|
|
switch (role) {
|
|
|
|
case (int)PathRole::TitleButtonIcons:
|
|
|
|
return "/res/icons/16x16/";
|
|
|
|
default:
|
|
|
|
return "/res/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &path[0];
|
|
|
|
};
|
|
|
|
|
2019-12-24 19:57:54 +00:00
|
|
|
#define DO_COLOR(x) \
|
2020-01-05 23:47:55 +00:00
|
|
|
data->color[(int)ColorRole::x] = get_color(#x)
|
2019-12-24 19:57:54 +00:00
|
|
|
|
|
|
|
DO_COLOR(DesktopBackground);
|
|
|
|
DO_COLOR(ThreedHighlight);
|
|
|
|
DO_COLOR(ThreedShadow1);
|
|
|
|
DO_COLOR(ThreedShadow2);
|
|
|
|
DO_COLOR(HoverHighlight);
|
|
|
|
DO_COLOR(Selection);
|
|
|
|
DO_COLOR(SelectionText);
|
2020-02-15 15:20:26 +00:00
|
|
|
DO_COLOR(InactiveSelection);
|
|
|
|
DO_COLOR(InactiveSelectionText);
|
2019-12-24 19:57:54 +00:00
|
|
|
DO_COLOR(Window);
|
|
|
|
DO_COLOR(WindowText);
|
|
|
|
DO_COLOR(Base);
|
2019-12-24 21:01:32 +00:00
|
|
|
DO_COLOR(BaseText);
|
2019-12-24 19:57:54 +00:00
|
|
|
DO_COLOR(Button);
|
|
|
|
DO_COLOR(ButtonText);
|
|
|
|
DO_COLOR(DesktopBackground);
|
|
|
|
DO_COLOR(ActiveWindowBorder1);
|
|
|
|
DO_COLOR(ActiveWindowBorder2);
|
|
|
|
DO_COLOR(ActiveWindowTitle);
|
2020-08-01 17:09:18 +00:00
|
|
|
DO_COLOR(ActiveWindowTitleShadow);
|
|
|
|
DO_COLOR(ActiveWindowTitleStripes);
|
2019-12-24 19:57:54 +00:00
|
|
|
DO_COLOR(InactiveWindowBorder1);
|
|
|
|
DO_COLOR(InactiveWindowBorder2);
|
|
|
|
DO_COLOR(InactiveWindowTitle);
|
2020-08-01 17:09:18 +00:00
|
|
|
DO_COLOR(InactiveWindowTitleShadow);
|
|
|
|
DO_COLOR(InactiveWindowTitleStripes);
|
2019-12-24 19:57:54 +00:00
|
|
|
DO_COLOR(MovingWindowBorder1);
|
|
|
|
DO_COLOR(MovingWindowBorder2);
|
|
|
|
DO_COLOR(MovingWindowTitle);
|
2020-08-01 17:09:18 +00:00
|
|
|
DO_COLOR(MovingWindowTitleShadow);
|
|
|
|
DO_COLOR(MovingWindowTitleStripes);
|
2019-12-24 19:57:54 +00:00
|
|
|
DO_COLOR(HighlightWindowBorder1);
|
|
|
|
DO_COLOR(HighlightWindowBorder2);
|
|
|
|
DO_COLOR(HighlightWindowTitle);
|
2020-08-01 17:09:18 +00:00
|
|
|
DO_COLOR(HighlightWindowTitleShadow);
|
|
|
|
DO_COLOR(HighlightWindowTitleStripes);
|
2019-12-24 19:57:54 +00:00
|
|
|
DO_COLOR(MenuStripe);
|
|
|
|
DO_COLOR(MenuBase);
|
2019-12-25 23:58:46 +00:00
|
|
|
DO_COLOR(MenuBaseText);
|
2019-12-24 19:57:54 +00:00
|
|
|
DO_COLOR(MenuSelection);
|
2019-12-25 23:58:46 +00:00
|
|
|
DO_COLOR(MenuSelectionText);
|
2020-01-05 23:47:55 +00:00
|
|
|
DO_COLOR(RubberBandFill);
|
|
|
|
DO_COLOR(RubberBandBorder);
|
2020-01-13 19:33:15 +00:00
|
|
|
DO_COLOR(Link);
|
|
|
|
DO_COLOR(ActiveLink);
|
|
|
|
DO_COLOR(VisitedLink);
|
2020-02-19 10:07:12 +00:00
|
|
|
DO_COLOR(Ruler);
|
|
|
|
DO_COLOR(RulerBorder);
|
|
|
|
DO_COLOR(RulerActiveText);
|
|
|
|
DO_COLOR(RulerInactiveText);
|
2020-02-20 08:01:48 +00:00
|
|
|
DO_COLOR(TextCursor);
|
2020-02-20 12:36:58 +00:00
|
|
|
DO_COLOR(FocusOutline);
|
2020-03-15 23:05:06 +00:00
|
|
|
DO_COLOR(SyntaxComment);
|
|
|
|
DO_COLOR(SyntaxNumber);
|
|
|
|
DO_COLOR(SyntaxString);
|
|
|
|
DO_COLOR(SyntaxType);
|
|
|
|
DO_COLOR(SyntaxPunctuation);
|
|
|
|
DO_COLOR(SyntaxOperator);
|
|
|
|
DO_COLOR(SyntaxKeyword);
|
|
|
|
DO_COLOR(SyntaxControlKeyword);
|
|
|
|
DO_COLOR(SyntaxIdentifier);
|
|
|
|
DO_COLOR(SyntaxPreprocessorStatement);
|
|
|
|
DO_COLOR(SyntaxPreprocessorValue);
|
2019-12-23 19:24:26 +00:00
|
|
|
|
2020-07-17 00:27:55 +00:00
|
|
|
#define DO_METRIC(x) \
|
|
|
|
data->metric[(int)MetricRole::x] = get_metric(#x, (int)MetricRole::x)
|
|
|
|
|
|
|
|
DO_METRIC(TitleHeight);
|
|
|
|
DO_METRIC(TitleButtonWidth);
|
|
|
|
DO_METRIC(TitleButtonHeight);
|
|
|
|
|
2020-07-29 20:09:04 +00:00
|
|
|
#define DO_PATH(x) \
|
|
|
|
data->path[(int)PathRole::x] = get_path(#x, (int)PathRole::x)
|
|
|
|
|
|
|
|
DO_PATH(TitleButtonIcons);
|
|
|
|
|
2019-12-23 19:24:26 +00:00
|
|
|
buffer->seal();
|
|
|
|
buffer->share_globally();
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
2020-02-06 10:56:38 +00:00
|
|
|
|
|
|
|
}
|