mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Style code (#25)
This commit is contained in:
@ -1,27 +1,26 @@
|
||||
#include "modules/clock.hpp"
|
||||
|
||||
waybar::modules::Clock::Clock(Json::Value config)
|
||||
: _config(config)
|
||||
: config_(std::move(config))
|
||||
{
|
||||
_label.set_name("clock");
|
||||
int interval = _config["interval"] ? _config["inveral"].asInt() : 60;
|
||||
_thread = [this, interval] {
|
||||
label_.set_name("clock");
|
||||
uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 60;
|
||||
thread_ = [this, interval] {
|
||||
auto now = waybar::chrono::clock::now();
|
||||
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Clock::update));
|
||||
auto timeout = std::chrono::floor<std::chrono::seconds>(now
|
||||
+ std::chrono::seconds(interval));
|
||||
_thread.sleep_until(timeout);
|
||||
thread_.sleep_until(timeout);
|
||||
};
|
||||
};
|
||||
|
||||
auto waybar::modules::Clock::update() -> void
|
||||
{
|
||||
auto localtime = fmt::localtime(std::time(nullptr));
|
||||
auto format =
|
||||
_config["format"] ? _config["format"].asString() : "{:%H:%M}";
|
||||
_label.set_text(fmt::format(format, localtime));
|
||||
auto format = config_["format"] ? config_["format"].asString() : "{:%H:%M}";
|
||||
label_.set_text(fmt::format(format, localtime));
|
||||
}
|
||||
|
||||
waybar::modules::Clock::operator Gtk::Widget &() {
|
||||
return _label;
|
||||
return label_;
|
||||
}
|
||||
|
Reference in New Issue
Block a user