mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(Cpu): dynamic fmt args
This commit is contained in:
parent
4dd36890c1
commit
2d9bcb1a2d
@ -13,13 +13,20 @@ waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
|
||||
}
|
||||
|
||||
auto waybar::modules::Cpu::update() -> void {
|
||||
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
|
||||
std::vector<fmt::basic_format_arg<fmt::format_context>> args;
|
||||
if (format_.find("{load}") != std::string::npos) {
|
||||
auto cpu_load = getCpuLoad();
|
||||
args.emplace_back(fmt::internal::make_arg<fmt::format_context>(fmt::arg("load", cpu_load)));
|
||||
}
|
||||
if (format_.find("{usage}") != std::string::npos) {
|
||||
auto [cpu_usage, tooltip] = getCpuUsage();
|
||||
args.emplace_back(fmt::internal::make_arg<fmt::format_context>(fmt::arg("usage", cpu_usage)));
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(tooltip);
|
||||
}
|
||||
label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
|
||||
}
|
||||
label_.set_markup(
|
||||
fmt::vformat(format_, fmt::basic_format_args<fmt::format_context>(args.data(), args.size())));
|
||||
}
|
||||
|
||||
uint16_t waybar::modules::Cpu::getCpuLoad() {
|
||||
|
Loading…
Reference in New Issue
Block a user