Remove config singleton (#2951)
* Remove unused function * Refactor deprecation warning * Modules take config as parameter instead of using the singleton * Bar take config as parameter instead of using the singleton * Renderer take config as parameter instead of using the singleton * Legacy Tray Manager take config as parameter instead of using the singleton * Screen take config as parameter instead of using the singleton * Controller take config as parameter instead of using the singleton * Remove the config singleton * Apply review suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> * Apply style suggestion Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com> --------- Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
This commit is contained in:
parent
61f0e9dd5d
commit
0caa30683c
@ -37,7 +37,7 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
|
||||
public signal_receiver<SIGN_PRIORITY_BAR, signals::ui::dim_window> {
|
||||
public:
|
||||
using make_type = unique_ptr<bar>;
|
||||
static make_type make(eventloop::loop&, bool only_initialize_values = false);
|
||||
static make_type make(eventloop::loop&, const config&, bool only_initialize_values = false);
|
||||
|
||||
explicit bar(connection&, signal_emitter&, const config&, const logger&, eventloop::loop&, unique_ptr<screen>&&,
|
||||
unique_ptr<tags::dispatch>&&, unique_ptr<tags::action_context>&&, bool only_initialize_values);
|
||||
|
@ -24,10 +24,7 @@ using file_list = vector<string>;
|
||||
|
||||
class config {
|
||||
public:
|
||||
using make_type = const config&;
|
||||
static make_type make(string path = "", string bar = "");
|
||||
|
||||
explicit config(const logger& logger, string&& path = "", string&& bar = "")
|
||||
explicit config(const logger& logger, string&& path, string&& bar)
|
||||
: m_log(logger), m_file(move(path)), m_barname(move(bar)){};
|
||||
|
||||
const string& filepath() const;
|
||||
@ -46,7 +43,7 @@ class config {
|
||||
|
||||
file_list get_included_files() const;
|
||||
|
||||
void warn_deprecated(const string& section, const string& key, string replacement) const;
|
||||
void warn_deprecated(const string& section, const string& key, string replacement = "") const;
|
||||
|
||||
/**
|
||||
* Returns true if a given parameter exists
|
||||
@ -212,8 +209,6 @@ class config {
|
||||
return default_value;
|
||||
}
|
||||
|
||||
void ignore_key(const string& section, const string& key) const;
|
||||
|
||||
/**
|
||||
* Attempt to load value using the deprecated key name. If successful show a
|
||||
* warning message. If it fails load the value using the new key and given
|
||||
@ -234,20 +229,6 @@ class config {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see deprecated<T>
|
||||
*/
|
||||
template <typename T = string>
|
||||
T deprecated_list(const string& section, const string& old, const string& newkey, const vector<T>& fallback) const {
|
||||
try {
|
||||
vector<T> value{get_list<T>(section, old)};
|
||||
warn_deprecated(section, old, newkey);
|
||||
return value;
|
||||
} catch (const key_error& err) {
|
||||
return get_list<T>(section, newkey, fallback);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void copy_inherited();
|
||||
|
||||
|
@ -105,7 +105,7 @@ class config_parser {
|
||||
* @throws syntax_error If there was any kind of syntax error
|
||||
* @throws parser_error If aynthing else went wrong
|
||||
*/
|
||||
config::make_type parse(string barname);
|
||||
config parse(string barname);
|
||||
|
||||
protected:
|
||||
/**
|
||||
@ -229,7 +229,7 @@ class config_parser {
|
||||
/**
|
||||
* @brief Absolute path to the main config file
|
||||
*/
|
||||
string m_config;
|
||||
string m_config_file;
|
||||
|
||||
/**
|
||||
* @brief List of all the lines in the config (with included files)
|
||||
|
@ -39,7 +39,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
|
||||
signals::ipc::hook, signals::ui::button_press, signals::ui::update_background> {
|
||||
public:
|
||||
using make_type = unique_ptr<controller>;
|
||||
static make_type make(bool has_ipc, eventloop::loop&);
|
||||
static make_type make(bool has_ipc, eventloop::loop&, const config&);
|
||||
|
||||
explicit controller(connection&, signal_emitter&, const logger&, const config&, bool has_ipc, eventloop::loop&);
|
||||
~controller();
|
||||
|
@ -46,7 +46,7 @@ class renderer : public renderer_interface,
|
||||
public signal_receiver<SIGN_PRIORITY_RENDERER, signals::ui::request_snapshot> {
|
||||
public:
|
||||
using make_type = unique_ptr<renderer>;
|
||||
static make_type make(const bar_settings& bar, tags::action_context& action_ctxt);
|
||||
static make_type make(const bar_settings& bar, tags::action_context& action_ctxt, const config&);
|
||||
|
||||
explicit renderer(connection& conn, signal_emitter& sig, const config&, const logger& logger, const bar_settings& bar,
|
||||
background_manager& background_manager, tags::action_context& action_ctxt);
|
||||
|
@ -19,7 +19,7 @@ class signal_emitter;
|
||||
class screen : public xpp::event::sink<evt::map_notify, evt::randr_screen_change_notify> {
|
||||
public:
|
||||
using make_type = unique_ptr<screen>;
|
||||
static make_type make();
|
||||
static make_type make(const config&);
|
||||
|
||||
explicit screen(connection& conn, signal_emitter& emitter, const logger& logger, const config& conf);
|
||||
~screen();
|
||||
|
@ -20,7 +20,7 @@ namespace modules {
|
||||
|
||||
class alsa_module : public event_module<alsa_module> {
|
||||
public:
|
||||
explicit alsa_module(const bar_settings&, string);
|
||||
explicit alsa_module(const bar_settings&, string, const config&);
|
||||
|
||||
void teardown();
|
||||
bool has_event();
|
||||
|
@ -20,7 +20,7 @@ namespace modules {
|
||||
string get_output();
|
||||
|
||||
public:
|
||||
explicit backlight_module(const bar_settings&, string);
|
||||
explicit backlight_module(const bar_settings&, string, const config&);
|
||||
|
||||
void idle();
|
||||
bool on_event(const inotify_event& event);
|
||||
|
@ -46,7 +46,7 @@ namespace modules {
|
||||
using consumption_reader = mutex_wrapper<value_reader<string /* watts */>>;
|
||||
|
||||
public:
|
||||
explicit battery_module(const bar_settings&, string);
|
||||
explicit battery_module(const bar_settings&, string, const config&);
|
||||
|
||||
void start() override;
|
||||
void teardown();
|
||||
|
@ -39,7 +39,7 @@ namespace modules {
|
||||
};
|
||||
|
||||
public:
|
||||
explicit bspwm_module(const bar_settings&, string);
|
||||
explicit bspwm_module(const bar_settings&, string, const config&);
|
||||
|
||||
void stop() override;
|
||||
bool has_event();
|
||||
|
@ -7,7 +7,7 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
class counter_module : public timer_module<counter_module> {
|
||||
public:
|
||||
explicit counter_module(const bar_settings&, string);
|
||||
explicit counter_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool update();
|
||||
bool build(builder* builder, const string& tag) const;
|
||||
|
@ -20,7 +20,7 @@ namespace modules {
|
||||
|
||||
class cpu_module : public timer_module<cpu_module> {
|
||||
public:
|
||||
explicit cpu_module(const bar_settings&, string);
|
||||
explicit cpu_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool update();
|
||||
string get_format() const;
|
||||
|
@ -12,7 +12,7 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
class date_module : public timer_module<date_module> {
|
||||
public:
|
||||
explicit date_module(const bar_settings&, string);
|
||||
explicit date_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool update();
|
||||
bool build(builder* builder, const string& tag) const;
|
||||
|
@ -35,7 +35,7 @@ namespace modules {
|
||||
*/
|
||||
class fs_module : public timer_module<fs_module> {
|
||||
public:
|
||||
explicit fs_module(const bar_settings&, string);
|
||||
explicit fs_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool update();
|
||||
string get_format() const;
|
||||
|
@ -14,7 +14,7 @@ namespace modules {
|
||||
*/
|
||||
class github_module : public timer_module<github_module> {
|
||||
public:
|
||||
explicit github_module(const bar_settings&, string);
|
||||
explicit github_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool update();
|
||||
bool build(builder* builder, const string& tag) const;
|
||||
|
@ -44,7 +44,7 @@ namespace modules {
|
||||
};
|
||||
|
||||
public:
|
||||
explicit i3_module(const bar_settings&, string);
|
||||
explicit i3_module(const bar_settings&, string, const config&);
|
||||
|
||||
void stop() override;
|
||||
bool has_event();
|
||||
|
@ -24,7 +24,7 @@ namespace modules {
|
||||
};
|
||||
|
||||
public:
|
||||
explicit ipc_module(const bar_settings&, string);
|
||||
explicit ipc_module(const bar_settings&, string, const config&);
|
||||
|
||||
void start() override;
|
||||
void update();
|
||||
|
@ -10,7 +10,7 @@ namespace modules {
|
||||
enum class memory_state { NORMAL = 0, WARN };
|
||||
class memory_module : public timer_module<memory_module> {
|
||||
public:
|
||||
explicit memory_module(const bar_settings&, string);
|
||||
explicit memory_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool update();
|
||||
string get_format() const;
|
||||
|
@ -17,7 +17,7 @@ namespace modules {
|
||||
};
|
||||
|
||||
public:
|
||||
explicit menu_module(const bar_settings&, string);
|
||||
explicit menu_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool build(builder* builder, const string& tag) const;
|
||||
void update() {}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
@ -142,7 +143,7 @@ namespace modules {
|
||||
template <class Impl>
|
||||
class module : public module_interface {
|
||||
public:
|
||||
module(const bar_settings& bar, string name);
|
||||
module(const bar_settings& bar, string name, const config&);
|
||||
~module() noexcept;
|
||||
|
||||
static constexpr auto EVENT_MODULE_TOGGLE = "module_toggle";
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "components/builder.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "events/signal.hpp"
|
||||
#include "events/signal_emitter.hpp"
|
||||
@ -16,11 +15,11 @@ namespace modules {
|
||||
// module<Impl> public {{{
|
||||
|
||||
template <typename Impl>
|
||||
module<Impl>::module(const bar_settings& bar, string name)
|
||||
module<Impl>::module(const bar_settings& bar, string name, const config& conf)
|
||||
: m_sig(signal_emitter::make())
|
||||
, m_bar(bar)
|
||||
, m_log(logger::make())
|
||||
, m_conf(config::make())
|
||||
, m_conf(conf)
|
||||
, m_router(make_unique<action_router>())
|
||||
, m_name("module/" + name)
|
||||
, m_name_raw(name)
|
||||
|
@ -17,8 +17,9 @@ namespace modules {
|
||||
* @param bar An instance of the @ref bar_settings
|
||||
* @param module_name The user-specified module name
|
||||
* @param log A @ref logger instance
|
||||
* @param config A @ref config instance
|
||||
*/
|
||||
module_t make_module(string&& type, const bar_settings& bar, string module_name, const logger& log);
|
||||
module_t make_module(string&& type, const bar_settings& bar, string module_name, const logger& log, const config& config);
|
||||
} // namespace modules
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -13,7 +13,7 @@ using namespace mpd;
|
||||
namespace modules {
|
||||
class mpd_module : public event_module<mpd_module> {
|
||||
public:
|
||||
explicit mpd_module(const bar_settings&, string);
|
||||
explicit mpd_module(const bar_settings&, string, const config&);
|
||||
|
||||
void teardown();
|
||||
inline bool connected() const;
|
||||
|
@ -11,7 +11,7 @@ namespace modules {
|
||||
|
||||
class network_module : public timer_module<network_module> {
|
||||
public:
|
||||
explicit network_module(const bar_settings&, string);
|
||||
explicit network_module(const bar_settings&, string, const config&);
|
||||
|
||||
void teardown();
|
||||
bool update();
|
||||
|
@ -13,7 +13,7 @@ namespace modules {
|
||||
|
||||
class pulseaudio_module : public event_module<pulseaudio_module> {
|
||||
public:
|
||||
explicit pulseaudio_module(const bar_settings&, string);
|
||||
explicit pulseaudio_module(const bar_settings&, string, const config&);
|
||||
|
||||
void teardown();
|
||||
bool has_event();
|
||||
|
@ -10,7 +10,7 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
class script_module : public module<script_module> {
|
||||
public:
|
||||
explicit script_module(const bar_settings&, string);
|
||||
explicit script_module(const bar_settings&, string, const config&);
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
@ -12,7 +12,7 @@ namespace modules {
|
||||
|
||||
class temperature_module : public timer_module<temperature_module> {
|
||||
public:
|
||||
explicit temperature_module(const bar_settings&, string);
|
||||
explicit temperature_module(const bar_settings&, string, const config&);
|
||||
|
||||
bool update();
|
||||
string get_format() const;
|
||||
|
@ -7,7 +7,7 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
class text_module : public static_module<text_module> {
|
||||
public:
|
||||
explicit text_module(const bar_settings&, string);
|
||||
explicit text_module(const bar_settings&, string, const config&);
|
||||
|
||||
void update() {}
|
||||
string get_format() const;
|
||||
|
@ -9,7 +9,7 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
class tray_module : public static_module<tray_module> {
|
||||
public:
|
||||
explicit tray_module(const bar_settings& bar_settings, string name_);
|
||||
explicit tray_module(const bar_settings& bar_settings, string name_, const config&);
|
||||
string get_format() const;
|
||||
|
||||
void start() override;
|
||||
|
@ -11,7 +11,7 @@ namespace modules {
|
||||
#define DEFINE_UNSUPPORTED_MODULE(MODULE_NAME, MODULE_TYPE) \
|
||||
class MODULE_NAME : public module_interface { \
|
||||
public: \
|
||||
MODULE_NAME(const bar_settings, string) { \
|
||||
MODULE_NAME(const bar_settings, string, const config&) { \
|
||||
throw application_error("No built-in support for '" + string{MODULE_TYPE} + "'"); \
|
||||
} \
|
||||
static constexpr auto TYPE = MODULE_TYPE; \
|
||||
|
@ -24,7 +24,7 @@ namespace modules {
|
||||
*/
|
||||
class xbacklight_module : public static_module<xbacklight_module>, public event_handler<evt::randr_notify> {
|
||||
public:
|
||||
explicit xbacklight_module(const bar_settings& bar, string name_);
|
||||
explicit xbacklight_module(const bar_settings& bar, string name_, const config&);
|
||||
|
||||
void update();
|
||||
string get_output();
|
||||
|
@ -21,7 +21,7 @@ namespace modules {
|
||||
: public static_module<xkeyboard_module>,
|
||||
public event_handler<evt::xkb_new_keyboard_notify, evt::xkb_state_notify, evt::xkb_indicator_state_notify> {
|
||||
public:
|
||||
explicit xkeyboard_module(const bar_settings& bar, string name_);
|
||||
explicit xkeyboard_module(const bar_settings& bar, string name_, const config&);
|
||||
|
||||
string get_output();
|
||||
void update();
|
||||
|
@ -33,7 +33,7 @@ namespace modules {
|
||||
class xwindow_module : public static_module<xwindow_module>, public event_handler<evt::property_notify> {
|
||||
public:
|
||||
enum class state { NONE, ACTIVE, EMPTY };
|
||||
explicit xwindow_module(const bar_settings&, string);
|
||||
explicit xwindow_module(const bar_settings&, string, const config&);
|
||||
|
||||
void update();
|
||||
bool build(builder* builder, const string& tag) const;
|
||||
|
@ -44,7 +44,7 @@ namespace modules {
|
||||
*/
|
||||
class xworkspaces_module : public static_module<xworkspaces_module>, public event_handler<evt::property_notify> {
|
||||
public:
|
||||
explicit xworkspaces_module(const bar_settings& bar, string name_);
|
||||
explicit xworkspaces_module(const bar_settings& bar, string name_, const config&);
|
||||
|
||||
void update();
|
||||
string get_output();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "cairo/context.hpp"
|
||||
#include "cairo/surface.hpp"
|
||||
#include "common.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "events/signal_fwd.hpp"
|
||||
@ -134,7 +135,7 @@ class tray_manager
|
||||
|
||||
const tray_settings settings() const;
|
||||
|
||||
void setup(const string& tray_module_name);
|
||||
void setup(const config&, const string& tray_module_name);
|
||||
void activate();
|
||||
void activate_delayed(chrono::duration<double, std::milli> delay = 1s);
|
||||
void deactivate(bool clear_selection = true);
|
||||
|
@ -38,17 +38,17 @@ using namespace eventloop;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
bar::make_type bar::make(loop& loop, bool only_initialize_values) {
|
||||
bar::make_type bar::make(loop& loop, const config& config, bool only_initialize_values) {
|
||||
auto action_ctxt = make_unique<tags::action_context>();
|
||||
|
||||
// clang-format off
|
||||
return std::make_unique<bar>(
|
||||
connection::make(),
|
||||
signal_emitter::make(),
|
||||
config::make(),
|
||||
config,
|
||||
logger::make(),
|
||||
loop,
|
||||
screen::make(),
|
||||
screen::make(config),
|
||||
tags::dispatch::make(*action_ctxt),
|
||||
std::move(action_ctxt),
|
||||
only_initialize_values);
|
||||
@ -889,7 +889,7 @@ void bar::handle(const evt::configure_notify& evt) {
|
||||
|
||||
void bar::start(const string& tray_module_name) {
|
||||
m_log.trace("bar: Create renderer");
|
||||
m_renderer = renderer::make(m_opts, *m_action_ctxt);
|
||||
m_renderer = renderer::make(m_opts, *m_action_ctxt, m_conf);
|
||||
|
||||
m_opts.x_data.window = m_renderer->window();
|
||||
m_opts.x_data.visual = m_renderer->visual();
|
||||
@ -918,7 +918,7 @@ void bar::start(const string& tray_module_name) {
|
||||
m_renderer->end();
|
||||
|
||||
m_log.trace("bar: Setup tray manager");
|
||||
m_tray->setup(tray_module_name);
|
||||
m_tray->setup(m_conf, tray_module_name);
|
||||
|
||||
if (m_tray->settings().tray_position == legacy_tray::tray_postition::MODULE ||
|
||||
m_tray->settings().tray_position == legacy_tray::tray_postition::NONE) {
|
||||
|
@ -16,13 +16,6 @@ POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
config::make_type config::make(string path, string bar) {
|
||||
return *factory_util::singleton<std::remove_reference_t<config::make_type>>(logger::make(), move(path), move(bar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path of loaded file
|
||||
*/
|
||||
@ -63,24 +56,20 @@ file_list config::get_included_files() const {
|
||||
return m_included;
|
||||
}
|
||||
|
||||
void config::ignore_key(const string& section, const string& key) const {
|
||||
if (has(section, key)) {
|
||||
m_log.warn(
|
||||
"The config parameter '%s.%s' is deprecated, it will be removed in the future. Please remove it from your "
|
||||
"config",
|
||||
section, key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a deprecation warning if the given parameter is set
|
||||
*/
|
||||
void config::warn_deprecated(const string& section, const string& key, string replacement) const {
|
||||
try {
|
||||
auto value = get<string>(section, key);
|
||||
m_log.warn(
|
||||
"The config parameter `%s.%s` is deprecated, use `%s.%s` instead.", section, key, section, move(replacement));
|
||||
} catch (const key_error& err) {
|
||||
if (has(section, key)) {
|
||||
if (replacement.empty()) {
|
||||
m_log.warn(
|
||||
"The config parameter '%s.%s' is deprecated, it will be removed in the future. Please remove it from your "
|
||||
"config",
|
||||
section, key);
|
||||
} else {
|
||||
m_log.warn(
|
||||
"The config parameter `%s.%s` is deprecated, use `%s.%s` instead.", section, key, section, move(replacement));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,12 @@
|
||||
POLYBAR_NS
|
||||
|
||||
config_parser::config_parser(const logger& logger, string&& file)
|
||||
: m_log(logger), m_config(file_util::expand(file)) {}
|
||||
: m_log(logger), m_config_file(file_util::expand(file)) {}
|
||||
|
||||
config::make_type config_parser::parse(string barname) {
|
||||
m_log.notice("Parsing config file: %s", m_config);
|
||||
config config_parser::parse(string barname) {
|
||||
m_log.notice("Parsing config file: %s", m_config_file);
|
||||
|
||||
parse_file(m_config, {});
|
||||
parse_file(m_config_file, {});
|
||||
|
||||
sectionmap_t sections = create_sectionmap();
|
||||
|
||||
@ -45,18 +45,15 @@ config::make_type config_parser::parse(string barname) {
|
||||
* second element onwards for the included list
|
||||
*/
|
||||
file_list included(m_files.begin() + 1, m_files.end());
|
||||
config::make_type result = config::make(m_config, barname);
|
||||
config conf(m_log, move(m_config_file), move(barname));
|
||||
|
||||
// Cast to non-const to set sections, included and xrm
|
||||
config& m_conf = const_cast<config&>(result);
|
||||
|
||||
m_conf.set_sections(move(sections));
|
||||
m_conf.set_included(move(included));
|
||||
conf.set_sections(move(sections));
|
||||
conf.set_included(move(included));
|
||||
if (use_xrm) {
|
||||
m_conf.use_xrm();
|
||||
conf.use_xrm();
|
||||
}
|
||||
|
||||
return result;
|
||||
return conf;
|
||||
}
|
||||
|
||||
sectionmap_t config_parser::create_sectionmap() {
|
||||
|
@ -31,9 +31,9 @@ using namespace modules;
|
||||
/**
|
||||
* Build controller instance
|
||||
*/
|
||||
controller::make_type controller::make(bool has_ipc, loop& loop) {
|
||||
controller::make_type controller::make(bool has_ipc, loop& loop, const config& config) {
|
||||
return std::make_unique<controller>(
|
||||
connection::make(), signal_emitter::make(), logger::make(), config::make(), has_ipc, loop);
|
||||
connection::make(), signal_emitter::make(), logger::make(), config, has_ipc, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,13 +46,13 @@ controller::controller(
|
||||
, m_log(logger)
|
||||
, m_conf(config)
|
||||
, m_loop(loop)
|
||||
, m_bar(bar::make(m_loop))
|
||||
, m_bar(bar::make(m_loop, config))
|
||||
, m_has_ipc(has_ipc) {
|
||||
m_conf.ignore_key("settings", "throttle-input-for");
|
||||
m_conf.ignore_key("settings", "throttle-output");
|
||||
m_conf.ignore_key("settings", "throttle-output-for");
|
||||
m_conf.ignore_key("settings", "eventqueue-swallow");
|
||||
m_conf.ignore_key("settings", "eventqueue-swallow-time");
|
||||
m_conf.warn_deprecated("settings", "throttle-input-for");
|
||||
m_conf.warn_deprecated("settings", "throttle-output");
|
||||
m_conf.warn_deprecated("settings", "throttle-output-for");
|
||||
m_conf.warn_deprecated("settings", "eventqueue-swallow");
|
||||
m_conf.warn_deprecated("settings", "eventqueue-swallow-time");
|
||||
|
||||
m_log.trace("controller: Setup user-defined modules");
|
||||
size_t created_modules{0};
|
||||
@ -630,7 +630,7 @@ size_t controller::setup_modules(alignment align) {
|
||||
}
|
||||
|
||||
m_log.notice("Loading module '%s' of type '%s'", module_name, type);
|
||||
module_t module = modules::make_module(move(type), m_bar->settings(), module_name, m_log);
|
||||
module_t module = modules::make_module(move(type), m_bar->settings(), module_name, m_log, m_conf);
|
||||
|
||||
m_modules.push_back(module);
|
||||
m_blocks[align].push_back(module);
|
||||
|
@ -21,12 +21,12 @@ static constexpr double BLOCK_GAP{20.0};
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
renderer::make_type renderer::make(const bar_settings& bar, tags::action_context& action_ctxt) {
|
||||
renderer::make_type renderer::make(const bar_settings& bar, tags::action_context& action_ctxt, const config& conf) {
|
||||
// clang-format off
|
||||
return std::make_unique<renderer>(
|
||||
connection::make(),
|
||||
signal_emitter::make(),
|
||||
config::make(),
|
||||
conf,
|
||||
logger::make(),
|
||||
forward<decltype(bar)>(bar),
|
||||
background_manager::make(),
|
||||
|
@ -22,8 +22,8 @@ using namespace signals::eventqueue;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
screen::make_type screen::make() {
|
||||
return std::make_unique<screen>(connection::make(), signal_emitter::make(), logger::make(), config::make());
|
||||
screen::make_type screen::make(const config& config) {
|
||||
return std::make_unique<screen>(connection::make(), signal_emitter::make(), logger::make(), config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,7 +128,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
config_parser parser{logger, move(confpath)};
|
||||
config::make_type conf = parser.parse(move(barname));
|
||||
config conf = parser.parse(move(barname));
|
||||
|
||||
//==================================================
|
||||
// Dump requested data
|
||||
@ -138,7 +138,7 @@ int main(int argc, char** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (cli->has("print-wmname")) {
|
||||
printf("%s\n", bar::make(loop, true)->settings().wmname.c_str());
|
||||
printf("%s\n", bar::make(loop, conf, true)->settings().wmname.c_str());
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
auto ctrl = controller::make((bool)ipc, loop);
|
||||
auto ctrl = controller::make((bool)ipc, loop, conf);
|
||||
|
||||
if (!ctrl->run(cli->has("stdout"), cli->get("png"), cli->has("reload"))) {
|
||||
reload = true;
|
||||
|
@ -17,7 +17,8 @@ using namespace alsa;
|
||||
namespace modules {
|
||||
template class module<alsa_module>;
|
||||
|
||||
alsa_module::alsa_module(const bar_settings& bar, string name_) : event_module<alsa_module>(bar, move(name_)) {
|
||||
alsa_module::alsa_module(const bar_settings& bar, string name_, const config& config)
|
||||
: event_module<alsa_module>(bar, move(name_), config) {
|
||||
if (m_handle_events) {
|
||||
m_router->register_action(EVENT_DEC, [this]() { action_dec(); });
|
||||
m_router->register_action(EVENT_INC, [this]() { action_inc(); });
|
||||
|
@ -23,8 +23,8 @@ namespace modules {
|
||||
return std::strtof(file_util::contents(m_path).c_str(), nullptr);
|
||||
}
|
||||
|
||||
backlight_module::backlight_module(const bar_settings& bar, string name_)
|
||||
: inotify_module<backlight_module>(bar, move(name_)) {
|
||||
backlight_module::backlight_module(const bar_settings& bar, string name_, const config& config)
|
||||
: inotify_module<backlight_module>(bar, move(name_), config) {
|
||||
m_router->register_action(EVENT_DEC, [this]() { action_dec(); });
|
||||
m_router->register_action(EVENT_INC, [this]() { action_inc(); });
|
||||
auto card = m_conf.get(name(), "card", ""s);
|
||||
|
@ -23,8 +23,8 @@ namespace modules {
|
||||
/**
|
||||
* Bootstrap module by setting up required components
|
||||
*/
|
||||
battery_module::battery_module(const bar_settings& bar, string name_)
|
||||
: inotify_module<battery_module>(bar, move(name_)) {
|
||||
battery_module::battery_module(const bar_settings& bar, string name_, const config& config)
|
||||
: inotify_module<battery_module>(bar, move(name_), config) {
|
||||
// Load configuration values
|
||||
m_fullat = std::min(m_conf.get(name(), "full-at", m_fullat), 100);
|
||||
m_lowat = std::max(m_conf.get(name(), "low-at", m_lowat), 0);
|
||||
|
@ -39,7 +39,8 @@ namespace {
|
||||
namespace modules {
|
||||
template class module<bspwm_module>;
|
||||
|
||||
bspwm_module::bspwm_module(const bar_settings& bar, string name_) : event_module<bspwm_module>(bar, move(name_)) {
|
||||
bspwm_module::bspwm_module(const bar_settings& bar, string name_, const config& config)
|
||||
: event_module<bspwm_module>(bar, move(name_), config) {
|
||||
m_router->register_action_with_data(EVENT_FOCUS, [this](const std::string& data) { action_focus(data); });
|
||||
m_router->register_action(EVENT_NEXT, [this]() { action_next(); });
|
||||
m_router->register_action(EVENT_PREV, [this]() { action_prev(); });
|
||||
|
@ -7,8 +7,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<counter_module>;
|
||||
|
||||
counter_module::counter_module(const bar_settings& bar, string name_)
|
||||
: timer_module<counter_module>(bar, move(name_)) {
|
||||
counter_module::counter_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<counter_module>(bar, move(name_), config) {
|
||||
set_interval(1s);
|
||||
m_formatter->add(DEFAULT_FORMAT, TAG_COUNTER, {TAG_COUNTER});
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<cpu_module>;
|
||||
|
||||
cpu_module::cpu_module(const bar_settings& bar, string name_) : timer_module<cpu_module>(bar, move(name_)) {
|
||||
cpu_module::cpu_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<cpu_module>(bar, move(name_), config) {
|
||||
set_interval(1s);
|
||||
m_totalwarn = m_conf.get(name(), "warn-percentage", m_totalwarn);
|
||||
m_ramp_padding = m_conf.get(name(), "ramp-coreload-spacing", m_ramp_padding);
|
||||
|
@ -8,7 +8,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<date_module>;
|
||||
|
||||
date_module::date_module(const bar_settings& bar, string name_) : timer_module<date_module>(bar, move(name_)) {
|
||||
date_module::date_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<date_module>(bar, move(name_), config) {
|
||||
if (!m_bar.locale.empty()) {
|
||||
datetime_stream.imbue(std::locale(m_bar.locale.c_str()));
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ namespace modules {
|
||||
* Bootstrap the module by reading config values and
|
||||
* setting up required components
|
||||
*/
|
||||
fs_module::fs_module(const bar_settings& bar, string name_) : timer_module<fs_module>(bar, move(name_)) {
|
||||
fs_module::fs_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<fs_module>(bar, move(name_), config) {
|
||||
m_mountpoints = m_conf.get_list(name(), "mount", {});
|
||||
if (m_mountpoints.empty()) {
|
||||
m_log.info("%s: No mountpoints specified, using fallback \"/\"", name());
|
||||
|
@ -14,7 +14,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
github_module::github_module(const bar_settings& bar, string name_) : timer_module<github_module>(bar, move(name_)) {
|
||||
github_module::github_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<github_module>(bar, move(name_), config) {
|
||||
m_accesstoken = m_conf.get(name(), "token");
|
||||
m_user = m_conf.get(name(), "user", ""s);
|
||||
m_api_url = m_conf.get(name(), "api-url", "https://api.github.com/"s);
|
||||
|
@ -12,7 +12,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<i3_module>;
|
||||
|
||||
i3_module::i3_module(const bar_settings& bar, string name_) : event_module<i3_module>(bar, move(name_)) {
|
||||
i3_module::i3_module(const bar_settings& bar, string name_, const config& conf)
|
||||
: event_module<i3_module>(bar, move(name_), conf) {
|
||||
m_router->register_action_with_data(EVENT_FOCUS, [this](const std::string& data) { action_focus(data); });
|
||||
m_router->register_action(EVENT_NEXT, [this]() { action_next(); });
|
||||
m_router->register_action(EVENT_PREV, [this]() { action_prev(); });
|
||||
|
@ -14,7 +14,8 @@ namespace modules {
|
||||
* Load user-defined ipc hooks and
|
||||
* create formatting tags
|
||||
*/
|
||||
ipc_module::ipc_module(const bar_settings& bar, string name_) : module<ipc_module>(bar, move(name_)) {
|
||||
ipc_module::ipc_module(const bar_settings& bar, string name_, const config& config)
|
||||
: module<ipc_module>(bar, move(name_), config) {
|
||||
m_router->register_action_with_data(EVENT_SEND, [this](const std::string& data) { action_send(data); });
|
||||
m_router->register_action_with_data(EVENT_HOOK, [this](const std::string& data) { action_hook(data); });
|
||||
m_router->register_action(EVENT_NEXT, [this]() { action_next(); });
|
||||
|
@ -15,7 +15,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<memory_module>;
|
||||
|
||||
memory_module::memory_module(const bar_settings& bar, string name_) : timer_module<memory_module>(bar, move(name_)) {
|
||||
memory_module::memory_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<memory_module>(bar, move(name_), config) {
|
||||
set_interval(1s);
|
||||
m_perc_memused_warn = m_conf.get(name(), "warn-percentage", 90);
|
||||
|
||||
|
@ -11,7 +11,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<menu_module>;
|
||||
|
||||
menu_module::menu_module(const bar_settings& bar, string name_) : static_module<menu_module>(bar, move(name_)) {
|
||||
menu_module::menu_module(const bar_settings& bar, string name_, const config& config)
|
||||
: static_module<menu_module>(bar, move(name_), config) {
|
||||
m_expand_right = m_conf.get(name(), "expand-right", m_expand_right);
|
||||
|
||||
m_router->register_action_with_data(EVENT_OPEN, [this](const std::string& data) { action_open(data); });
|
||||
|
@ -9,7 +9,7 @@ namespace modules {
|
||||
/**
|
||||
* Function pointer for creating a module.
|
||||
*/
|
||||
using factory_fun = module_t (*)(const bar_settings&, string&&);
|
||||
using factory_fun = module_t (*)(const bar_settings&, string&&, const config&);
|
||||
using factory_map = map<string, factory_fun>;
|
||||
|
||||
/**
|
||||
@ -19,8 +19,8 @@ namespace modules {
|
||||
*/
|
||||
template <typename M>
|
||||
static constexpr factory_fun get_factory() {
|
||||
return [](const bar_settings& bar, string&& module_name) -> module_t {
|
||||
return make_shared<M>(bar, move(module_name));
|
||||
return [](const bar_settings& bar, string&& module_name, const config& config) -> module_t {
|
||||
return make_shared<M>(bar, move(module_name), config);
|
||||
};
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ namespace modules {
|
||||
map_entry<ipc_module>(),
|
||||
};
|
||||
|
||||
module_t make_module(string&& type, const bar_settings& bar, string module_name, const logger& log) {
|
||||
module_t make_module(string&& type, const bar_settings& bar, string module_name, const logger& log, const config& config) {
|
||||
string actual_type = type;
|
||||
|
||||
if (type == "internal/volume") {
|
||||
@ -76,7 +76,7 @@ namespace modules {
|
||||
|
||||
auto it = factories.find(actual_type);
|
||||
if (it != factories.end()) {
|
||||
return it->second(bar, std::move(module_name));
|
||||
return it->second(bar, std::move(module_name), config);
|
||||
} else {
|
||||
throw application_error("Unknown module: " + type);
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<mpd_module>;
|
||||
|
||||
mpd_module::mpd_module(const bar_settings& bar, string name_) : event_module<mpd_module>(bar, move(name_)) {
|
||||
mpd_module::mpd_module(const bar_settings& bar, string name_, const config& config)
|
||||
: event_module<mpd_module>(bar, move(name_), config) {
|
||||
m_router->register_action(EVENT_PLAY, [this]() { action_play(); });
|
||||
m_router->register_action(EVENT_PAUSE, [this]() { action_pause(); });
|
||||
m_router->register_action(EVENT_STOP, [this]() { action_stop(); });
|
||||
|
@ -10,8 +10,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<network_module>;
|
||||
|
||||
network_module::network_module(const bar_settings& bar, string name_)
|
||||
: timer_module<network_module>(bar, move(name_)) {
|
||||
network_module::network_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<network_module>(bar, move(name_), config) {
|
||||
// Load configuration values
|
||||
m_interface = m_conf.get(name(), "interface", m_interface);
|
||||
|
||||
|
@ -13,8 +13,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<pulseaudio_module>;
|
||||
|
||||
pulseaudio_module::pulseaudio_module(const bar_settings& bar, string name_)
|
||||
: event_module<pulseaudio_module>(bar, move(name_)) {
|
||||
pulseaudio_module::pulseaudio_module(const bar_settings& bar, string name_, const config& config)
|
||||
: event_module<pulseaudio_module>(bar, move(name_), config) {
|
||||
if (m_handle_events) {
|
||||
m_router->register_action(EVENT_DEC, [this]() { action_dec(); });
|
||||
m_router->register_action(EVENT_INC, [this]() { action_inc(); });
|
||||
|
@ -6,8 +6,8 @@
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
script_module::script_module(const bar_settings& bar, string name_)
|
||||
: module<script_module>(bar, move(name_))
|
||||
script_module::script_module(const bar_settings& bar, string name_, const config& config)
|
||||
: module<script_module>(bar, move(name_), config)
|
||||
, m_tail(m_conf.get(name(), "tail", false))
|
||||
, m_interval_success(m_conf.get<script_runner::interval>(name(), "interval", m_tail ? 0s : 5s))
|
||||
, m_interval_fail(m_conf.get<script_runner::interval>(name(), "interval-fail", m_interval_success))
|
||||
|
@ -13,8 +13,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<temperature_module>;
|
||||
|
||||
temperature_module::temperature_module(const bar_settings& bar, string name_)
|
||||
: timer_module<temperature_module>(bar, move(name_)) {
|
||||
temperature_module::temperature_module(const bar_settings& bar, string name_, const config& config)
|
||||
: timer_module<temperature_module>(bar, move(name_), config) {
|
||||
m_zone = m_conf.get(name(), "thermal-zone", 0);
|
||||
m_zone_type = m_conf.get(name(), "zone-type", ""s);
|
||||
m_path = m_conf.get(name(), "hwmon-path", ""s);
|
||||
|
@ -8,7 +8,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<text_module>;
|
||||
|
||||
text_module::text_module(const bar_settings& bar, string name_) : static_module<text_module>(bar, move(name_)) {
|
||||
text_module::text_module(const bar_settings& bar, string name_, const config& config)
|
||||
: static_module<text_module>(bar, move(name_), config) {
|
||||
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL});
|
||||
m_formatter->add_optional("content", {});
|
||||
|
||||
|
@ -7,8 +7,8 @@ POLYBAR_NS
|
||||
namespace modules {
|
||||
template class module<tray_module>;
|
||||
|
||||
tray_module::tray_module(const bar_settings& bar_settings, string name_)
|
||||
: static_module<tray_module>(bar_settings, move(name_))
|
||||
tray_module::tray_module(const bar_settings& bar_settings, string name_, const config& config)
|
||||
: static_module<tray_module>(bar_settings, move(name_), config)
|
||||
, m_tray(connection::make(), signal_emitter::make(), m_log, bar_settings, [&] { this->broadcast(); }) {
|
||||
m_formatter->add(DEFAULT_FORMAT, TAG_TRAY, {TAG_TRAY});
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
xbacklight_module::xbacklight_module(const bar_settings& bar, string name_)
|
||||
: static_module<xbacklight_module>(bar, move(name_)), m_connection(connection::make()) {
|
||||
xbacklight_module::xbacklight_module(const bar_settings& bar, string name_, const config& config)
|
||||
: static_module<xbacklight_module>(bar, move(name_), config), m_connection(connection::make()) {
|
||||
m_router->register_action(EVENT_INC, [this]() { action_inc(); });
|
||||
m_router->register_action(EVENT_DEC, [this]() { action_dec(); });
|
||||
|
||||
|
@ -22,8 +22,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
xkeyboard_module::xkeyboard_module(const bar_settings& bar, string name_)
|
||||
: static_module<xkeyboard_module>(bar, move(name_)), m_connection(connection::make()) {
|
||||
xkeyboard_module::xkeyboard_module(const bar_settings& bar, string name_, const config& config)
|
||||
: static_module<xkeyboard_module>(bar, move(name_), config), m_connection(connection::make()) {
|
||||
m_router->register_action(EVENT_SWITCH, [this]() { action_switch(); });
|
||||
|
||||
// Setup extension
|
||||
|
@ -69,8 +69,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
xwindow_module::xwindow_module(const bar_settings& bar, string name_)
|
||||
: static_module<xwindow_module>(bar, move(name_)), m_connection(connection::make()) {
|
||||
xwindow_module::xwindow_module(const bar_settings& bar, string name_, const config& config)
|
||||
: static_module<xwindow_module>(bar, move(name_), config), m_connection(connection::make()) {
|
||||
// Initialize ewmh atoms
|
||||
ewmh_util::initialize();
|
||||
|
||||
|
@ -27,8 +27,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
xworkspaces_module::xworkspaces_module(const bar_settings& bar, string name_)
|
||||
: static_module<xworkspaces_module>(bar, move(name_))
|
||||
xworkspaces_module::xworkspaces_module(const bar_settings& bar, string name_, const config& config)
|
||||
: static_module<xworkspaces_module>(bar, move(name_), config)
|
||||
, m_connection(connection::make())
|
||||
, m_ewmh(ewmh_util::initialize()) {
|
||||
m_router->register_action_with_data(EVENT_FOCUS, [this](const std::string& data) { action_focus(data); });
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "cairo/context.hpp"
|
||||
#include "cairo/surface.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "events/signal.hpp"
|
||||
#include "utils/color.hpp"
|
||||
@ -55,8 +54,7 @@ tray_manager::~tray_manager() {
|
||||
deactivate();
|
||||
}
|
||||
|
||||
void tray_manager::setup(const string& tray_module_name) {
|
||||
const config& conf = config::make();
|
||||
void tray_manager::setup(const config& conf, const string& tray_module_name) {
|
||||
auto bs = conf.section();
|
||||
string position = conf.get(bs, "tray-position", "none"s);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user