mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
2b735f44bc
Mouse-over tooltips set on the label only appear once the mouse hovers over exactly the label. Other apps (e.g. firefox) show the tooltip once the pointer hovers the button. Not solely its label. With this commit we get the same behaviour.
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
#include "modules/simpleclock.hpp"
|
|
|
|
#include <time.h>
|
|
|
|
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
|
: AButton(config, "clock", id, "{:%H:%M}", 60) {
|
|
thread_ = [this] {
|
|
dp.emit();
|
|
auto now = std::chrono::system_clock::now();
|
|
/* difference with projected wakeup time */
|
|
auto diff = now.time_since_epoch() % interval_;
|
|
/* sleep until the next projected time */
|
|
thread_.sleep_for(interval_ - diff);
|
|
};
|
|
}
|
|
|
|
auto waybar::modules::Clock::update() -> void {
|
|
tzset(); // Update timezone information
|
|
auto now = std::chrono::system_clock::now();
|
|
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
|
|
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);
|
|
button_.set_tooltip_text(tooltip_text);
|
|
} else {
|
|
button_.set_tooltip_text(text);
|
|
}
|
|
}
|
|
// Call parent update
|
|
AButton::update();
|
|
}
|