diff --git a/include/components/bar.hpp b/include/components/bar.hpp index d06d6d7d..6e36570a 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -25,6 +25,8 @@ class renderer; class bar : public xpp::event::sink { public: + static unique_ptr make(); + explicit bar(connection& conn, signal_emitter& emitter, const config& config, const logger& logger, unique_ptr screen, unique_ptr tray_manager); @@ -63,21 +65,4 @@ class bar : public xpp::event::sink make_bar() { - // clang-format off - return factory_util::unique( - make_connection(), - make_signal_emitter(), - make_confreader(), - make_logger(), - make_screen(), - make_tray_manager()); - // clang-format on - } -} - POLYBAR_NS_END diff --git a/include/components/command_line.hpp b/include/components/command_line.hpp index bf6221ca..05e519d9 100644 --- a/include/components/command_line.hpp +++ b/include/components/command_line.hpp @@ -36,6 +36,8 @@ namespace command_line { class parser { public: + static unique_ptr make(string scriptname, const options& opts); + explicit parser(const string& synopsis, const options& opts) : m_synopsis(synopsis), m_opts(opts) {} void usage() const; @@ -68,13 +70,4 @@ using cliparser = command_line::parser; using clioption = command_line::option; using clioptions = command_line::options; -namespace { - /** - * Configure injection module - */ - inline unique_ptr make_command_line(string scriptname, const clioptions& opts) { - return factory_util::unique("Usage: " + scriptname + " bar_name [OPTION...]", opts); - } -} - POLYBAR_NS_END diff --git a/include/components/config.hpp b/include/components/config.hpp index 286fda17..5a7fd9aa 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -26,7 +26,7 @@ class config { using valuemap_t = std::unordered_map; using sectionmap_t = std::unordered_map; - static constexpr const char* KEY_INHERIT{"inherit"}; + static const config& make(); explicit config(const logger& logger, const xresource_manager& xrm) : m_logger(logger), m_xrm(xrm) {} @@ -257,6 +257,8 @@ class config { } private: + static constexpr const char* KEY_INHERIT{"inherit"}; + const logger& m_logger; const xresource_manager& m_xrm; string m_file; @@ -264,14 +266,4 @@ class config { sectionmap_t m_sections; }; -namespace { - /** - * Configure injection module - */ - inline const config& make_confreader() { - shared_ptr instance = factory_util::singleton(make_logger(), make_xresource_manager()); - return static_cast(*instance); - } -} - POLYBAR_NS_END diff --git a/include/components/controller.hpp b/include/components/controller.hpp index e589cdfc..e59f7044 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -37,6 +37,8 @@ class controller : public signal_receiver { public: + static unique_ptr make(watch_t&& confwatch, bool enable_ipc = false, bool writeback = false); + explicit controller(connection& conn, signal_emitter& emitter, const logger& logger, const config& config, unique_ptr eventloop, unique_ptr bar, unique_ptr ipc, watch_t confwatch, bool writeback); ~controller(); @@ -82,27 +84,4 @@ class controller : public signal_receiver make_controller(watch_t&& confwatch, bool enableipc = false, bool writeback = false) { - unique_ptr ipc; - - if (enableipc) { - ipc = make_ipc(); - } - - // clang-format off - return factory_util::unique( - make_connection(), - make_signal_emitter(), - make_logger(), - make_confreader(), - make_eventloop(), - make_bar(), - move(ipc), - move(confwatch), - writeback); - // clang-format on - } -} - POLYBAR_NS_END diff --git a/include/components/eventloop.hpp b/include/components/eventloop.hpp index 9291a043..50a25850 100644 --- a/include/components/eventloop.hpp +++ b/include/components/eventloop.hpp @@ -2,20 +2,32 @@ #include #include +#include +#include +#include #include "common.hpp" -#include "components/logger.hpp" #include "events/signal_emitter.hpp" #include "events/signal_fwd.hpp" #include "events/signal_receiver.hpp" -#include "modules/meta/base.hpp" +#include "utils/concurrency.hpp" POLYBAR_NS +// fwd +namespace modules { + struct module_interface; +} +enum class alignment : uint8_t; +class config; +class logger; + using namespace signals::eventloop; using module_t = unique_ptr; -using modulemap_t = map>; +using modulemap_t = std::map>; + +using namespace std::chrono_literals; class eventloop : public signal_receiver { @@ -39,9 +51,11 @@ class eventloop : public signal_receiver using queue_t = moodycamel::BlockingConcurrentQueue; - using duration_t = chrono::duration; + using duration_t = std::chrono::duration; public: + static unique_ptr make(); + explicit eventloop(signal_emitter& emitter, const logger& logger, const config& config); ~eventloop(); @@ -55,23 +69,11 @@ class eventloop : public signal_receiver(event_type::QUIT), reload}; - } - static auto make_update_evt(bool force = false) { - return event{static_cast(event_type::UPDATE), force}; - } - static auto make_input_evt() { - return event{static_cast(event_type::INPUT)}; - } - static auto make_input_data(string&& data) { - input_data d{}; - memcpy(d.data, &data[0], sizeof(d.data)); - return d; - } - static auto make_check_evt() { - return event{static_cast(event_type::CHECK)}; - } + static event make_quit_evt(bool reload = false); + static event make_update_evt(bool force = false); + static event make_input_evt(); + static event make_check_evt(); + static input_data make_input_data(string&& data); protected: void process_inputqueue(); @@ -128,10 +130,4 @@ class eventloop : public signal_receiver make_eventloop() { - return make_unique(make_signal_emitter(), make_logger(), make_confreader()); - } -} - POLYBAR_NS_END diff --git a/include/components/ipc.hpp b/include/components/ipc.hpp index 074fc542..78ef8f9e 100644 --- a/include/components/ipc.hpp +++ b/include/components/ipc.hpp @@ -5,7 +5,6 @@ #include "events/signal_emitter.hpp" #include "utils/concurrency.hpp" #include "utils/functional.hpp" -#include "utils/factory.hpp" POLYBAR_NS @@ -34,6 +33,8 @@ struct ipc_action { */ class ipc { public: + static unique_ptr make(); + explicit ipc(signal_emitter& emitter, const logger& logger) : m_sig(emitter), m_log(logger) {} ~ipc(); @@ -50,13 +51,4 @@ class ipc { stateflag m_running{false}; }; -namespace { - /** - * Configure injection module - */ - inline unique_ptr make_ipc() { - return factory_util::unique(make_signal_emitter(), make_logger()); - } -} - POLYBAR_NS_END diff --git a/include/components/logger.hpp b/include/components/logger.hpp index 5b42eb94..6539dd16 100644 --- a/include/components/logger.hpp +++ b/include/components/logger.hpp @@ -5,7 +5,6 @@ #include #include "common.hpp" -#include "utils/factory.hpp" POLYBAR_NS @@ -21,6 +20,8 @@ loglevel parse_loglevel_name(const string& name); class logger { public: + static const logger& make(loglevel level = loglevel::NONE); + explicit logger(loglevel level); explicit logger(string level_name) : logger(parse_loglevel_name(level_name)) {} @@ -134,14 +135,4 @@ class logger { std::map m_suffixes; }; -/** - * Configure injection module - */ -namespace { - inline const logger& make_logger(loglevel level = loglevel::NONE) { - auto instance = factory_util::singleton(level); - return static_cast(*instance); - } -} - POLYBAR_NS_END diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp index 353a442f..65027761 100644 --- a/include/components/renderer.hpp +++ b/include/components/renderer.hpp @@ -1,22 +1,22 @@ #pragma once #include "common.hpp" -#include "components/logger.hpp" #include "components/types.hpp" #include "events/signal_emitter.hpp" #include "events/signal_fwd.hpp" #include "events/signal_receiver.hpp" -#include "x11/connection.hpp" #include "x11/fonts.hpp" #include "x11/types.hpp" POLYBAR_NS +// fwd class connection; class font_manager; class logger; using namespace signals::parser; +using std::map; class renderer : public signal_receiver make(const bar_settings& bar, vector&& fonts); + explicit renderer(connection& conn, signal_emitter& emitter, const logger& logger, unique_ptr font_manager, const bar_settings& bar, const vector& fonts); ~renderer(); @@ -122,21 +124,4 @@ class renderer xcb_font_t m_gcfont{XCB_NONE}; }; -namespace { - /** - * Configure injection module - */ - inline unique_ptr make_renderer(const bar_settings& bar, const vector& fonts) { - // clang-format off - return factory_util::unique( - make_connection(), - make_signal_emitter(), - make_logger(), - make_font_manager(), - bar, - fonts); - // clang-format on - } -} - POLYBAR_NS_END diff --git a/include/components/screen.hpp b/include/components/screen.hpp index f251fb9c..07014f86 100644 --- a/include/components/screen.hpp +++ b/include/components/screen.hpp @@ -18,6 +18,8 @@ class signal_emitter; class screen : public xpp::event::sink { public: + static unique_ptr make(); + explicit screen(connection& conn, signal_emitter& emitter, const logger& logger, const config& conf); ~screen(); @@ -48,14 +50,4 @@ class screen : public xpp::event::sink { bool m_sigraised{false}; }; -namespace { - /** - * Configure injection module - */ - inline unique_ptr make_screen() { - return factory_util::unique( - make_connection(), make_signal_emitter(), make_logger(), make_confreader()); - } -} - POLYBAR_NS_END diff --git a/include/drawtypes/progressbar.hpp b/include/drawtypes/progressbar.hpp index a3416e40..6fa4b45e 100644 --- a/include/drawtypes/progressbar.hpp +++ b/include/drawtypes/progressbar.hpp @@ -4,12 +4,17 @@ #include "components/builder.hpp" #include "components/config.hpp" #include "components/types.hpp" -#include "drawtypes/label.hpp" #include "utils/mixins.hpp" POLYBAR_NS namespace drawtypes { + // fwd + class label; + using label_t = shared_ptr