polybar-dwm/include/modules/meta/event_module.hpp

50 lines
978 B
C++
Raw Normal View History

2016-11-20 22:04:31 +00:00
#pragma once
#include "modules/meta/base.hpp"
POLYBAR_NS
namespace modules {
template <class Impl>
class event_module : public module<Impl> {
public:
using module<Impl>::module;
void start() {
2017-01-12 19:29:08 +00:00
CAST_MOD(Impl)->update();
CAST_MOD(Impl)->broadcast();
this->m_mainthread = thread(&event_module::runner, this);
}
2016-11-20 22:04:31 +00:00
protected:
void runner() {
try {
2016-12-21 22:22:02 +00:00
while (this->running()) {
CAST_MOD(Impl)->idle();
2016-12-21 22:22:02 +00:00
if (!this->running()) {
break;
}
std::lock_guard<std::mutex> guard(this->m_updatelock);
if (!CAST_MOD(Impl)->has_event()) {
continue;
2016-12-21 22:22:02 +00:00
} else if (!this->running()) {
break;
} else if (!CAST_MOD(Impl)->update()) {
continue;
}
CAST_MOD(Impl)->broadcast();
}
} catch (const exception& err) {
CAST_MOD(Impl)->halt(err.what());
}
}
2016-11-20 22:04:31 +00:00
};
}
POLYBAR_NS_END