diff --git a/include/components/config.hpp b/include/components/config.hpp index d5ea951d..ea79b218 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -22,7 +22,7 @@ class config { using make_type = const config&; static make_type make(string path = "", string bar = ""); - explicit config(const logger& logger, const xresource_manager& xrm, string&& path = "", string&& bar = ""); + explicit config(const logger& logger, string&& path = "", string&& bar = ""); string filepath() const; string section() const; @@ -263,13 +263,14 @@ class config { */ template T dereference_xrdb(string var, const T& fallback) const { + const auto& xrm = xresource_manager::make(); 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(xrm->get_string(var.substr(0, pos), var.substr(pos + 1))); } - string str{m_xrm.get_string(var, "")}; + string str{xrm->get_string(var, "")}; return str.empty() ? fallback : convert(move(str)); } @@ -292,7 +293,6 @@ class config { static constexpr const char* KEY_INHERIT{"inherit"}; const logger& m_log; - 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 008fd279..c2d9409d 100644 --- a/include/x11/xresources.hpp +++ b/include/x11/xresources.hpp @@ -9,7 +9,7 @@ POLYBAR_NS class xresource_manager { public: - using make_type = const xresource_manager&; + using make_type = unique_ptr; static make_type make(); explicit xresource_manager(Display*); @@ -26,7 +26,6 @@ class xresource_manager { string load_value(const string& key, const string& res_type, size_t n) const; private: - Display* m_display{nullptr}; XrmDatabase m_db; char* m_manager{nullptr}; }; diff --git a/src/components/config.cpp b/src/components/config.cpp index ceb41ffb..27ba0d91 100644 --- a/src/components/config.cpp +++ b/src/components/config.cpp @@ -19,15 +19,15 @@ namespace chrono = std::chrono; * Create instance */ config::make_type config::make(string path, string bar) { - return static_cast(*factory_util::singleton>( - logger::make(), xresource_manager::make(), move(path), move(bar))); + return static_cast( + *factory_util::singleton>(logger::make(), move(path), move(bar))); } /** * Construct config object */ -config::config(const logger& logger, const xresource_manager& xrm, string&& path, string&& bar) - : m_log(logger), m_xrm(xrm), m_file(forward(path)), m_barname(forward(bar)) { +config::config(const logger& logger, string&& path, string&& bar) + : m_log(logger), m_file(forward(path)), m_barname(forward(bar)) { if (!file_util::exists(m_file)) { throw application_error("Could not find config file: " + m_file); } diff --git a/src/x11/xresources.cpp b/src/x11/xresources.cpp index c29e8339..28604915 100644 --- a/src/x11/xresources.cpp +++ b/src/x11/xresources.cpp @@ -12,17 +12,16 @@ POLYBAR_NS * Create instance */ xresource_manager::make_type xresource_manager::make() { - return static_cast( - *factory_util::singleton>(connection::make())); + return factory_util::unique(static_cast(connection::make())); } /** * Construct manager instance */ -xresource_manager::xresource_manager(Display* dsp) : m_display(forward(dsp)) { +xresource_manager::xresource_manager(Display* dsp) { XrmInitialize(); - if ((m_manager = XResourceManagerString(m_display)) != nullptr) { + if ((m_manager = XResourceManagerString(dsp)) != nullptr) { m_db = XrmGetStringDatabase(m_manager); } } @@ -31,9 +30,6 @@ xresource_manager::xresource_manager(Display* dsp) : m_display(forward