refactor: Object construction
This commit is contained in:
parent
1a2a6e5fab
commit
4fca0c89b4
@ -25,7 +25,8 @@ class renderer;
|
||||
|
||||
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify> {
|
||||
public:
|
||||
static unique_ptr<bar> make();
|
||||
using make_type = unique_ptr<bar>;
|
||||
static make_type make();
|
||||
|
||||
explicit bar(connection& conn, signal_emitter& emitter, const config& config, const logger& logger,
|
||||
unique_ptr<screen> screen, unique_ptr<tray_manager> tray_manager);
|
||||
|
@ -36,7 +36,8 @@ namespace command_line {
|
||||
|
||||
class parser {
|
||||
public:
|
||||
static unique_ptr<parser> make(string scriptname, const options& opts);
|
||||
using make_type = unique_ptr<parser>;
|
||||
static make_type make(string scriptname, const options& opts);
|
||||
|
||||
explicit parser(const string& synopsis, const options& opts) : m_synopsis(synopsis), m_opts(opts) {}
|
||||
|
||||
|
@ -26,7 +26,8 @@ class config {
|
||||
using valuemap_t = std::unordered_map<string, string>;
|
||||
using sectionmap_t = std::unordered_map<string, valuemap_t>;
|
||||
|
||||
static const config& make();
|
||||
using make_type = const config&;
|
||||
static make_type make();
|
||||
|
||||
explicit config(const logger& logger, const xresource_manager& xrm) : m_logger(logger), m_xrm(xrm) {}
|
||||
|
||||
|
@ -4,18 +4,12 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/bar.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/eventloop.hpp"
|
||||
#include "components/ipc.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "config.hpp"
|
||||
#include "events/signal_emitter.hpp"
|
||||
#include "events/signal_fwd.hpp"
|
||||
#include "events/signal_receiver.hpp"
|
||||
#include "utils/command.hpp"
|
||||
#include "utils/inotify.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/types.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
@ -23,7 +17,20 @@ POLYBAR_NS
|
||||
// fwd decl {{{
|
||||
|
||||
class bar;
|
||||
class config;
|
||||
class connection;
|
||||
class eventloop;
|
||||
class logger;
|
||||
struct bar_settings;
|
||||
namespace inotify_util {
|
||||
class inotify_watch;
|
||||
using watch_t = unique_ptr<inotify_watch>;
|
||||
}
|
||||
namespace command_util {
|
||||
class command;
|
||||
}
|
||||
using command = command_util::command;
|
||||
using command_t = unique_ptr<command>;
|
||||
|
||||
// }}}
|
||||
|
||||
@ -37,7 +44,8 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::proc
|
||||
sig_ev::process_quit, sig_ui::button_press, sig_ipc::process_action, sig_ipc::process_command,
|
||||
sig_ipc::process_hook> {
|
||||
public:
|
||||
static unique_ptr<controller> make(watch_t&& confwatch, bool enable_ipc = false, bool writeback = false);
|
||||
using make_type = unique_ptr<controller>;
|
||||
static make_type make(string&& path_confwatch, bool enable_ipc = false, bool writeback = false);
|
||||
|
||||
explicit controller(connection& conn, signal_emitter& emitter, const logger& logger, const config& config,
|
||||
unique_ptr<eventloop> eventloop, unique_ptr<bar> bar, unique_ptr<ipc> ipc, watch_t confwatch, bool writeback);
|
||||
|
@ -54,7 +54,8 @@ class eventloop : public signal_receiver<SIGN_PRIORITY_EVENTLOOP, process_quit,
|
||||
using duration_t = std::chrono::duration<double, std::milli>;
|
||||
|
||||
public:
|
||||
static unique_ptr<eventloop> make();
|
||||
using make_type = unique_ptr<eventloop>;
|
||||
static make_type make();
|
||||
|
||||
explicit eventloop(signal_emitter& emitter, const logger& logger, const config& config);
|
||||
~eventloop();
|
||||
|
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
enum class event_type;
|
||||
struct event;
|
||||
struct quit_event;
|
||||
struct update_event;
|
||||
struct input_event;
|
||||
|
||||
class eventloop {
|
||||
public:
|
||||
using entry_t = event;
|
||||
};
|
||||
|
||||
POLYBAR_NS_END
|
@ -33,7 +33,8 @@ struct ipc_action {
|
||||
*/
|
||||
class ipc {
|
||||
public:
|
||||
static unique_ptr<ipc> make();
|
||||
using make_type = unique_ptr<ipc>;
|
||||
static make_type make();
|
||||
|
||||
explicit ipc(signal_emitter& emitter, const logger& logger) : m_sig(emitter), m_log(logger) {}
|
||||
~ipc();
|
||||
|
@ -20,7 +20,8 @@ loglevel parse_loglevel_name(const string& name);
|
||||
|
||||
class logger {
|
||||
public:
|
||||
static const logger& make(loglevel level = loglevel::NONE);
|
||||
using make_type = const logger&;
|
||||
static make_type make(loglevel level = loglevel::NONE);
|
||||
|
||||
explicit logger(loglevel level);
|
||||
explicit logger(string level_name) : logger(parse_loglevel_name(level_name)) {}
|
||||
|
@ -25,7 +25,8 @@ class renderer
|
||||
public:
|
||||
enum class gc : uint8_t { BG, FG, OL, UL, BT, BB, BL, BR };
|
||||
|
||||
static unique_ptr<renderer> make(const bar_settings& bar, vector<string>&& fonts);
|
||||
using make_type = unique_ptr<renderer>;
|
||||
static make_type make(const bar_settings& bar, vector<string>&& fonts);
|
||||
|
||||
explicit renderer(connection& conn, signal_emitter& emitter, const logger& logger,
|
||||
unique_ptr<font_manager> font_manager, const bar_settings& bar, const vector<string>& fonts);
|
||||
|
@ -18,7 +18,8 @@ class signal_emitter;
|
||||
|
||||
class screen : public xpp::event::sink<evt::randr_screen_change_notify> {
|
||||
public:
|
||||
static unique_ptr<screen> make();
|
||||
using make_type = unique_ptr<screen>;
|
||||
static make_type make();
|
||||
|
||||
explicit screen(connection& conn, signal_emitter& emitter, const logger& logger, const config& conf);
|
||||
~screen();
|
||||
|
@ -18,7 +18,8 @@ extern signal_receivers_t g_signal_receivers;
|
||||
*/
|
||||
class signal_emitter {
|
||||
public:
|
||||
static signal_emitter& make();
|
||||
using make_type = signal_emitter&;
|
||||
static make_type make();
|
||||
|
||||
explicit signal_emitter() = default;
|
||||
virtual ~signal_emitter() {}
|
||||
|
@ -123,7 +123,7 @@ namespace modules {
|
||||
template <class Impl>
|
||||
class module : public module_interface {
|
||||
public:
|
||||
module(const bar_settings bar, const logger& logger, const config& config, string name);
|
||||
module(const bar_settings bar, string name);
|
||||
~module() noexcept;
|
||||
|
||||
void set_update_cb(callback<>&& cb);
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "components/builder.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/config.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -6,10 +8,10 @@ namespace modules {
|
||||
// module<Impl> public {{{
|
||||
|
||||
template <typename Impl>
|
||||
module<Impl>::module(const bar_settings bar, const logger& logger, const config& config, string name)
|
||||
module<Impl>::module(const bar_settings bar, string name)
|
||||
: m_bar(bar)
|
||||
, m_log(logger)
|
||||
, m_conf(config)
|
||||
, m_log(logger::make())
|
||||
, m_conf(config::make())
|
||||
, m_name("module/" + name)
|
||||
, m_builder(make_unique<builder>(bar))
|
||||
, m_formatter(make_unique<module_formatter>(m_conf, m_name)) {}
|
||||
|
@ -25,7 +25,7 @@ namespace modules {
|
||||
*/
|
||||
class xbacklight_module : public static_module<xbacklight_module>, public xpp::event::sink<evt::randr_notify> {
|
||||
public:
|
||||
explicit xbacklight_module(const bar_settings& bar, const logger& logger, const config& config, string name);
|
||||
explicit xbacklight_module(const bar_settings& bar, string name);
|
||||
|
||||
void setup();
|
||||
void teardown();
|
||||
|
@ -19,7 +19,7 @@ namespace modules {
|
||||
class xkeyboard_module : public static_module<xkeyboard_module>,
|
||||
public xpp::event::sink<evt::xkb_new_keyboard_notify, evt::xkb_state_notify, evt::xkb_indicator_state_notify> {
|
||||
public:
|
||||
explicit xkeyboard_module(const bar_settings& bar, const logger& logger, const config& config, string name);
|
||||
explicit xkeyboard_module(const bar_settings& bar, string name);
|
||||
|
||||
void setup();
|
||||
void teardown();
|
||||
|
@ -32,7 +32,7 @@ namespace modules {
|
||||
*/
|
||||
class xwindow_module : public static_module<xwindow_module>, public xpp::event::sink<evt::property_notify> {
|
||||
public:
|
||||
explicit xwindow_module(const bar_settings&, const logger&, const config&, string);
|
||||
explicit xwindow_module(const bar_settings&, string);
|
||||
|
||||
void setup();
|
||||
void teardown();
|
||||
|
@ -49,7 +49,7 @@ namespace modules {
|
||||
*/
|
||||
class xworkspaces_module : public static_module<xworkspaces_module>, public xpp::event::sink<evt::property_notify> {
|
||||
public:
|
||||
explicit xworkspaces_module(const bar_settings& bar, const logger& logger, const config& config, string name);
|
||||
explicit xworkspaces_module(const bar_settings& bar, string name);
|
||||
|
||||
void setup();
|
||||
void teardown();
|
||||
|
@ -20,7 +20,8 @@ using xpp_connection = xpp::connection<XPP_EXTENSION_LIST>;
|
||||
|
||||
class connection : public xpp_connection {
|
||||
public:
|
||||
static connection& make();
|
||||
using make_type = connection&;
|
||||
static make_type make();
|
||||
|
||||
explicit connection(xcb_connection_t* conn) : connection(conn, 0) {}
|
||||
explicit connection(xcb_connection_t* conn, int connection_fd)
|
||||
|
@ -39,7 +39,8 @@ using font_t = unique_ptr<fonttype, fonttype_deleter>;
|
||||
|
||||
class font_manager {
|
||||
public:
|
||||
static unique_ptr<font_manager> make();
|
||||
using make_type = unique_ptr<font_manager>;
|
||||
static make_type make();
|
||||
|
||||
explicit font_manager(connection& conn, const logger& logger);
|
||||
~font_manager();
|
||||
|
@ -65,7 +65,8 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
||||
evt::reparent_notify, evt::destroy_notify, evt::map_notify, evt::unmap_notify>,
|
||||
public signal_receiver<SIGN_PRIORITY_TRAY, visibility_change> {
|
||||
public:
|
||||
static unique_ptr<tray_manager> make();
|
||||
using make_type = unique_ptr<tray_manager>;
|
||||
static make_type make();
|
||||
|
||||
explicit tray_manager(connection& conn, signal_emitter& emitter, const logger& logger);
|
||||
|
||||
|
@ -35,7 +35,7 @@ using namespace wm_util;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<bar> bar::make() {
|
||||
bar::make_type bar::make() {
|
||||
// clang-format off
|
||||
return factory_util::unique<bar>(
|
||||
connection::make(),
|
||||
|
@ -10,7 +10,7 @@ POLYBAR_NS
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<cliparser> cliparser::make(string scriptname, const clioptions& opts) {
|
||||
cliparser::make_type cliparser::make(string scriptname, const clioptions& opts) {
|
||||
return factory_util::unique<cliparser>("Usage: " + scriptname + " bar_name [OPTION...]", opts);
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,9 @@ POLYBAR_NS
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
const config& config::make() {
|
||||
shared_ptr<config> instance = factory_util::singleton<config>(logger::make(), xresource_manager::make());
|
||||
return static_cast<config&>(*instance);
|
||||
config::make_type config::make() {
|
||||
auto instance = factory_util::singleton<const config>(logger::make(), xresource_manager::make());
|
||||
return static_cast<const config&>(*instance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,9 +7,12 @@
|
||||
#include "components/logger.hpp"
|
||||
#include "events/signal.hpp"
|
||||
#include "modules/meta/factory.hpp"
|
||||
#include "utils/command.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/inotify.hpp"
|
||||
#include "utils/process.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/xutils.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
@ -19,13 +22,7 @@ using namespace modules;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<controller> controller::make(watch_t&& confwatch, bool enable_ipc, bool writeback) {
|
||||
unique_ptr<ipc> ipc;
|
||||
|
||||
if (enable_ipc) {
|
||||
ipc = ipc::make();
|
||||
}
|
||||
|
||||
controller::make_type controller::make(string&& path_confwatch, bool enable_ipc, bool writeback) {
|
||||
// clang-format off
|
||||
return factory_util::unique<controller>(
|
||||
connection::make(),
|
||||
@ -34,8 +31,8 @@ unique_ptr<controller> controller::make(watch_t&& confwatch, bool enable_ipc, bo
|
||||
config::make(),
|
||||
eventloop::make(),
|
||||
bar::make(),
|
||||
move(ipc),
|
||||
move(confwatch),
|
||||
enable_ipc ? ipc::make() : ipc::make_type{},
|
||||
!path_confwatch.empty() ? inotify_util::make_watch(path_confwatch) : watch_t{},
|
||||
writeback);
|
||||
// clang-format on
|
||||
}
|
||||
@ -124,7 +121,7 @@ void controller::setup() {
|
||||
throw application_error("Inter-process messaging needs to be enabled");
|
||||
}
|
||||
|
||||
unique_ptr<module_interface> module{make_module(move(type), m_bar->settings(), m_log, m_conf, module_name)};
|
||||
unique_ptr<module_interface> module{make_module(move(type), m_bar->settings(), module_name)};
|
||||
|
||||
module->set_update_cb([&] {
|
||||
if (m_eventloop && m_running) {
|
||||
@ -340,7 +337,7 @@ bool controller::on(const sig_ev::process_update& evt) {
|
||||
|
||||
try {
|
||||
if (!m_writeback) {
|
||||
m_bar->parse(contents, evt());
|
||||
m_bar->parse(move(contents), evt());
|
||||
} else {
|
||||
std::cout << contents << std::endl;
|
||||
}
|
||||
@ -362,7 +359,7 @@ bool controller::on(const sig_ev::process_input& evt) {
|
||||
|
||||
m_log.info("Executing shell command: %s", input);
|
||||
|
||||
m_command = command_util::make_command(input);
|
||||
m_command = command_util::make_command(move(input));
|
||||
m_command->exec();
|
||||
m_command.reset();
|
||||
} catch (const application_error& err) {
|
||||
@ -404,6 +401,7 @@ bool controller::on(const sig_ipc::process_action& evt) {
|
||||
m_log.err("Cannot enqueue empty ipc action");
|
||||
} else {
|
||||
m_log.info("Enqueuing ipc action: %s", action);
|
||||
m_eventloop->enqueue(eventloop::make_input_data(move(action)));
|
||||
m_eventloop->enqueue(eventloop::make_input_evt());
|
||||
}
|
||||
return true;
|
||||
|
@ -17,7 +17,7 @@ POLYBAR_NS
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<eventloop> eventloop::make() {
|
||||
eventloop::make_type eventloop::make() {
|
||||
return factory_util::unique<eventloop>(signal_emitter::make(), logger::make(), config::make());
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ using namespace signals::ipc;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<ipc> ipc::make() {
|
||||
ipc::make_type ipc::make() {
|
||||
return factory_util::unique<ipc>(signal_emitter::make(), logger::make());
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ POLYBAR_NS
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
const logger& logger::make(loglevel level) {
|
||||
logger::make_type logger::make(loglevel level) {
|
||||
auto instance = factory_util::singleton<const logger>(level);
|
||||
return static_cast<const logger&>(*instance);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ POLYBAR_NS
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<renderer> renderer::make(const bar_settings& bar, vector<string>&& fonts) {
|
||||
renderer::make_type renderer::make(const bar_settings& bar, vector<string>&& fonts) {
|
||||
// clang-format off
|
||||
return factory_util::unique<renderer>(
|
||||
connection::make(),
|
||||
|
@ -19,7 +19,7 @@ using namespace signals::eventloop;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<screen> screen::make() {
|
||||
screen::make_type screen::make() {
|
||||
return factory_util::unique<screen>(
|
||||
connection::make(), signal_emitter::make(), logger::make(), config::make());
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "events/signal_emitter.hpp"
|
||||
#include "events/signal_receiver.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -8,7 +7,7 @@ signal_receivers_t g_signal_receivers;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
signal_emitter& signal_emitter::make() {
|
||||
signal_emitter::make_type signal_emitter::make() {
|
||||
auto instance = factory_util::singleton<signal_emitter>();
|
||||
return static_cast<signal_emitter&>(*instance);
|
||||
}
|
||||
|
@ -117,17 +117,17 @@ int main(int argc, char** argv) {
|
||||
// Create controller and run application
|
||||
//==================================================
|
||||
unique_ptr<controller> ctrl;
|
||||
string path_confwatch;
|
||||
bool enable_ipc{false};
|
||||
watch_t confwatch;
|
||||
|
||||
if (!cli->has("print-wmname")) {
|
||||
enable_ipc = conf.get<bool>(conf.bar_section(), "enable-ipc", false);
|
||||
}
|
||||
if (!cli->has("print-wmname") && cli->has("reload")) {
|
||||
inotify_util::make_watch(conf.filepath());
|
||||
path_confwatch = conf.filepath();
|
||||
}
|
||||
|
||||
ctrl = controller::make(move(confwatch), enable_ipc, cli->has("stdout"));
|
||||
ctrl = controller::make(move(path_confwatch), enable_ipc, cli->has("stdout"));
|
||||
|
||||
if (cli->has("print-wmname")) {
|
||||
cout << ctrl->opts().wmname << endl;
|
||||
|
@ -19,8 +19,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
xbacklight_module::xbacklight_module(const bar_settings& bar, const logger& logger, const config& config, string name)
|
||||
: static_module<xbacklight_module>(bar, logger, config, name)
|
||||
xbacklight_module::xbacklight_module(const bar_settings& bar, string name)
|
||||
: static_module<xbacklight_module>(bar, move(name))
|
||||
, m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
|
@ -17,8 +17,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
xkeyboard_module::xkeyboard_module(const bar_settings& bar, const logger& logger, const config& config, string name)
|
||||
: static_module<xkeyboard_module>(bar, logger, config, name), m_connection(connection::make()) {}
|
||||
xkeyboard_module::xkeyboard_module(const bar_settings& bar, string name)
|
||||
: static_module<xkeyboard_module>(bar, move(name)), m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
* Bootstrap the module
|
||||
|
@ -64,8 +64,8 @@ namespace modules {
|
||||
/**
|
||||
* Construct module
|
||||
*/
|
||||
xwindow_module::xwindow_module(const bar_settings& bar, const logger& logger, const config& config, string name)
|
||||
: static_module<xwindow_module>(bar, logger, config, name), m_connection(connection::make()) {}
|
||||
xwindow_module::xwindow_module(const bar_settings& bar, string name)
|
||||
: static_module<xwindow_module>(bar, name), m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
* Bootstrap the module
|
||||
|
@ -21,8 +21,8 @@ namespace modules {
|
||||
* Construct module
|
||||
*/
|
||||
xworkspaces_module::xworkspaces_module(
|
||||
const bar_settings& bar, const logger& logger, const config& config, string name)
|
||||
: static_module<xworkspaces_module>(bar, logger, config, name)
|
||||
const bar_settings& bar, string name)
|
||||
: static_module<xworkspaces_module>(bar, move(name))
|
||||
, m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ POLYBAR_NS
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
connection& connection::make() {
|
||||
connection::make_type connection::make() {
|
||||
auto instance = factory_util::singleton<connection>(xutils::get_connection(), xutils::get_connection_fd());
|
||||
return static_cast<connection&>(*instance);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ POLYBAR_NS
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<font_manager> font_manager::make() {
|
||||
font_manager::make_type font_manager::make() {
|
||||
return factory_util::unique<font_manager>(connection::make(), logger::make());
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace randr_util {
|
||||
}
|
||||
auto crtc = conn.get_crtc_info(info->crtc);
|
||||
string name{info.name().begin(), info.name().end()};
|
||||
monitors.emplace_back(make_monitor(*it, name, crtc->width, crtc->height, crtc->x, crtc->y));
|
||||
monitors.emplace_back(make_monitor(*it, move(name), crtc->width, crtc->height, crtc->x, crtc->y));
|
||||
} catch (const xpp::randr::error::bad_crtc&) {
|
||||
} catch (const xpp::randr::error::bad_output&) {
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ using namespace wm_util;
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<tray_manager> tray_manager::make() {
|
||||
tray_manager::make_type tray_manager::make() {
|
||||
return factory_util::unique<tray_manager>(connection::make(), signal_emitter::make(), logger::make());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user