2016-11-20 17:04:31 -05: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;
|
|
|
|
|
2016-12-21 03:21:35 -05:00
|
|
|
void start() {
|
2017-01-12 14:29:08 -05:00
|
|
|
CAST_MOD(Impl)->update();
|
|
|
|
CAST_MOD(Impl)->broadcast();
|
|
|
|
|
2016-12-21 03:21:35 -05:00
|
|
|
this->m_mainthread = thread(&event_module::runner, this);
|
|
|
|
}
|
2016-11-20 17:04:31 -05:00
|
|
|
|
|
|
|
protected:
|
2016-12-21 03:21:35 -05:00
|
|
|
void runner() {
|
|
|
|
try {
|
2016-12-21 17:22:02 -05:00
|
|
|
while (this->running()) {
|
2016-12-21 03:21:35 -05:00
|
|
|
CAST_MOD(Impl)->idle();
|
|
|
|
|
2016-12-21 17:22:02 -05:00
|
|
|
if (!this->running()) {
|
2016-12-21 03:21:35 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> guard(this->m_updatelock);
|
|
|
|
|
|
|
|
if (!CAST_MOD(Impl)->has_event()) {
|
|
|
|
continue;
|
2016-12-21 17:22:02 -05:00
|
|
|
} else if (!this->running()) {
|
2016-12-21 03:21:35 -05:00
|
|
|
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 17:04:31 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|