diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4201f..c0589d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.4.6.2") +set(JUCI_VERSION "1.4.6.3") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/src/config.cc b/src/config.cc index 114b814..e79e032 100644 --- a/src/config.cc +++ b/src/config.cc @@ -184,9 +184,11 @@ void Config::read(const boost::property_tree::ptree &cfg) { } } - window.theme_name = cfg.get("gtk_theme.name"); - window.theme_variant = cfg.get("gtk_theme.variant"); - window.version = cfg.get("version"); + version = cfg.get("version"); + + theme.name = cfg.get("gtk_theme.name"); + theme.variant = cfg.get("gtk_theme.variant"); + theme.font = cfg.get("gtk_theme.font"); project.default_build_path = cfg.get("project.default_build_path"); project.debug_build_path = cfg.get("project.debug_build_path"); diff --git a/src/config.h b/src/config.h index ee5a0f4..b744516 100644 --- a/src/config.h +++ b/src/config.h @@ -14,11 +14,11 @@ public: std::unordered_map keys; }; - class Window { + class Theme { public: - std::string theme_name; - std::string theme_variant; - std::string version; + std::string name; + std::string variant; + std::string font; }; class Terminal { @@ -111,8 +111,9 @@ public: void load(); + std::string version; Menu menu; - Window window; + Theme theme; Terminal terminal; Project project; Source source; diff --git a/src/files.h b/src/files.h index 9a66d44..044cb52 100644 --- a/src/files.h +++ b/src/files.h @@ -10,7 +10,9 @@ const std::string default_config_file = R"RAW({ "name_comment": "Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh", "name": "", "variant_comment": "Use \"\" for default variant, and \"dark\" for dark theme variant. Note that not all themes support dark variant, but for instance Adwaita does", - "variant": "" + "variant": "", + "font_comment": "Set to override theme font, for instance: \"Arial 12\"", + "font": "" }, "source": { "style_comment": "Use \"\" for default style, and for instance juci-dark or juci-dark-blue together with dark gtk_theme variant. Styles from normal gtksourceview install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango", diff --git a/src/window.cc b/src/window.cc index 6ec5767..d3cf905 100644 --- a/src/window.cc +++ b/src/window.cc @@ -122,7 +122,7 @@ Window::Window() { }); about.set_logo_icon_name("juci"); - about.set_version(Config::get().window.version); + about.set_version(Config::get().version); about.set_authors({"(in order of appearance)", "Ted Johan Kristoffersen", "Jørgen Lien Sellæg", @@ -140,15 +140,37 @@ void Window::configure() { auto screen = get_screen(); if(css_provider_theme) Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_theme); - if(Config::get().window.theme_name.empty()) { + if(Config::get().theme.name.empty()) { css_provider_theme = Gtk::CssProvider::create(); - Gtk::Settings::get_default()->property_gtk_application_prefer_dark_theme() = (Config::get().window.theme_variant == "dark"); + Gtk::Settings::get_default()->property_gtk_application_prefer_dark_theme() = (Config::get().theme.variant == "dark"); } else - css_provider_theme = Gtk::CssProvider::get_named(Config::get().window.theme_name, Config::get().window.theme_variant); + css_provider_theme = Gtk::CssProvider::get_named(Config::get().theme.name, Config::get().theme.variant); //TODO: add check if theme exists, or else write error to terminal Gtk::StyleContext::add_provider_for_screen(screen, css_provider_theme, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS); + if(css_provider_theme_font) + Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_theme_font); + if(!Config::get().theme.font.empty()) { + Pango::FontDescription font_description(Config::get().theme.font); + try { + css_provider_theme_font = Gtk::CssProvider::create(); + auto family = font_description.get_family(); + auto size = std::to_string(font_description.get_size() / 1024); + if(size == "0") + size.clear(); + if(!family.empty()) + family = "font-family: " + family + ';'; + if(!size.empty()) + size = "font-size: " + size + "px;"; + css_provider_theme_font->load_from_data("* {" + family + size + "}"); + get_style_context()->add_provider_for_screen(screen, css_provider_theme_font, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } + catch(const Gtk::CssProviderError &e) { + Terminal::get().print("Error: could not override theme font: " + e.what() + '\n', true); + } + } + auto style_scheme_manager = Source::StyleSchemeManager::get_default(); if(css_provider_tooltips) Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_tooltips); diff --git a/src/window.h b/src/window.h index 20b4a50..41f146f 100644 --- a/src/window.h +++ b/src/window.h @@ -23,6 +23,7 @@ private: Gtk::AboutDialog about; Glib::RefPtr css_provider_theme; + Glib::RefPtr css_provider_theme_font; Glib::RefPtr css_provider_tooltips; void configure();