fix(bspwm): Cleanup

This commit is contained in:
Michael Carlberg 2016-11-30 18:23:18 +01:00
parent 9cadb681d4
commit 43350c484e

View File

@ -1,9 +1,9 @@
#include <sys/socket.h> #include <sys/socket.h>
#include "modules/bspwm.hpp"
#include "drawtypes/iconset.hpp" #include "drawtypes/iconset.hpp"
#include "drawtypes/label.hpp" #include "drawtypes/label.hpp"
#include "modules/bspwm.hpp"
#include "utils/file.hpp"
#include "modules/meta/base.inl" #include "modules/meta/base.inl"
#include "modules/meta/event_module.inl" #include "modules/meta/event_module.inl"
@ -14,7 +14,13 @@ namespace modules {
template class module<bspwm_module>; template class module<bspwm_module>;
template class event_module<bspwm_module>; template class event_module<bspwm_module>;
void bspwm_module::setup() { // {{{ void bspwm_module::setup() {
auto socket_path = bspwm_util::get_socket_path();
if (!file_util::exists(socket_path)) {
throw module_error("Could not find socket: " + (socket_path.empty() ? "<empty>" : socket_path));
}
// Create ipc subscriber // Create ipc subscriber
m_subscriber = bspwm_util::make_subscriber(); m_subscriber = bspwm_util::make_subscriber();
@ -73,17 +79,17 @@ namespace modules {
m_icons->add(vec[0], make_shared<label>(vec[1])); m_icons->add(vec[0], make_shared<label>(vec[1]));
} }
} }
} // }}} }
void bspwm_module::stop() { // {{{ void bspwm_module::stop() {
if (m_subscriber) { if (m_subscriber) {
m_log.info("%s: Disconnecting from socket", name()); m_log.info("%s: Disconnecting from socket", name());
m_subscriber->disconnect(); m_subscriber->disconnect();
} }
event_module::stop(); event_module::stop();
} // }}} }
bool bspwm_module::has_event() { // {{{ bool bspwm_module::has_event() {
if (m_subscriber->poll(POLLHUP, 0)) { if (m_subscriber->poll(POLLHUP, 0)) {
m_log.warn("%s: Reconnecting to socket...", name()); m_log.warn("%s: Reconnecting to socket...", name());
m_subscriber = bspwm_util::make_subscriber(); m_subscriber = bspwm_util::make_subscriber();
@ -92,9 +98,9 @@ namespace modules {
ssize_t bytes = 0; ssize_t bytes = 0;
m_subscriber->receive(1, bytes, MSG_PEEK); m_subscriber->receive(1, bytes, MSG_PEEK);
return bytes > 0; return bytes > 0;
} // }}} }
bool bspwm_module::update() { // {{{ bool bspwm_module::update() {
ssize_t bytes = 0; ssize_t bytes = 0;
string data = m_subscriber->receive(BUFSIZ - 1, bytes, 0); string data = m_subscriber->receive(BUFSIZ - 1, bytes, 0);
@ -308,9 +314,9 @@ namespace modules {
} }
return true; return true;
} // }}} }
string bspwm_module::get_output() { // {{{ string bspwm_module::get_output() {
string output; string output;
for (m_index = 0; m_index < m_monitors.size(); m_index++) { for (m_index = 0; m_index < m_monitors.size(); m_index++) {
if (m_index > 0) { if (m_index > 0) {
@ -319,9 +325,9 @@ namespace modules {
output += event_module::get_output(); output += event_module::get_output();
} }
return output; return output;
} // }}} }
bool bspwm_module::build(builder* builder, const string& tag) const { // {{{ bool bspwm_module::build(builder* builder, const string& tag) const {
if (tag == TAG_LABEL_MONITOR) { if (tag == TAG_LABEL_MONITOR) {
builder->node(m_monitors[m_index]->label); builder->node(m_monitors[m_index]->label);
return true; return true;
@ -371,9 +377,9 @@ namespace modules {
} }
return false; return false;
} // }}} }
bool bspwm_module::handle_event(string cmd) { // {{{ bool bspwm_module::handle_event(string cmd) {
if (cmd.find(EVENT_PREFIX) != 0) { if (cmd.find(EVENT_PREFIX) != 0) {
return false; return false;
} }
@ -410,7 +416,7 @@ namespace modules {
} }
return true; return true;
} // }}} }
} }
POLYBAR_NS_END POLYBAR_NS_END