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 tray_manager;
class logger; 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: public:
using make_type = unique_ptr<bar>; using make_type = unique_ptr<bar>;
static make_type make(); 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 reconfigure_wm_hints();
void broadcast_visibility(); 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::enter_notify& evt);
void handle(const evt::leave_notify& evt); void handle(const evt::leave_notify& evt);
void handle(const evt::button_press& evt); void handle(const evt::button_press& evt);

View File

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

View File

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

View File

@ -26,7 +26,7 @@ namespace modules {
if (!CONST_MOD(Impl).running()) if (!CONST_MOD(Impl).running())
break; 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()) if (!CAST_MOD(Impl)->has_event())
continue; continue;
@ -34,7 +34,6 @@ namespace modules {
break; break;
if (!CAST_MOD(Impl)->update()) if (!CAST_MOD(Impl)->update())
continue; continue;
CAST_MOD(Impl)->broadcast(); CAST_MOD(Impl)->broadcast();
} }
} }

View File

@ -58,7 +58,7 @@ namespace modules {
} }
while (CONST_MOD(Impl).running()) { 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) { for (auto&& w : watches) {
this->m_log.trace_x("%s: Poll inotify watch %s", CONST_MOD(Impl).name(), w->path()); 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() { void timer_module<Impl>::runner() {
try { try {
while (CONST_MOD(Impl).running()) { 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()) if (CAST_MOD(Impl)->update())
CAST_MOD(Impl)->broadcast(); 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 * Event handler for XCB_ENTER_NOTIFY events
* *

View File

@ -336,7 +336,7 @@ bool controller::on(const sig_ev::process_update& evt) {
try { try {
if (!m_writeback) { if (!m_writeback) {
m_bar->parse(move(contents), evt()); m_bar->parse(move(contents), force);
} else { } else {
std::cout << contents << std::endl; 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) { bool controller::on(const sig_ev::process_input& evt) {
try { try {
string input{*evt()}; string input{*evt.data()};
if (m_command) { if (m_command) {
m_log.warn("Terminating previous shell command"); m_log.warn("Terminating previous shell command");
@ -378,7 +378,7 @@ bool controller::on(const sig_ui::button_press& evt) {
return false; return false;
} }
string input{*evt()}; string input{*evt.data()};
if (input.empty()) { if (input.empty()) {
m_log.err("Cannot enqueue empty input"); 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) { bool controller::on(const sig_ipc::process_action& evt) {
ipc_action a{*evt()}; ipc_action a{*evt.data()};
string action{a.payload}; string action{a.payload};
action.erase(0, strlen(ipc_action::prefix)); 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) { bool controller::on(const sig_ipc::process_command& evt) {
ipc_command c{*evt()}; ipc_command c{*evt.data()};
string command{c.payload}; string command{c.payload};
command.erase(0, strlen(ipc_command::prefix)); 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) { 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& block : m_eventloop->modules()) {
for (const auto& module : block.second) { 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)) { if (evt.type == static_cast<uint8_t>(event_type::INPUT)) {
handle_inputdata(); handle_inputdata();
} else if (evt.type == static_cast<uint8_t>(event_type::QUIT)) { } 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)) { } 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)) { } 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 { } else {
m_log.warn("Unknown event type for enqueued event (%d)", evt.type); 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) { 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())}; const event quit{static_cast<const event>(*evt())};
m_log.info("Processing QUIT event (reload=%i)", quit.flag); m_log.info("Processing QUIT event (reload=%i)", quit.flag);
m_running = false; m_running = false;
@ -254,7 +253,6 @@ bool eventloop::on(const enqueue_event& evt) {
} }
bool eventloop::on(const enqueue_quit& evt) { bool eventloop::on(const enqueue_quit& evt) {
assert((*evt()).type == static_cast<uint8_t>(event_type::QUIT));
if (m_running) { if (m_running) {
const event quit{reinterpret_cast<const event&>(*evt())}; const event quit{reinterpret_cast<const event&>(*evt())};
m_log.info("Enqueuing QUIT event (reload=%i)", quit.flag); 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) { bool eventloop::on(const enqueue_update& evt) {
event update{reinterpret_cast<const event&>(*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); m_log.trace("eventloop: enqueuing UPDATE event (force=%i)", update.flag);
return enqueue(move(update)); return enqueue(move(update));
} }
@ -277,7 +274,6 @@ bool eventloop::on(const enqueue_input& evt) {
bool eventloop::on(const enqueue_check& evt) { bool eventloop::on(const enqueue_check& evt) {
event check{reinterpret_cast<const event&>(*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"); m_log.trace("eventloop: enqueuing CHECK event");
return enqueue(move(check)); return enqueue(move(check));
} }

View File

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

View File

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