Merge pull request #189 from DutchMofo/clock-tooltip

Added clock tooltip with optional alternate format
This commit is contained in:
Alex 2019-02-24 12:10:01 +01:00 committed by GitHub
commit 5a7f801922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View File

@ -38,6 +38,7 @@
"spacing": 10
},
"clock": {
"tooltip-format": "{:%Y-%m-%d | %H:%S}",
"format-alt": "{:%Y-%m-%d}"
},
"cpu": {

View File

@ -109,8 +109,7 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt)
bool waybar::ALabel::tooltipEnabled()
{
return !config_["tooltip"].isBool() ||
(config_["tooltip"].isBool() && config_["tooltip"].asBool());
return config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true;
}
waybar::ALabel::operator Gtk::Widget&() { return event_box_; }

View File

@ -21,5 +21,16 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
auto waybar::modules::Clock::update() -> void
{
auto localtime = fmt::localtime(std::time(nullptr));
label_.set_markup(fmt::format(format_, localtime));
auto text = fmt::format(format_, localtime);
label_.set_markup(text);
if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString();
auto tooltip_text = fmt::format(tooltip_format, localtime);
label_.set_tooltip_text(tooltip_text);
} else {
label_.set_tooltip_text(text);
}
}
}