diff --git a/resources/config b/resources/config index 5fe80ed4..fa9d1b41 100644 --- a/resources/config +++ b/resources/config @@ -38,6 +38,8 @@ "spacing": 10 }, "clock": { + "tooltip": true, + "tooltip-format": "{:%Y-%m-%d | %H:%S}" "format-alt": "{:%Y-%m-%d}" }, "cpu": { diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 223b942b..c7e794fa 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -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_; } diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 85bcd5f8..ac85c4cc 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -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); + } + } }