2018-08-08 23:54:58 +02:00
|
|
|
#include "modules/clock.hpp"
|
|
|
|
|
2018-08-20 14:50:45 +02:00
|
|
|
waybar::modules::Clock::Clock(const Json::Value& config)
|
2018-08-27 01:36:25 +02:00
|
|
|
: ALabel(config, "{:%H:%M}")
|
2018-08-08 23:54:58 +02:00
|
|
|
{
|
2018-08-16 14:29:41 +02:00
|
|
|
label_.set_name("clock");
|
2018-10-26 09:27:16 +02:00
|
|
|
uint32_t interval = config_["interval"].isUInt() ? config_["interval"].asUInt() : 60;
|
2018-08-16 14:29:41 +02:00
|
|
|
thread_ = [this, interval] {
|
2018-08-08 23:54:58 +02:00
|
|
|
auto now = waybar::chrono::clock::now();
|
2018-08-20 14:50:45 +02:00
|
|
|
dp.emit();
|
2018-08-15 21:00:04 +02:00
|
|
|
auto timeout = std::chrono::floor<std::chrono::seconds>(now
|
|
|
|
+ std::chrono::seconds(interval));
|
2018-08-16 14:29:41 +02:00
|
|
|
thread_.sleep_until(timeout);
|
2018-08-08 23:54:58 +02:00
|
|
|
};
|
2018-08-18 11:43:48 +02:00
|
|
|
}
|
2018-08-08 23:54:58 +02:00
|
|
|
|
2018-08-09 12:05:48 +02:00
|
|
|
auto waybar::modules::Clock::update() -> void
|
|
|
|
{
|
2018-08-15 20:53:27 +02:00
|
|
|
auto localtime = fmt::localtime(std::time(nullptr));
|
2018-11-21 20:49:09 +01:00
|
|
|
label_.set_markup(fmt::format(format_, localtime));
|
2018-08-09 12:05:48 +02:00
|
|
|
}
|