2018-08-08 23:54:58 +02:00
|
|
|
#include "modules/clock.hpp"
|
|
|
|
|
|
|
|
waybar::modules::Clock::Clock()
|
|
|
|
{
|
2018-08-09 10:50:16 +02:00
|
|
|
_label.get_style_context()->add_class("clock");
|
2018-08-08 23:54:58 +02:00
|
|
|
_thread = [this] {
|
2018-08-09 12:05:48 +02:00
|
|
|
update();
|
2018-08-08 23:54:58 +02:00
|
|
|
auto now = waybar::chrono::clock::now();
|
|
|
|
auto timeout =
|
|
|
|
std::chrono::floor<std::chrono::minutes>(now + std::chrono::minutes(1));
|
|
|
|
_thread.sleep_until(timeout);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-08-09 12:05:48 +02:00
|
|
|
auto waybar::modules::Clock::update() -> void
|
|
|
|
{
|
|
|
|
auto t = std::time(nullptr);
|
|
|
|
auto localtime = std::localtime(&t);
|
|
|
|
_label.set_text(
|
|
|
|
fmt::format("{:02}:{:02}", localtime->tm_hour, localtime->tm_min));
|
|
|
|
}
|
|
|
|
|
2018-08-08 23:54:58 +02:00
|
|
|
waybar::modules::Clock::operator Gtk::Widget &() {
|
|
|
|
return _label;
|
|
|
|
}
|