1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00

refactor: Cleanup

This commit is contained in:
Michael Carlberg 2016-12-16 10:23:54 +01:00
parent 09ea07b750
commit f50f43af02
11 changed files with 55 additions and 39 deletions

View file

@ -22,7 +22,7 @@ class screen;
class tray_manager;
class logger;
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify, evt::leave_notify> {
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify, evt::leave_notify, evt::destroy_notify, evt::client_message> {
public:
using make_type = unique_ptr<bar>;
static make_type make();
@ -43,6 +43,8 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
void reconfigure_wm_hints();
void broadcast_visibility();
void handle(const evt::client_message& evt);
void handle(const evt::destroy_notify& evt);
void handle(const evt::enter_notify& evt);
void handle(const evt::leave_notify& evt);
void handle(const evt::button_press& evt);

View file

@ -59,18 +59,18 @@ namespace modules {
// class definition : module_format {{{
struct module_format {
string value;
vector<string> tags;
label_t prefix;
label_t suffix;
string fg;
string bg;
string ul;
string ol;
int spacing;
int padding;
int margin;
int offset;
string value{};
vector<string> tags{};
label_t prefix{};
label_t suffix{};
string fg{};
string bg{};
string ul{};
string ol{};
int spacing{};
int padding{};
int margin{};
int offset{};
string decorate(builder* builder, string output);
};
@ -151,12 +151,12 @@ namespace modules {
callback<> m_update_callback;
callback<> m_stop_callback;
concurrency_util::spin_lock m_lock;
const bar_settings m_bar;
const logger& m_log;
const config& m_conf;
std::mutex m_buildlock;
std::mutex m_updatelock;
std::mutex m_sleeplock;
std::condition_variable m_sleephandler;

View file

@ -70,7 +70,8 @@ namespace modules {
wakeup();
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
std::lock_guard<std::mutex> guard_a(m_buildlock);
std::lock_guard<std::mutex> guard_b(m_updatelock);
{
CAST_MOD(Impl)->teardown();
@ -154,6 +155,7 @@ namespace modules {
m_log.trace("%s: Module is disabled", name());
return "";
}
std::lock_guard<std::mutex> guard(m_buildlock);
auto format_name = CONST_MOD(Impl).get_format();
auto format = m_formatter->get(format_name);

View file

@ -26,7 +26,7 @@ namespace modules {
if (!CONST_MOD(Impl).running())
break;
std::lock_guard<concurrency_util::spin_lock> guard(this->m_lock);
std::lock_guard<std::mutex> guard(this->m_updatelock);
{
if (!CAST_MOD(Impl)->has_event())
continue;
@ -34,7 +34,6 @@ namespace modules {
break;
if (!CAST_MOD(Impl)->update())
continue;
CAST_MOD(Impl)->broadcast();
}
}

View file

@ -58,7 +58,7 @@ namespace modules {
}
while (CONST_MOD(Impl).running()) {
std::unique_lock<concurrency_util::spin_lock> guard(this->m_lock);
std::unique_lock<std::mutex> guard(this->m_updatelock);
{
for (auto&& w : watches) {
this->m_log.trace_x("%s: Poll inotify watch %s", CONST_MOD(Impl).name(), w->path());

View file

@ -15,7 +15,7 @@ namespace modules {
void timer_module<Impl>::runner() {
try {
while (CONST_MOD(Impl).running()) {
std::lock_guard<concurrency_util::spin_lock> guard(this->m_lock);
std::lock_guard<std::mutex> guard(this->m_updatelock);
{
if (CAST_MOD(Impl)->update())
CAST_MOD(Impl)->broadcast();

View file

@ -415,6 +415,28 @@ void bar::broadcast_visibility() {
}
}
/**
* Event handler for XCB_DESTROY_NOTIFY events
*/
void bar::handle(const evt::client_message& evt) {
if (evt->type != WM_PROTOCOLS || evt->data.data32[0] != WM_DELETE_WINDOW) {
return;
}
if (evt->window == m_opts.window) {
m_log.err("Bar window has been destroyed, shutting down...");
m_connection.disconnect();
}
}
/**
* Event handler for XCB_DESTROY_NOTIFY events
*/
void bar::handle(const evt::destroy_notify& evt) {
if (evt->window == m_opts.window) {
m_connection.disconnect();
}
}
/**
* Event handler for XCB_ENTER_NOTIFY events
*

View file

@ -336,7 +336,7 @@ bool controller::on(const sig_ev::process_update& evt) {
try {
if (!m_writeback) {
m_bar->parse(move(contents), evt());
m_bar->parse(move(contents), force);
} else {
std::cout << contents << std::endl;
}
@ -349,7 +349,7 @@ bool controller::on(const sig_ev::process_update& evt) {
bool controller::on(const sig_ev::process_input& evt) {
try {
string input{*evt()};
string input{*evt.data()};
if (m_command) {
m_log.warn("Terminating previous shell command");
@ -378,7 +378,7 @@ bool controller::on(const sig_ui::button_press& evt) {
return false;
}
string input{*evt()};
string input{*evt.data()};
if (input.empty()) {
m_log.err("Cannot enqueue empty input");
@ -389,7 +389,7 @@ bool controller::on(const sig_ui::button_press& evt) {
}
bool controller::on(const sig_ipc::process_action& evt) {
ipc_action a{*evt()};
ipc_action a{*evt.data()};
string action{a.payload};
action.erase(0, strlen(ipc_action::prefix));
@ -403,7 +403,7 @@ bool controller::on(const sig_ipc::process_action& evt) {
}
bool controller::on(const sig_ipc::process_command& evt) {
ipc_command c{*evt()};
ipc_command c{*evt.data()};
string command{c.payload};
command.erase(0, strlen(ipc_command::prefix));
@ -423,7 +423,7 @@ bool controller::on(const sig_ipc::process_command& evt) {
}
bool controller::on(const sig_ipc::process_hook& evt) {
const ipc_hook hook{*evt()};
const ipc_hook hook{*evt.data()};
for (const auto& block : m_eventloop->modules()) {
for (const auto& module : block.second) {

View file

@ -93,11 +93,11 @@ void eventloop::start() {
if (evt.type == static_cast<uint8_t>(event_type::INPUT)) {
handle_inputdata();
} else if (evt.type == static_cast<uint8_t>(event_type::QUIT)) {
m_sig.emit(process_quit{reinterpret_cast<event&&>(evt)});
m_sig.emit(process_quit{make_input_evt()});
} else if (evt.type == static_cast<uint8_t>(event_type::UPDATE)) {
m_sig.emit(process_update{reinterpret_cast<event&&>(evt)});
m_sig.emit(process_update{make_update_evt(evt.flag)});
} else if (evt.type == static_cast<uint8_t>(event_type::CHECK)) {
m_sig.emit(process_check{reinterpret_cast<event&&>(evt)});
m_sig.emit(process_check{make_check_evt()});
} else {
m_log.warn("Unknown event type for enqueued event (%d)", evt.type);
}
@ -241,7 +241,6 @@ bool eventloop::on(const process_check&) {
}
bool eventloop::on(const process_quit& evt) {
assert((*evt()).type == static_cast<uint8_t>(event_type::QUIT));
const event quit{static_cast<const event>(*evt())};
m_log.info("Processing QUIT event (reload=%i)", quit.flag);
m_running = false;
@ -254,7 +253,6 @@ bool eventloop::on(const enqueue_event& evt) {
}
bool eventloop::on(const enqueue_quit& evt) {
assert((*evt()).type == static_cast<uint8_t>(event_type::QUIT));
if (m_running) {
const event quit{reinterpret_cast<const event&>(*evt())};
m_log.info("Enqueuing QUIT event (reload=%i)", quit.flag);
@ -265,7 +263,6 @@ bool eventloop::on(const enqueue_quit& evt) {
bool eventloop::on(const enqueue_update& evt) {
event update{reinterpret_cast<const event&>(*evt())};
assert(update.type == static_cast<uint8_t>(event_type::UPDATE));
m_log.trace("eventloop: enqueuing UPDATE event (force=%i)", update.flag);
return enqueue(move(update));
}
@ -277,7 +274,6 @@ bool eventloop::on(const enqueue_input& evt) {
bool eventloop::on(const enqueue_check& evt) {
event check{reinterpret_cast<const event&>(*evt())};
assert(check.type == static_cast<uint8_t>(event_type::CHECK));
m_log.trace("eventloop: enqueuing CHECK event");
return enqueue(move(check));
}

View file

@ -474,10 +474,6 @@ void renderer::debug_hints() {
// clang-format on
}};
for (auto&& hintwin : m_debughints) {
m_connection.destroy_window(hintwin);
}
m_debughints.clear();
for (auto&& action : m_actions) {

View file

@ -9,8 +9,7 @@ namespace xlib {
shared_ptr<Display> get_display() {
if (!g_display_ptr) {
// g_display_ptr = shared_ptr<Display>(XOpenDisplay(nullptr), bind(XCloseDisplay, placeholders::_1));
g_display_ptr = shared_ptr<Display>(XOpenDisplay(nullptr), factory_util::null_deleter{});
g_display_ptr = shared_ptr<Display>(XOpenDisplay(nullptr), [=](Display* ptr) { XCloseDisplay(ptr); });
}
return g_display_ptr;
}