Merge pull request #189 from DutchMofo/clock-tooltip
Added clock tooltip with optional alternate format
This commit is contained in:
commit
5a7f801922
|
@ -38,6 +38,7 @@
|
|||
"spacing": 10
|
||||
},
|
||||
"clock": {
|
||||
"tooltip-format": "{:%Y-%m-%d | %H:%S}",
|
||||
"format-alt": "{:%Y-%m-%d}"
|
||||
},
|
||||
"cpu": {
|
||||
|
|
|
@ -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_; }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue