diff --git a/include/components/config.hpp b/include/components/config.hpp index d3bd3820..3169b17f 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -23,7 +23,7 @@ class config { using make_type = const config&; static make_type make(string path = "", string bar = ""); - explicit config(const logger& logger, unique_ptr&& xrm, string&& path = "", string&& bar = ""); + explicit config(const logger& logger, const xresource_manager& xrm, string&& path = "", string&& bar = ""); string filepath() const; string section() const; @@ -285,10 +285,10 @@ class config { size_t pos; if ((pos = var.find(":")) != string::npos) { - return convert(m_xrm->get_string(var.substr(0, pos), var.substr(pos + 1))); + return convert(m_xrm.get_string(var.substr(0, pos), var.substr(pos + 1))); } - string str{m_xrm->get_string(var, "")}; + string str{m_xrm.get_string(var, "")}; return str.empty() ? fallback : convert(move(str)); } @@ -310,7 +310,7 @@ class config { private: static constexpr const char* KEY_INHERIT{"inherit"}; const logger& m_log; - unique_ptr m_xrm; + const xresource_manager& m_xrm; string m_file; string m_barname; sectionmap_t m_sections{}; diff --git a/include/x11/xresources.hpp b/include/x11/xresources.hpp index c2d9409d..7f2f3431 100644 --- a/include/x11/xresources.hpp +++ b/include/x11/xresources.hpp @@ -9,7 +9,7 @@ POLYBAR_NS class xresource_manager { public: - using make_type = unique_ptr; + using make_type = const xresource_manager&; static make_type make(); explicit xresource_manager(Display*); diff --git a/src/components/config.cpp b/src/components/config.cpp index 2425285d..ef9cb11d 100644 --- a/src/components/config.cpp +++ b/src/components/config.cpp @@ -22,7 +22,7 @@ config::make_type config::make(string path, string bar) { /** * Construct config object */ -config::config(const logger& logger, unique_ptr&& xrm, string&& path, string&& bar) +config::config(const logger& logger, const xresource_manager& xrm, string&& path, string&& bar) : m_log(logger) , m_xrm(forward(xrm)) , m_file(forward(path)) diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index b2d35582..1c9ed0e8 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -63,7 +63,7 @@ tray_manager::~tray_manager() { } void tray_manager::setup(const bar_settings& bar_opts) { - auto& conf = config::make(); + const config& conf = config::make(); auto bs = conf.section(); string position; diff --git a/src/x11/xresources.cpp b/src/x11/xresources.cpp index 5fc11556..45d04575 100644 --- a/src/x11/xresources.cpp +++ b/src/x11/xresources.cpp @@ -12,7 +12,7 @@ POLYBAR_NS * Create instance */ xresource_manager::make_type xresource_manager::make() { - return factory_util::unique(static_cast(connection::make())); + return *factory_util::singleton(static_cast(connection::make())); } /** @@ -30,7 +30,7 @@ xresource_manager::xresource_manager(Display* dsp) { * Deconstruct instance */ xresource_manager::~xresource_manager() { - if (m_db != nullptr) { + if (m_manager != nullptr) { XrmDestroyDatabase(m_db); } } @@ -72,7 +72,7 @@ int xresource_manager::get_int(string name, int fallback) const { * Query the database for given key */ string xresource_manager::load_value(const string& key, const string& res_type, size_t n) const { - if (m_manager != nullptr && m_db != nullptr) { + if (m_manager != nullptr) { char* type = nullptr; XrmValue ret{};