mirror of
https://github.com/polybar/polybar.git
synced 2024-11-25 13:55:47 -05:00
refactor: Construction methods
This commit is contained in:
parent
08be86fbe1
commit
1a2a6e5fab
51 changed files with 299 additions and 243 deletions
|
@ -25,6 +25,8 @@ class renderer;
|
|||
|
||||
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify> {
|
||||
public:
|
||||
static unique_ptr<bar> make();
|
||||
|
||||
explicit bar(connection& conn, signal_emitter& emitter, const config& config, const logger& logger,
|
||||
unique_ptr<screen> screen, unique_ptr<tray_manager> tray_manager);
|
||||
|
||||
|
@ -63,21 +65,4 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
|
|||
event_timer m_buttonpress{0L, 5L};
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure bar controller
|
||||
*/
|
||||
inline unique_ptr<bar> make_bar() {
|
||||
// clang-format off
|
||||
return factory_util::unique<bar>(
|
||||
make_connection(),
|
||||
make_signal_emitter(),
|
||||
make_confreader(),
|
||||
make_logger(),
|
||||
make_screen(),
|
||||
make_tray_manager());
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace command_line {
|
|||
|
||||
class parser {
|
||||
public:
|
||||
static unique_ptr<parser> 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<cliparser> make_command_line(string scriptname, const clioptions& opts) {
|
||||
return factory_util::unique<cliparser>("Usage: " + scriptname + " bar_name [OPTION...]", opts);
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -26,7 +26,7 @@ class config {
|
|||
using valuemap_t = std::unordered_map<string, string>;
|
||||
using sectionmap_t = std::unordered_map<string, valuemap_t>;
|
||||
|
||||
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<config> instance = factory_util::singleton<config>(make_logger(), make_xresource_manager());
|
||||
return static_cast<config&>(*instance);
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -37,6 +37,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);
|
||||
|
||||
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);
|
||||
~controller();
|
||||
|
@ -82,27 +84,4 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::proc
|
|||
bool m_writeback{false};
|
||||
};
|
||||
|
||||
namespace {
|
||||
inline unique_ptr<controller> make_controller(watch_t&& confwatch, bool enableipc = false, bool writeback = false) {
|
||||
unique_ptr<ipc> ipc;
|
||||
|
||||
if (enableipc) {
|
||||
ipc = make_ipc();
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
return factory_util::unique<controller>(
|
||||
make_connection(),
|
||||
make_signal_emitter(),
|
||||
make_logger(),
|
||||
make_confreader(),
|
||||
make_eventloop(),
|
||||
make_bar(),
|
||||
move(ipc),
|
||||
move(confwatch),
|
||||
writeback);
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -2,20 +2,32 @@
|
|||
|
||||
#include <moodycamel/blockingconcurrentqueue.h>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#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<modules::module_interface>;
|
||||
using modulemap_t = map<alignment, vector<module_t>>;
|
||||
using modulemap_t = std::map<alignment, vector<module_t>>;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class eventloop : public signal_receiver<SIGN_PRIORITY_EVENTLOOP, process_quit, process_input, process_check,
|
||||
enqueue_event, enqueue_quit, enqueue_update, enqueue_input, enqueue_check> {
|
||||
|
@ -39,9 +51,11 @@ class eventloop : public signal_receiver<SIGN_PRIORITY_EVENTLOOP, process_quit,
|
|||
|
||||
template <typename EventType>
|
||||
using queue_t = moodycamel::BlockingConcurrentQueue<EventType>;
|
||||
using duration_t = chrono::duration<double, std::milli>;
|
||||
using duration_t = std::chrono::duration<double, std::milli>;
|
||||
|
||||
public:
|
||||
static unique_ptr<eventloop> make();
|
||||
|
||||
explicit eventloop(signal_emitter& emitter, const logger& logger, const config& config);
|
||||
~eventloop();
|
||||
|
||||
|
@ -55,23 +69,11 @@ class eventloop : public signal_receiver<SIGN_PRIORITY_EVENTLOOP, process_quit,
|
|||
const modulemap_t& modules() const;
|
||||
size_t module_count() const;
|
||||
|
||||
static auto make_quit_evt(bool reload = false) {
|
||||
return event{static_cast<uint8_t>(event_type::QUIT), reload};
|
||||
}
|
||||
static auto make_update_evt(bool force = false) {
|
||||
return event{static_cast<uint8_t>(event_type::UPDATE), force};
|
||||
}
|
||||
static auto make_input_evt() {
|
||||
return event{static_cast<uint8_t>(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<uint8_t>(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<SIGN_PRIORITY_EVENTLOOP, process_quit,
|
|||
size_t m_swallow_limit{0};
|
||||
};
|
||||
|
||||
namespace {
|
||||
inline unique_ptr<eventloop> make_eventloop() {
|
||||
return make_unique<eventloop>(make_signal_emitter(), make_logger(), make_confreader());
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -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<ipc> 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<ipc> make_ipc() {
|
||||
return factory_util::unique<ipc>(make_signal_emitter(), make_logger());
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <string>
|
||||
|
||||
#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<loglevel, string> m_suffixes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
namespace {
|
||||
inline const logger& make_logger(loglevel level = loglevel::NONE) {
|
||||
auto instance = factory_util::singleton<const logger>(level);
|
||||
return static_cast<const logger&>(*instance);
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -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<SIGN_PRIORITY_RENDERER, change_background, change_foreground, change_underline,
|
||||
|
@ -25,6 +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);
|
||||
|
||||
explicit renderer(connection& conn, signal_emitter& emitter, const logger& logger,
|
||||
unique_ptr<font_manager> font_manager, const bar_settings& bar, const vector<string>& fonts);
|
||||
~renderer();
|
||||
|
@ -122,21 +124,4 @@ class renderer
|
|||
xcb_font_t m_gcfont{XCB_NONE};
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
inline unique_ptr<renderer> make_renderer(const bar_settings& bar, const vector<string>& fonts) {
|
||||
// clang-format off
|
||||
return factory_util::unique<renderer>(
|
||||
make_connection(),
|
||||
make_signal_emitter(),
|
||||
make_logger(),
|
||||
make_font_manager(),
|
||||
bar,
|
||||
fonts);
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -18,6 +18,8 @@ class signal_emitter;
|
|||
|
||||
class screen : public xpp::event::sink<evt::randr_screen_change_notify> {
|
||||
public:
|
||||
static unique_ptr<screen> 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<evt::randr_screen_change_notify> {
|
|||
bool m_sigraised{false};
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
inline unique_ptr<screen> make_screen() {
|
||||
return factory_util::unique<screen>(
|
||||
make_connection(), make_signal_emitter(), make_logger(), make_confreader());
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -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<label>;
|
||||
using icon = label;
|
||||
using icon_t = label_t;
|
||||
|
||||
class progressbar : public non_copyable_mixin<progressbar> {
|
||||
public:
|
||||
explicit progressbar(const bar_settings& bar, int width, string format);
|
||||
|
|
|
@ -18,6 +18,8 @@ extern signal_receivers_t g_signal_receivers;
|
|||
*/
|
||||
class signal_emitter {
|
||||
public:
|
||||
static signal_emitter& make();
|
||||
|
||||
explicit signal_emitter() = default;
|
||||
virtual ~signal_emitter() {}
|
||||
|
||||
|
@ -99,14 +101,4 @@ class signal_emitter {
|
|||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
inline signal_emitter& make_signal_emitter() {
|
||||
auto instance = factory_util::singleton<signal_emitter>();
|
||||
return static_cast<signal_emitter&>(*instance);
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "components/logger.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/functional.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -76,7 +77,7 @@ namespace command_util {
|
|||
|
||||
template <typename... Args>
|
||||
unique_ptr<command> make_command(Args&&... args) {
|
||||
return make_unique<command>(make_logger(), forward<Args>(args)...);
|
||||
return factory_util::unique<command>(logger::make(), forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,7 @@ POLYBAR_NS
|
|||
namespace this_thread = std::this_thread;
|
||||
|
||||
using std::thread;
|
||||
|
||||
template <typename T>
|
||||
using atomic = std::atomic<T>;
|
||||
|
||||
using stateflag = atomic<bool>;
|
||||
using stateflag = std::atomic<bool>;
|
||||
|
||||
namespace concurrency_util {
|
||||
namespace locking_strategy {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "common.hpp"
|
||||
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -36,7 +37,7 @@ namespace scope_util {
|
|||
*/
|
||||
template <typename Fn = function<void()>, typename... Args>
|
||||
decltype(auto) make_exit_handler(Fn&& fn, Args&&... args) {
|
||||
return make_unique<on_exit<Args...>>(forward<Fn>(fn), forward<Args>(args)...);
|
||||
return factory_util::unique<on_exit<Args...>>(forward<Fn>(fn), forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <poll.h>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -36,8 +37,9 @@ namespace socket_util {
|
|||
* conn->receive(...);
|
||||
* @endcode
|
||||
*/
|
||||
auto make_unix_connection = [](
|
||||
string&& path) -> unique_ptr<unix_connection> { return make_unique<unix_connection>(forward<string>(path)); };
|
||||
auto make_unix_connection = [](string&& path) -> unique_ptr<unix_connection> {
|
||||
return factory_util::unique<unix_connection>(forward<string>(path));
|
||||
};
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -84,7 +85,7 @@ namespace throttle_util {
|
|||
|
||||
template <typename... Args>
|
||||
throttle_t make_throttler(Args&&... args) {
|
||||
return make_unique<event_throttler>(forward<Args>(args)...);
|
||||
return factory_util::unique<event_throttler>(forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ using xpp_connection = xpp::connection<XPP_EXTENSION_LIST>;
|
|||
|
||||
class connection : public xpp_connection {
|
||||
public:
|
||||
static connection& make();
|
||||
|
||||
explicit connection(xcb_connection_t* conn) : connection(conn, 0) {}
|
||||
explicit connection(xcb_connection_t* conn, int connection_fd)
|
||||
: xpp_connection(conn), m_connection_fd(connection_fd) {}
|
||||
|
@ -98,14 +100,4 @@ class connection : public xpp_connection {
|
|||
int m_connection_fd{0};
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
inline connection& make_connection() {
|
||||
auto instance = factory_util::singleton<connection>(xutils::get_connection(), xutils::get_connection_fd());
|
||||
return static_cast<connection&>(*instance);
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <xcb/xcbext.h>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "x11/color.hpp"
|
||||
#include "x11/types.hpp"
|
||||
|
||||
|
@ -12,6 +11,7 @@ POLYBAR_NS
|
|||
|
||||
// fwd
|
||||
class connection;
|
||||
class logger;
|
||||
|
||||
#define XFT_MAXCHARS (1 << 16)
|
||||
extern array<char, XFT_MAXCHARS> xft_widths;
|
||||
|
@ -39,6 +39,8 @@ using font_t = unique_ptr<fonttype, fonttype_deleter>;
|
|||
|
||||
class font_manager {
|
||||
public:
|
||||
static unique_ptr<font_manager> make();
|
||||
|
||||
explicit font_manager(connection& conn, const logger& logger);
|
||||
~font_manager();
|
||||
|
||||
|
@ -71,13 +73,11 @@ class font_manager {
|
|||
Visual* m_visual{nullptr};
|
||||
Colormap m_colormap{};
|
||||
|
||||
map<uint8_t, font_t> m_fonts;
|
||||
std::map<uint8_t, font_t> m_fonts;
|
||||
int8_t m_fontindex{DEFAULT_FONT_INDEX};
|
||||
|
||||
XftColor m_xftcolor{};
|
||||
XftDraw* m_xftdraw{nullptr};
|
||||
};
|
||||
|
||||
unique_ptr<font_manager> make_font_manager();
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -65,6 +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();
|
||||
|
||||
explicit tray_manager(connection& conn, signal_emitter& emitter, const logger& logger);
|
||||
|
||||
~tray_manager();
|
||||
|
@ -156,13 +158,4 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
|
|||
std::mutex m_mtx;
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
inline unique_ptr<tray_manager> make_tray_manager() {
|
||||
return factory_util::unique<tray_manager>(make_connection(), make_signal_emitter(), make_logger());
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -8,6 +8,8 @@ POLYBAR_NS
|
|||
|
||||
class xresource_manager {
|
||||
public:
|
||||
static const xresource_manager& make();
|
||||
|
||||
explicit xresource_manager();
|
||||
|
||||
string get_string(string name, string fallback = "") const;
|
||||
|
@ -22,6 +24,4 @@ class xresource_manager {
|
|||
XrmDatabase m_db;
|
||||
};
|
||||
|
||||
const xresource_manager& make_xresource_manager();
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "events/signal_emitter.hpp"
|
||||
#include "utils/bspwm.hpp"
|
||||
#include "utils/color.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "x11/atoms.hpp"
|
||||
|
@ -31,6 +32,21 @@ POLYBAR_NS
|
|||
using namespace signals::ui;
|
||||
using namespace wm_util;
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<bar> bar::make() {
|
||||
// clang-format off
|
||||
return factory_util::unique<bar>(
|
||||
connection::make(),
|
||||
signal_emitter::make(),
|
||||
config::make(),
|
||||
logger::make(),
|
||||
screen::make(),
|
||||
tray_manager::make());
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct bar instance
|
||||
*
|
||||
|
@ -196,7 +212,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||
|
||||
m_log.trace("bar: Create renderer");
|
||||
auto fonts = m_conf.get_list<string>(m_conf.bar_section(), "font", {});
|
||||
m_renderer = make_renderer(m_opts, move(fonts));
|
||||
m_renderer = renderer::make(m_opts, move(fonts));
|
||||
|
||||
m_log.trace("bar: Attaching sink to registry");
|
||||
m_connection.attach_sink(this, SINK_PRIORITY_BAR);
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<cliparser> cliparser::make(string scriptname, const clioptions& opts) {
|
||||
return factory_util::unique<cliparser>("Usage: " + scriptname + " bar_name [OPTION...]", opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print application usage message
|
||||
*/
|
||||
|
|
|
@ -4,12 +4,20 @@
|
|||
#include <utility>
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/env.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration and validate bar section
|
||||
*
|
||||
|
|
|
@ -16,6 +16,33 @@ POLYBAR_NS
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
return factory_util::unique<controller>(
|
||||
connection::make(),
|
||||
signal_emitter::make(),
|
||||
logger::make(),
|
||||
config::make(),
|
||||
eventloop::make(),
|
||||
bar::make(),
|
||||
move(ipc),
|
||||
move(confwatch),
|
||||
writeback);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct controller object
|
||||
*/
|
||||
controller::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)
|
||||
: m_connection(conn)
|
||||
|
@ -28,6 +55,9 @@ controller::controller(connection& conn, signal_emitter& emitter, const logger&
|
|||
, m_confwatch(move(confwatch))
|
||||
, m_writeback(writeback) {}
|
||||
|
||||
/**
|
||||
* Deconstruct controller object
|
||||
*/
|
||||
controller::~controller() {
|
||||
if (m_eventloop) {
|
||||
m_log.info("Deconstructing eventloop");
|
||||
|
|
|
@ -1,14 +1,44 @@
|
|||
#include <csignal>
|
||||
#include <cstring>
|
||||
|
||||
#include "components/eventloop.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "events/signal.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "modules/meta/base.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "x11/color.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<eventloop> eventloop::make() {
|
||||
return factory_util::unique<eventloop>(signal_emitter::make(), logger::make(), config::make());
|
||||
}
|
||||
|
||||
eventloop::event eventloop::make_quit_evt(bool reload) {
|
||||
return event{static_cast<uint8_t>(event_type::QUIT), reload};
|
||||
}
|
||||
eventloop::event eventloop::make_update_evt(bool force) {
|
||||
return event{static_cast<uint8_t>(event_type::UPDATE), force};
|
||||
}
|
||||
eventloop::event eventloop::make_input_evt() {
|
||||
return event{static_cast<uint8_t>(event_type::INPUT)};
|
||||
}
|
||||
eventloop::event eventloop::make_check_evt() {
|
||||
return event{static_cast<uint8_t>(event_type::CHECK)};
|
||||
}
|
||||
eventloop::input_data eventloop::make_input_data(string&& data) {
|
||||
input_data d{};
|
||||
memcpy(d.data, &data[0], sizeof(d.data));
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct eventloop instance
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "config.hpp"
|
||||
#include "events/signal.hpp"
|
||||
#include "events/signal_emitter.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/io.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
@ -14,6 +15,13 @@ POLYBAR_NS
|
|||
|
||||
using namespace signals::ipc;
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<ipc> ipc::make() {
|
||||
return factory_util::unique<ipc>(signal_emitter::make(), logger::make());
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupt the blocked listener and
|
||||
* remove the file handler
|
||||
|
|
|
@ -2,10 +2,19 @@
|
|||
|
||||
#include "components/logger.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
const logger& logger::make(loglevel level) {
|
||||
auto instance = factory_util::singleton<const logger>(level);
|
||||
return static_cast<const logger&>(*instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct logger
|
||||
*/
|
||||
|
|
|
@ -15,6 +15,21 @@
|
|||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<renderer> renderer::make(const bar_settings& bar, vector<string>&& fonts) {
|
||||
// clang-format off
|
||||
return factory_util::unique<renderer>(
|
||||
connection::make(),
|
||||
signal_emitter::make(),
|
||||
logger::make(),
|
||||
font_manager::make(),
|
||||
forward<decltype(bar)>(bar),
|
||||
forward<decltype(fonts)>(fonts));
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct renderer instance
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,14 @@ POLYBAR_NS
|
|||
|
||||
using namespace signals::eventloop;
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<screen> screen::make() {
|
||||
return factory_util::unique<screen>(
|
||||
connection::make(), signal_emitter::make(), logger::make(), config::make());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct screen instance
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "drawtypes/animation.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <utility>
|
||||
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -19,8 +20,8 @@ namespace drawtypes {
|
|||
std::back_insert_iterator<decltype(tokens)> back_it(tokens);
|
||||
std::copy(m_tokens.begin(), m_tokens.end(), back_it);
|
||||
}
|
||||
return factory_util::shared<label>(m_text, m_foreground, m_background, m_underline, m_overline, m_font, m_padding, m_margin,
|
||||
m_maxlen, m_ellipsis, move(tokens));
|
||||
return factory_util::shared<label>(m_text, m_foreground, m_background, m_underline, m_overline, m_font, m_padding,
|
||||
m_margin, m_maxlen, m_ellipsis, move(tokens));
|
||||
}
|
||||
|
||||
void label::reset_tokens() {
|
||||
|
@ -204,7 +205,7 @@ namespace drawtypes {
|
|||
}
|
||||
|
||||
// clang-format off
|
||||
return make_shared<label>(text,
|
||||
return factory_util::shared<label>(text,
|
||||
conf.get<string>(section, name + "-foreground", ""),
|
||||
conf.get<string>(section, name + "-background", ""),
|
||||
conf.get<string>(section, name + "-underline", ""),
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include <utility>
|
||||
|
||||
#include "components/types.hpp"
|
||||
#include "x11/color.hpp"
|
||||
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace drawtypes {
|
||||
progressbar::progressbar(const bar_settings& bar, int width, string format)
|
||||
: m_builder(make_unique<builder>(bar)), m_format(move(format)), m_width(width) {}
|
||||
: m_builder(factory_util::unique<builder>(bar)), m_format(move(format)), m_width(width) {}
|
||||
|
||||
void progressbar::set_fill(icon_t&& fill) {
|
||||
m_fill = forward<decltype(fill)>(fill);
|
||||
|
@ -100,9 +99,9 @@ namespace drawtypes {
|
|||
throw application_error("Invalid width defined at [" + section + "." + name + "]");
|
||||
}
|
||||
|
||||
progressbar_t progressbar{new progressbar_t::element_type(bar, width, format)};
|
||||
progressbar->set_gradient(conf.get<bool>(section, name + "-gradient", true));
|
||||
progressbar->set_colors(conf.get_list<string>(section, name + "-foreground", {}));
|
||||
auto pbar = factory_util::shared<progressbar>(bar, width, format);
|
||||
pbar->set_gradient(conf.get<bool>(section, name + "-gradient", true));
|
||||
pbar->set_colors(conf.get_list<string>(section, name + "-foreground", {}));
|
||||
|
||||
icon_t icon_empty;
|
||||
icon_t icon_fill;
|
||||
|
@ -130,11 +129,11 @@ namespace drawtypes {
|
|||
}
|
||||
}
|
||||
|
||||
progressbar->set_empty(move(icon_empty));
|
||||
progressbar->set_fill(move(icon_fill));
|
||||
progressbar->set_indicator(move(icon_indicator));
|
||||
pbar->set_empty(move(icon_empty));
|
||||
pbar->set_fill(move(icon_fill));
|
||||
pbar->set_indicator(move(icon_indicator));
|
||||
|
||||
return progressbar;
|
||||
return pbar;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "drawtypes/ramp.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -45,7 +46,7 @@ namespace drawtypes {
|
|||
vec.emplace_back(move(icon));
|
||||
}
|
||||
|
||||
return factory_util::shared<ramp>(move(vec));
|
||||
return factory_util::shared<drawtypes::ramp>(move(vec));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,4 +5,12 @@ POLYBAR_NS
|
|||
|
||||
signal_receivers_t g_signal_receivers;
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
signal_emitter& signal_emitter::make() {
|
||||
auto instance = factory_util::singleton<signal_emitter>();
|
||||
return static_cast<signal_emitter&>(*instance);
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -1,7 +1,6 @@
|
|||
#include <X11/Xlib-xcb.h>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include "components/command_line.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/controller.hpp"
|
||||
|
@ -14,6 +13,9 @@
|
|||
|
||||
using namespace polybar;
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
struct exit_success {};
|
||||
struct exit_failure {};
|
||||
|
||||
|
@ -35,7 +37,7 @@ int main(int argc, char** argv) {
|
|||
uint8_t exit_code{EXIT_SUCCESS};
|
||||
bool reload{false};
|
||||
|
||||
logger& logger{const_cast<class logger&>(make_logger(loglevel::WARNING))};
|
||||
logger& logger{const_cast<class logger&>(logger::make(loglevel::WARNING))};
|
||||
|
||||
try {
|
||||
//==================================================
|
||||
|
@ -68,7 +70,7 @@ int main(int argc, char** argv) {
|
|||
string scriptname{argv[0]};
|
||||
vector<string> args(argv + 1, argv + argc);
|
||||
|
||||
unique_ptr<cliparser> cli{make_command_line(scriptname, opts)};
|
||||
unique_ptr<cliparser> cli{command_line::parser::make(scriptname, opts)};
|
||||
cli->process_input(args);
|
||||
|
||||
if (cli->has("quiet")) {
|
||||
|
@ -91,7 +93,7 @@ int main(int argc, char** argv) {
|
|||
//==================================================
|
||||
// Load user configuration
|
||||
//==================================================
|
||||
config& conf{const_cast<config&>(make_confreader())};
|
||||
config& conf{const_cast<config&>(config::make())};
|
||||
|
||||
if (cli->has("config")) {
|
||||
conf.load(cli->get("config"), args[0]);
|
||||
|
@ -107,7 +109,7 @@ int main(int argc, char** argv) {
|
|||
// Dump requested data
|
||||
//==================================================
|
||||
if (cli->has("dump")) {
|
||||
std::cout << conf.get<string>(conf.bar_section(), cli->get("dump")) << std::endl;
|
||||
cout << conf.get<string>(conf.bar_section(), cli->get("dump")) << endl;
|
||||
throw exit_success{};
|
||||
}
|
||||
|
||||
|
@ -115,19 +117,20 @@ int main(int argc, char** argv) {
|
|||
// Create controller and run application
|
||||
//==================================================
|
||||
unique_ptr<controller> ctrl;
|
||||
bool enable_ipc{conf.get<bool>(conf.bar_section(), "enable-ipc", false)};
|
||||
bool enable_ipc{false};
|
||||
watch_t confwatch;
|
||||
|
||||
if (cli->has("print-wmname")) {
|
||||
enable_ipc = false;
|
||||
} else if (cli->has("reload")) {
|
||||
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());
|
||||
}
|
||||
|
||||
ctrl = make_controller(move(confwatch), enable_ipc, cli->has("stdout"));
|
||||
ctrl = controller::make(move(confwatch), enable_ipc, cli->has("stdout"));
|
||||
|
||||
if (cli->has("print-wmname")) {
|
||||
std::cout << ctrl->opts().wmname << std::endl;
|
||||
cout << ctrl->opts().wmname << endl;
|
||||
throw exit_success{};
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "drawtypes/label.hpp"
|
||||
#include "modules/bspwm.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/event_module.inl"
|
||||
|
@ -226,7 +227,7 @@ namespace modules {
|
|||
uint32_t workspace_mask{0U};
|
||||
|
||||
if (tag[0] == 'm' || tag[0] == 'M') {
|
||||
m_monitors.emplace_back(make_unique<bspwm_monitor>());
|
||||
m_monitors.emplace_back(factory_util::unique<bspwm_monitor>());
|
||||
m_monitors.back()->name = value;
|
||||
|
||||
if (m_monitorlabel) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "drawtypes/ramp.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "utils/mtab.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
@ -66,7 +67,7 @@ namespace modules {
|
|||
continue;
|
||||
}
|
||||
|
||||
auto mtab = make_unique<mtab_util::reader>();
|
||||
auto mtab = factory_util::unique<mtab_util::reader>();
|
||||
auto& mount = m_mounts.back();
|
||||
|
||||
while (mtab->next(&mnt)) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "drawtypes/iconset.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "modules/i3.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
|
@ -25,7 +26,7 @@ namespace modules {
|
|||
throw module_error("Could not find socket: " + (socket_path.empty() ? "<empty>" : socket_path));
|
||||
}
|
||||
|
||||
m_ipc = make_unique<i3ipc::connection>();
|
||||
m_ipc = factory_util::unique<i3ipc::connection>();
|
||||
|
||||
// Load configuration values
|
||||
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
||||
|
@ -151,7 +152,7 @@ namespace modules {
|
|||
label->replace_token("%name%", ws_name);
|
||||
label->replace_token("%icon%", icon->get());
|
||||
label->replace_token("%index%", to_string(ws->num));
|
||||
m_workspaces.emplace_back(make_unique<workspace>(ws->num, ws_state, move(label)));
|
||||
m_workspaces.emplace_back(factory_util::unique<workspace>(ws->num, ws_state, move(label)));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "modules/menu.hpp"
|
||||
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/scope.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
|
@ -36,7 +37,7 @@ namespace modules {
|
|||
}
|
||||
|
||||
m_log.trace("%s: Creating menu level %i", name(), m_levels.size());
|
||||
m_levels.emplace_back(make_unique<menu_tree>());
|
||||
m_levels.emplace_back(factory_util::unique<menu_tree>());
|
||||
|
||||
while (true) {
|
||||
string item_param{level_param + "-" + to_string(m_levels.back()->items.size())};
|
||||
|
@ -46,7 +47,7 @@ namespace modules {
|
|||
}
|
||||
|
||||
m_log.trace("%s: Creating menu level item %i", name(), m_levels.back()->items.size());
|
||||
auto item = make_unique<menu_tree_item>();
|
||||
auto item = factory_util::unique<menu_tree_item>();
|
||||
item->label = load_label(m_conf, name(), item_param);
|
||||
item->exec = m_conf.get<string>(name(), item_param + "-exec", EVENT_MENU_CLOSE);
|
||||
m_levels.back()->items.emplace_back(move(item));
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "drawtypes/iconset.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/event_module.inl"
|
||||
|
@ -86,7 +87,7 @@ namespace modules {
|
|||
m_lastsync = chrono::system_clock::now();
|
||||
|
||||
try {
|
||||
m_mpd = make_unique<mpdconnection>(m_log, m_host, m_port, m_pass);
|
||||
m_mpd = factory_util::unique<mpdconnection>(m_log, m_host, m_port, m_pass);
|
||||
m_mpd->connect();
|
||||
m_status = m_mpd->get_status();
|
||||
} catch (const mpd_exception& err) {
|
||||
|
@ -122,7 +123,7 @@ namespace modules {
|
|||
|
||||
try {
|
||||
if (!m_mpd) {
|
||||
m_mpd = make_unique<mpdconnection>(m_log, m_host, m_port, m_pass);
|
||||
m_mpd = factory_util::unique<mpdconnection>(m_log, m_host, m_port, m_pass);
|
||||
}
|
||||
if (!connected()) {
|
||||
m_mpd->connect();
|
||||
|
@ -323,7 +324,7 @@ namespace modules {
|
|||
}
|
||||
|
||||
try {
|
||||
auto mpd = make_unique<mpdconnection>(m_log, m_host, m_port, m_pass);
|
||||
auto mpd = factory_util::unique<mpdconnection>(m_log, m_host, m_port, m_pass);
|
||||
mpd->connect();
|
||||
|
||||
auto status = mpd->get_status();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "drawtypes/animation.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/ramp.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
@ -62,9 +63,9 @@ namespace modules {
|
|||
|
||||
// Get an intstance of the network interface
|
||||
if (net::is_wireless_interface(m_interface)) {
|
||||
m_wireless = make_unique<net::wireless_network>(m_interface);
|
||||
m_wireless = factory_util::unique<net::wireless_network>(m_interface);
|
||||
} else {
|
||||
m_wired = make_unique<net::wired_network>(m_interface);
|
||||
m_wired = factory_util::unique<net::wired_network>(m_interface);
|
||||
};
|
||||
|
||||
// We only need to start the subthread if the packetloss animation is used
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace modules {
|
|||
*/
|
||||
xbacklight_module::xbacklight_module(const bar_settings& bar, const logger& logger, const config& config, string name)
|
||||
: static_module<xbacklight_module>(bar, logger, config, name)
|
||||
, m_connection(make_connection()) {}
|
||||
, m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
* Bootstrap the module by grabbing all required components
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "modules/xkeyboard.hpp"
|
||||
#include "drawtypes/iconset.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "x11/atoms.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
|
@ -17,8 +18,7 @@ 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(make_connection()) {}
|
||||
: static_module<xkeyboard_module>(bar, logger, config, name), m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
* Bootstrap the module
|
||||
|
@ -125,7 +125,7 @@ namespace modules {
|
|||
auto layouts = xkb_util::get_layouts(m_connection, XCB_XKB_ID_USE_CORE_KBD);
|
||||
auto indicators = xkb_util::get_indicators(m_connection, XCB_XKB_ID_USE_CORE_KBD);
|
||||
auto current_group = xkb_util::get_current_group(m_connection, XCB_XKB_ID_USE_CORE_KBD);
|
||||
m_keyboard = make_unique<keyboard>(move(layouts), move(indicators), current_group);
|
||||
m_keyboard = factory_util::unique<keyboard>(move(layouts), move(indicators), current_group);
|
||||
return true;
|
||||
} catch (const exception& err) {
|
||||
throw module_error("Failed to query keyboard, err: " + string{err.what()});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "modules/xwindow.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "x11/atoms.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/graphics.hpp"
|
||||
|
@ -17,8 +18,7 @@ namespace modules {
|
|||
* Wrapper used to update the event mask of the
|
||||
* currently active to enable title tracking
|
||||
*/
|
||||
active_window::active_window(xcb_window_t win)
|
||||
: m_connection(make_connection()), m_window(m_connection, win) {
|
||||
active_window::active_window(xcb_window_t win) : m_connection(connection::make()), m_window(m_connection, win) {
|
||||
try {
|
||||
m_window.change_event_mask(XCB_EVENT_MASK_PROPERTY_CHANGE);
|
||||
} catch (const xpp::x::error::window& err) {
|
||||
|
@ -65,8 +65,7 @@ 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(make_connection()) {}
|
||||
: static_module<xwindow_module>(bar, logger, config, name), m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
* Bootstrap the module
|
||||
|
@ -138,7 +137,7 @@ namespace modules {
|
|||
if (m_active && m_active->match(win)) {
|
||||
title = m_active->title(m_ewmh.get());
|
||||
} else if (win != XCB_NONE) {
|
||||
m_active = make_unique<active_window>(win);
|
||||
m_active = factory_util::unique<active_window>(win);
|
||||
title = m_active->title(m_ewmh.get());
|
||||
} else {
|
||||
m_active.reset();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "drawtypes/iconset.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "modules/xworkspaces.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "x11/atoms.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
@ -22,7 +23,7 @@ namespace modules {
|
|||
xworkspaces_module::xworkspaces_module(
|
||||
const bar_settings& bar, const logger& logger, const config& config, string name)
|
||||
: static_module<xworkspaces_module>(bar, logger, config, name)
|
||||
, m_connection(make_connection()) {}
|
||||
, m_connection(connection::make()) {}
|
||||
|
||||
/**
|
||||
* Bootstrap the module
|
||||
|
@ -140,7 +141,7 @@ namespace modules {
|
|||
}
|
||||
|
||||
if (m_monitorsupport && (n == 0 || pos.x != viewports[n].x || pos.y != viewports[n].y)) {
|
||||
m_viewports.emplace_back(make_unique<viewport>());
|
||||
m_viewports.emplace_back(factory_util::unique<viewport>());
|
||||
|
||||
for (auto&& monitor : m_monitors) {
|
||||
if (monitor->match(viewports[n])) {
|
||||
|
@ -155,12 +156,12 @@ namespace modules {
|
|||
}
|
||||
}
|
||||
} else if (!m_monitorsupport && n == 0) {
|
||||
m_viewports.emplace_back(make_unique<viewport>());
|
||||
m_viewports.emplace_back(factory_util::unique<viewport>());
|
||||
m_viewports.back()->state = viewport_state::NONE;
|
||||
}
|
||||
|
||||
desktop_state state{current == n ? desktop_state::ACTIVE : desktop_state::EMPTY};
|
||||
m_viewports.back()->desktops.emplace_back(make_unique<desktop>(n, state, m_labels[state]->clone()));
|
||||
m_viewports.back()->desktops.emplace_back(factory_util::unique<desktop>(n, state, m_labels[state]->clone()));
|
||||
|
||||
auto& desktop = m_viewports.back()->desktops.back();
|
||||
desktop->label->reset_tokens();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <fstream>
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/scope.hpp"
|
||||
|
||||
|
@ -80,7 +81,7 @@ namespace file_util {
|
|||
* Checks if the given file is a named pipe
|
||||
*/
|
||||
bool is_fifo(string filename) {
|
||||
auto fileptr = make_unique<file_ptr>(filename);
|
||||
auto fileptr = factory_util::unique<file_ptr>(filename);
|
||||
int fd = fileno((*fileptr)());
|
||||
struct stat statbuf;
|
||||
fstat(fd, &statbuf);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/inotify.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
|
||||
|
@ -66,7 +67,7 @@ namespace inotify_util {
|
|||
* Get the latest inotify event
|
||||
*/
|
||||
unique_ptr<event_t> inotify_watch::get_event() {
|
||||
auto event = make_unique<event_t>();
|
||||
auto event = factory_util::unique<event_t>();
|
||||
|
||||
if (m_fd == -1 || m_wd == -1) {
|
||||
return event;
|
||||
|
|
|
@ -8,6 +8,14 @@
|
|||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
connection& connection::make() {
|
||||
auto instance = factory_util::singleton<connection>(xutils::get_connection(), xutils::get_connection_fd());
|
||||
return static_cast<connection&>(*instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload required xcb atoms
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <X11/Xlib-xcb.h>
|
||||
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/color.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
|
@ -11,10 +12,10 @@
|
|||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Configure injection module
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<font_manager> make_font_manager() {
|
||||
return factory_util::unique<font_manager>(make_connection(), make_logger());
|
||||
unique_ptr<font_manager> font_manager::make() {
|
||||
return factory_util::unique<font_manager>(connection::make(), logger::make());
|
||||
}
|
||||
|
||||
array<char, XFT_MAXCHARS> xft_widths;
|
||||
|
|
|
@ -43,6 +43,13 @@ POLYBAR_NS
|
|||
|
||||
using namespace wm_util;
|
||||
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
unique_ptr<tray_manager> tray_manager::make() {
|
||||
return factory_util::unique<tray_manager>(connection::make(), signal_emitter::make(), logger::make());
|
||||
}
|
||||
|
||||
tray_manager::tray_manager(connection& conn, signal_emitter& emitter, const logger& logger)
|
||||
: m_connection(conn), m_sig(emitter), m_log(logger) {}
|
||||
|
||||
|
@ -54,7 +61,7 @@ tray_manager::~tray_manager() {
|
|||
}
|
||||
|
||||
void tray_manager::setup(const bar_settings& bar_opts) {
|
||||
auto conf = make_confreader();
|
||||
auto conf = config::make();
|
||||
auto bs = conf.bar_section();
|
||||
auto tray_position = conf.get<string>(bs, "tray-position", "");
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Configure injection module
|
||||
* Create instance
|
||||
*/
|
||||
const xresource_manager& make_xresource_manager() {
|
||||
const xresource_manager& xresource_manager::make() {
|
||||
auto instance = factory_util::singleton<xresource_manager>();
|
||||
return static_cast<const xresource_manager&>(*instance);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue