Waybar/src/modules/clock.cpp

26 lines
619 B
C++
Raw Normal View History

2018-08-08 21:54:58 +00:00
#include "modules/clock.hpp"
waybar::modules::Clock::Clock()
{
2018-08-09 08:50:16 +00:00
_label.get_style_context()->add_class("clock");
2018-08-08 21:54:58 +00:00
_thread = [this] {
2018-08-09 10:05:48 +00:00
update();
2018-08-08 21:54:58 +00: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 10:05:48 +00: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 21:54:58 +00:00
waybar::modules::Clock::operator Gtk::Widget &() {
return _label;
}