diff --git a/include/bar.hpp b/include/bar.hpp index 01903c58..efe83e92 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -89,7 +89,7 @@ class Bar public: Bar(); - std::unique_ptr opts; + std::shared_ptr opts; std::shared_ptr registry; void load(std::shared_ptr registry); @@ -98,6 +98,5 @@ class Bar std::string get_exec_line(); }; -std::shared_ptr &get_bar(); - -const Options& bar_opts(); +std::shared_ptr get_bar(); +std::shared_ptr bar_opts(); diff --git a/include/registry.hpp b/include/registry.hpp index e59e6fcf..3668df05 100644 --- a/include/registry.hpp +++ b/include/registry.hpp @@ -1,5 +1,6 @@ #pragma once +#include "exception.hpp" #include "modules/base.hpp" DefineBaseException(RegistryError); diff --git a/include/services/builder.hpp b/include/services/builder.hpp index eb4674bf..2c7047c8 100644 --- a/include/services/builder.hpp +++ b/include/services/builder.hpp @@ -3,6 +3,7 @@ #include #include +#include "bar.hpp" #include "drawtypes/animation.hpp" #include "drawtypes/bar.hpp" #include "drawtypes/icon.hpp" @@ -41,8 +42,12 @@ class Builder void align_center(); void align_right(); + std::shared_ptr opts; + public: - explicit Builder(bool lazy_closing = true) : lazy_closing(lazy_closing){} + explicit Builder(bool lazy_closing = true) + : lazy_closing(lazy_closing) + , opts(bar_opts()) {} void set_lazy_closing(bool mode) { this->lazy_closing = mode; } diff --git a/include/version.hpp b/include/version.hpp index 84ca4333..2cecdc79 100644 --- a/include/version.hpp +++ b/include/version.hpp @@ -1,3 +1,3 @@ #pragma once -#define GIT_TAG "1.4.1-3-g6329b56-dev" +#define GIT_TAG "1.4.1-5-gf406f1e-dev" diff --git a/src/bar.cpp b/src/bar.cpp index e8943e93..294cad04 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -28,21 +28,21 @@ #endif std::shared_ptr bar; -std::shared_ptr &get_bar() +std::shared_ptr get_bar() { if (bar == nullptr) bar = std::make_shared(); return bar; } -const Options& bar_opts() { - return *bar->opts.get(); +std::shared_ptr bar_opts() { + return bar->opts; } /** * Bar constructor */ -Bar::Bar() : config_path(config::get_bar_path()), opts(std::make_unique()) +Bar::Bar() : config_path(config::get_bar_path()), opts(std::make_shared()) { struct Options defaults; diff --git a/src/modules/date.cpp b/src/modules/date.cpp index 87c6934d..577745cb 100644 --- a/src/modules/date.cpp +++ b/src/modules/date.cpp @@ -26,7 +26,7 @@ bool DateModule::update() auto date_format = this->detailed ? this->date_detailed : this->date; auto time = std::time(nullptr); char new_str[256] = {0,}; - std::strftime(new_str, sizeof(this->date_str), date_format.c_str(), std::localtime(&time)); + std::strftime(new_str, sizeof(new_str), date_format.c_str(), std::localtime(&time)); if (std::strncmp(new_str, this->date_str, sizeof(new_str)) == 0) return false; @@ -40,7 +40,7 @@ std::string DateModule::get_output() { if (!this->date_detailed.empty()) this->builder->cmd(Cmd::LEFT_CLICK, EVENT_TOGGLE); - this->builder->node(this->Module::get_output()); + this->builder->node(this->TimerModule::get_output()); return this->builder->flush(); } diff --git a/src/services/builder.cpp b/src/services/builder.cpp index f62f187f..527f16cb 100644 --- a/src/services/builder.cpp +++ b/src/services/builder.cpp @@ -6,7 +6,6 @@ #include "config.hpp" #include "exception.hpp" -#include "bar.hpp" #include "services/builder.hpp" #include "utils/string.hpp" #include "utils/math.hpp" @@ -94,12 +93,12 @@ void Builder::append_module_output(Alignment alignment, std::string module_outpu int margin; - if (margin_left && (margin= bar_opts().module_margin_left) > 0) + if (margin_left && (margin= this->opts->module_margin_left) > 0) this->output += std::string(margin, ' '); this->append(module_output); - if (margin_right && (margin = bar_opts().module_margin_right) > 0) + if (margin_right && (margin = this->opts->module_margin_right) > 0) this->output += std::string(margin, ' '); } @@ -272,7 +271,7 @@ void Builder::offset(int pixels) void Builder::space(int width) { - if (width == DEFAULT_SPACING) width = bar_opts().spacing; + if (width == DEFAULT_SPACING) width = this->opts->spacing; if (width <= 0) return; std::string str(width, ' '); this->append(str); @@ -280,7 +279,7 @@ void Builder::space(int width) void Builder::remove_trailing_space(int width) { - if (width == DEFAULT_SPACING) width = bar_opts().spacing; + if (width == DEFAULT_SPACING) width = this->opts->spacing; if (width <= 0) return; std::string::size_type spacing = width; std::string str(spacing, ' '); @@ -324,7 +323,7 @@ void Builder::background(std::string color_) if (color.length() == 2 || (color.find("#") == 0 && color.length() == 3)) { color = "#"+ color.substr(color.length()-2); - auto bg = bar_opts().background; + auto bg = this->opts->background; color += bg.substr(bg.length()-(bg.length() < 6 ? 3 : 6)); } else if (color.length() >= 7 && color == "#"+ std::string(color.length()-1, color[1])) { color = color.substr(0, 4); @@ -353,7 +352,7 @@ void Builder::color(std::string color_) auto color(color_); if (color.length() == 2 || (color.find("#") == 0 && color.length() == 3)) { color = "#"+ color.substr(color.length()-2); - auto bg = bar_opts().foreground; + auto bg = this->opts->foreground; color += bg.substr(bg.length()-(bg.length() < 6 ? 3 : 6)); } else if (color.length() >= 7 && color == "#"+ std::string(color.length()-1, color[1])) { color = color.substr(0, 4); @@ -371,7 +370,7 @@ void Builder::color(std::string color_) void Builder::color_alpha(std::string alpha_) { auto alpha(alpha_); - std::string val = bar_opts().foreground; + std::string val = this->opts->foreground; if (val.size() < 6 && val.size() > 2) { val.append(val.substr(val.size() - 3)); } else if (val.length() > 6) {