Added clock tooltip with optional alternate format

pull/189/head
Piet van der Loo 2019-02-24 09:25:34 +01:00
parent b4f36436c3
commit 7245fb5d0a
3 changed files with 15 additions and 3 deletions

View File

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

View File

@ -109,8 +109,7 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt)
bool waybar::ALabel::tooltipEnabled() bool waybar::ALabel::tooltipEnabled()
{ {
return !config_["tooltip"].isBool() || return config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true;
(config_["tooltip"].isBool() && config_["tooltip"].asBool());
} }
waybar::ALabel::operator Gtk::Widget&() { return event_box_; } 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 waybar::modules::Clock::update() -> void
{ {
auto localtime = fmt::localtime(std::time(nullptr)); 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);
}
}
} }