diff --git a/src/config.cc b/src/config.cc index 317e2f1..a012764 100644 --- a/src/config.cc +++ b/src/config.cc @@ -158,7 +158,7 @@ void Config::read(const boost::property_tree::ptree &cfg) { if(source.smart_inserts) source.smart_brackets = true; source.show_map = source_json.get("show_map"); - source.map_font_size = source_json.get("map_font_size"); + source.map_font_size = source_json.get("map_font_size"); source.show_git_diff = source_json.get("show_git_diff"); source.show_background_pattern = source_json.get("show_background_pattern"); source.show_right_margin = source_json.get("show_right_margin"); diff --git a/src/config.h b/src/config.h index cff6dc1..600e700 100644 --- a/src/config.h +++ b/src/config.h @@ -74,7 +74,7 @@ public: bool smart_inserts; bool show_map; - std::string map_font_size; + unsigned map_font_size; bool show_git_diff; bool show_background_pattern; bool show_right_margin; diff --git a/src/notebook.cc b/src/notebook.cc index 556f681..0fd01c1 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -289,6 +289,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, Position position source_maps.emplace_back(Glib::wrap(gtk_source_map_new())); gtk_source_map_set_view(GTK_SOURCE_MAP(source_maps.back()->gobj()), view->gobj()); + source_maps.back()->get_style_context()->add_class("juci_source_map"); configure(source_views.size() - 1); @@ -462,9 +463,6 @@ void Notebook::open_uri(const std::string &uri) { void Notebook::configure(size_t index) { - auto source_font_description = Pango::FontDescription(Config::get().source.font); - auto source_map_font_desc = Pango::FontDescription(source_font_description.get_family() + " " + Config::get().source.map_font_size); - source_maps.at(index)->override_font(source_map_font_desc); if(Config::get().source.show_map) { if(hboxes.at(index)->get_children().size() == 1) hboxes.at(index)->pack_end(*source_maps.at(index), Gtk::PACK_SHRINK); diff --git a/src/source.cc b/src/source.cc index 032c1ba..6a0d0e6 100644 --- a/src/source.cc +++ b/src/source.cc @@ -380,8 +380,6 @@ void Source::View::configure() { set_wrap_mode(Gtk::WrapMode::WRAP_NONE); property_highlight_current_line() = Config::get().source.highlight_current_line; line_renderer->set_visible(Config::get().source.show_line_numbers); - if(Config::get().source.font.size() > 0) - override_font(Pango::FontDescription(Config::get().source.font)); #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 20) Gdk::Rectangle rectangle; diff --git a/src/source_base.cc b/src/source_base.cc index 599b501..32e2213 100644 --- a/src/source_base.cc +++ b/src/source_base.cc @@ -10,6 +10,8 @@ #include Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : Gsv::View(), file_path(file_path), language(language), status_diagnostics(0, 0, 0) { + get_style_context()->add_class("juci_source_view"); + load(true); get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); diff --git a/src/terminal.cc b/src/terminal.cc index 5233173..4e1a011 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -9,6 +9,8 @@ #include Terminal::Terminal() { + get_style_context()->add_class("juci_terminal"); + set_editable(false); bold_tag = get_buffer()->create_tag(); @@ -319,21 +321,6 @@ void Terminal::async_print(size_t line_nr, const std::string &message) { void Terminal::configure() { link_tag->property_foreground_rgba() = get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_LINK); - - if(Config::get().terminal.font.size() > 0) { - override_font(Pango::FontDescription(Config::get().terminal.font)); - } - else if(Config::get().source.font.size() > 0) { - Pango::FontDescription font_description(Config::get().source.font); - auto font_description_size = font_description.get_size(); - if(font_description_size == 0) { - Pango::FontDescription default_font_description(Gtk::Settings::get_default()->property_gtk_font_name()); - font_description_size = default_font_description.get_size(); - } - if(font_description_size > 0) - font_description.set_size(font_description_size * 0.95); - override_font(font_description); - } } void Terminal::clear() { diff --git a/src/window.cc b/src/window.cc index 6867d88..8fa2289 100644 --- a/src/window.cc +++ b/src/window.cc @@ -147,6 +147,8 @@ Window::Window() { void Window::configure() { Config::get().load(); auto screen = get_screen(); + + static Glib::RefPtr css_provider_theme; if(css_provider_theme) Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_theme); if(Config::get().theme.name.empty()) { @@ -158,36 +160,73 @@ void Window::configure() { //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(); + static Glib::RefPtr css_provider_fonts; + if(css_provider_fonts) + Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_fonts); + else + css_provider_fonts = Gtk::CssProvider::create(); + + auto font_description_to_style = [](const Pango::FontDescription &font_description) { + 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;"; + return family + size; + }; + auto font_description_string_to_style = [&font_description_to_style](const std::string font_description_string) { + return font_description_to_style(Pango::FontDescription(font_description_string)); + }; + + std::string fonts_style; + if(!Config::get().theme.font.empty()) + fonts_style += "* {" + font_description_string_to_style(Config::get().theme.font) + "}"; + if(!Config::get().source.font.empty()) { + auto font_description = Pango::FontDescription(Config::get().source.font); + fonts_style += ".juci_source_view {" + font_description_to_style(font_description) + "}"; + font_description.set_size(Config::get().source.map_font_size * 1024); + fonts_style += ".juci_source_map {" + font_description_to_style(font_description) + "}"; + } + else + fonts_style += ".juci_source_map {" + font_description_string_to_style(std::to_string(Config::get().source.map_font_size)) + "}"; + if(!Config::get().terminal.font.empty()) + fonts_style += ".juci_terminal {" + font_description_string_to_style(Config::get().terminal.font) + "}"; + else { + Pango::FontDescription font_description(Config::get().source.font); + auto font_description_size = font_description.get_size(); + if(font_description_size > 0) { + font_description.set_size(font_description_size * 0.95); + fonts_style += ".juci_terminal {" + font_description_to_style(font_description) + "}"; + } + else { 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); + fonts_style += ".juci_terminal {" + family + "font-size: 95%;}"; + } + } + + if(!fonts_style.empty()) { + try { + css_provider_fonts->load_from_data(fonts_style); + get_style_context()->add_provider_for_screen(screen, css_provider_fonts, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } catch(const Gtk::CssProviderError &e) { - Terminal::get().print("Error: could not override theme font: " + e.what() + '\n', true); + Terminal::get().print("Error: could not override fonts: " + e.what() + '\n', true); } } - auto style_scheme_manager = Source::StyleSchemeManager::get_default(); + static Glib::RefPtr css_provider_tooltips; if(css_provider_tooltips) Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_tooltips); else css_provider_tooltips = Gtk::CssProvider::create(); Glib::RefPtr style; if(Config::get().source.style.size() > 0) { - auto scheme = style_scheme_manager->get_scheme(Config::get().source.style); + auto scheme = Source::StyleSchemeManager::get_default()->get_scheme(Config::get().source.style); if(scheme) style = scheme->get_style("def:note"); else { diff --git a/src/window.h b/src/window.h index 41f146f..6378d87 100644 --- a/src/window.h +++ b/src/window.h @@ -22,10 +22,6 @@ protected: private: Gtk::AboutDialog about; - Glib::RefPtr css_provider_theme; - Glib::RefPtr css_provider_theme_font; - Glib::RefPtr css_provider_tooltips; - void configure(); void set_menu_actions(); void search_and_replace_entry();