Files
Waybar/src/modules/simpleclock.cpp
T
Alex 836449d253 refactor(modules): use ALabel dedup tooltip helper in simpleclock, systemd-failed-units, upower
simpleclock: migrate to updateLabelAndTooltip (label + tooltip share the
localtime arg; default tooltip falls back to the label format).
systemd-failed-units: use setLabelMarkup/setTooltipMarkup dedup setters;
label/tooltip formats are selected by different conditions so the combined
helper does not apply.
upower: use setLabelMarkup for the label; tooltip stays a custom GTK widget.
mpd already uses the dedup setters (label/tooltip use different truncated
args), so no change.
2026-07-04 00:00:17 +02:00

25 lines
783 B
C++

#include "modules/simpleclock.hpp"
#include <time.h>
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
: ALabel(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));
updateLabelAndTooltip(format_, format_, localtime);
// Call parent update
ALabel::update();
}