20
20
#include "config.h"
21
21
#include "DecorationStyle.h"
23
24
#include <NuxCore/Colors.h>
24
25
#include <NuxCore/Logger.h>
26
#include <UnityCore/ConnectionManager.h>
25
27
#include <UnityCore/GLibWrapper.h>
26
28
#include <UnityCore/GLibSignal.h>
31
#include "ThemeSettings.h"
53
57
const int DEFAULT_GLOW_SIZE = 10;
54
58
const nux::Color DEFAULT_GLOW_COLOR(221, 72, 20);
56
const std::array<std::string, 2> THEMED_FILE_EXTENSIONS = { "svg", "png" };
57
60
const std::array<std::string, size_t(WindowButtonType::Size)> WBUTTON_NAMES = { "close", "minimize", "unmaximize", "maximize" };
58
61
const std::array<std::string, size_t(WidgetState::Size)> WBUTTON_STATES = {"", "_focused_prelight", "_focused_pressed", "_unfocused",
59
62
"_unfocused", "_unfocused_prelight", "_unfocused_pressed" };
157
160
gtk_widget_path_append_type(widget_path.get(), unity_decoration_get_type());
158
161
gtk_style_context_set_path(ctx_, widget_path.get());
160
parent_->theme = glib::String(GetSettingValue<gchar*>("gtk-theme-name")).Str();
161
parent_->font = glib::String(GetSettingValue<gchar*>("gtk-font-name")).Str();
163
auto theme_settings = theme::Settings::Get();
164
parent_->theme.SetGetterFunction([theme_settings] { return theme_settings->theme(); });
165
parent_->font.SetGetterFunction([theme_settings] { return theme_settings->font(); });
162
166
parent_->font_scale = 1.0;
166
170
UpdateMenuItemPangoContext(parent_->font);
167
171
UpdateThemedValues();
169
GtkSettings* settings = gtk_settings_get_default();
170
signals_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-theme-name", [this] (GtkSettings*, GParamSpec*) {
173
connections_.Add(theme_settings->theme.changed.connect([this] (std::string const& theme) {
171
174
#if !GTK_CHECK_VERSION(3, 11, 0)
172
175
gtk_style_context_invalidate(ctx_);
174
177
UpdateThemedValues();
175
parent_->theme = glib::String(GetSettingValue<gchar*>("gtk-theme-name")).Str();
176
LOG_INFO(logger) << "gtk-theme-name changed to " << parent_->theme();
178
parent_->theme.EmitChanged(theme);
179
LOG_INFO(logger) << "unity theme changed to " << parent_->theme();
179
signals_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-font-name", [this] (GtkSettings*, GParamSpec*) {
180
auto const& font = glib::String(GetSettingValue<gchar*>("gtk-font-name")).Str();
182
connections_.Add(theme_settings->font.changed.connect([this] (std::string const& font) {
181
183
UpdateMenuItemPangoContext(font);
182
parent_->font = font;
184
parent_->font.EmitChanged(font);
184
186
if (g_settings_get_boolean(settings_, USE_SYSTEM_FONT_KEY.c_str()))
186
188
UpdateTitlePangoContext(parent_->font());
187
189
parent_->title_font = parent_->font();
190
LOG_INFO(logger) << "gtk-font-name changed to " << parent_->font();
191
LOG_INFO(logger) << "unity font changed to " << parent_->font();
193
194
parent_->font_scale.changed.connect([this] (bool scale) {
194
195
UpdateTitlePangoContext(parent_->title_font);
300
template <typename TYPE>
301
inline TYPE GetSettingValue(std::string const& name)
304
g_object_get(gtk_settings_get_default(), name.c_str(), &value, nullptr);
308
301
WMAction WMActionFromString(std::string const& action) const
310
303
if (action == "toggle-shade")
391
384
gtk_style_context_restore(ctx_);
394
std::string ThemedFilePath(std::string const& base_filename, std::vector<std::string> const& extra_folders = {}) const
396
auto const& theme = parent_->theme();
397
const char* home_dir = g_get_home_dir();
398
const char* gtk_prefix = g_getenv("GTK_DATA_PREFIX");
400
gtk_prefix = GTK_PREFIX;
402
for (auto const& extension : THEMED_FILE_EXTENSIONS)
404
auto filename = base_filename + '.' + extension;
405
glib::String subpath(g_build_filename(theme.c_str(), "unity", filename.c_str(), nullptr));
407
// Look in home directory
410
glib::String local_file(g_build_filename(home_dir, ".local", "share", "themes", subpath.Value(), nullptr));
412
if (g_file_test(local_file, G_FILE_TEST_EXISTS))
413
return local_file.Str();
415
glib::String home_file(g_build_filename(home_dir, ".themes", subpath.Value(), nullptr));
417
if (g_file_test(home_file, G_FILE_TEST_EXISTS))
418
return home_file.Str();
421
glib::String path(g_build_filename(gtk_prefix, "share", "themes", subpath.Value(), nullptr));
423
if (g_file_test(path, G_FILE_TEST_EXISTS))
426
for (auto const& folder : extra_folders)
428
glib::String path(g_build_filename(folder.c_str(), filename.c_str(), nullptr));
430
if (g_file_test(path, G_FILE_TEST_EXISTS))
435
return std::string();
438
387
std::string WindowButtonFile(WindowButtonType type, WidgetState state) const
440
389
auto base_filename = WBUTTON_NAMES[unsigned(type)] + WBUTTON_STATES[unsigned(state)];
441
auto const& file_path = ThemedFilePath(base_filename);
390
auto const& file_path = parent_->ThemedFilePath(base_filename);
443
392
if (!file_path.empty())
444
393
return file_path;
677
626
glib::Object<GSettings> usettings_;
678
627
glib::Object<PangoContext> title_pango_ctx_;
679
628
glib::Object<PangoContext> menu_item_pango_ctx_;
629
connection::Manager connections_;
680
630
decoration::Border border_;
681
631
decoration::Border input_edges_;
682
632
decoration::Border radius_;
752
702
std::string Style::ThemedFilePath(std::string const& basename, std::vector<std::string> const& extra_folders) const
754
return impl_->ThemedFilePath(basename, extra_folders);
704
return theme::Settings::Get()->ThemedFilePath(basename, extra_folders);
757
707
std::string Style::WindowButtonFile(WindowButtonType type, WidgetState state) const
833
783
int Style::DoubleClickMaxDistance() const
835
return impl_->GetSettingValue<int>("gtk-double-click-distance");
785
return gtk::GetSettingValue<int>("gtk-double-click-distance");
838
788
int Style::DoubleClickMaxTimeDelta() const
840
return impl_->GetSettingValue<int>("gtk-double-click-time");
790
return gtk::GetSettingValue<int>("gtk-double-click-time");
843
793
nux::Size Style::TitleNaturalSize(std::string const& text)