refactor(modules): migrate state modules to ALabel tooltip helper
Migrate cpu, cpu_usage, cpu_frequency and memory to the generic updateLabelAndTooltip/ForState helper so label and tooltip rendering go through the dedup-aware setters and shared tooltip-format resolution. Add store-accepting overloads of the helper to ALabel for modules that build a dynamic fmt argument store (per-core cpu stats). cpu keeps its tooltip-format-<state> selection via the state overload; the others keep their existing tooltip-format-only behavior.
This commit is contained in:
@@ -32,24 +32,12 @@ auto waybar::modules::CpuFrequency::update() -> void {
|
||||
} else {
|
||||
event_box_.show();
|
||||
auto icons = std::vector<std::string>{state};
|
||||
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
||||
store.push_back(fmt::arg("icon", getIcon(avg_frequency, icons)));
|
||||
store.push_back(fmt::arg("max_frequency", max_frequency));
|
||||
store.push_back(fmt::arg("min_frequency", min_frequency));
|
||||
store.push_back(fmt::arg("avg_frequency", avg_frequency));
|
||||
label_.set_markup(fmt::vformat(format, store));
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
std::string tooltip;
|
||||
if (config_["tooltip-format"].isString()) {
|
||||
tooltip = config_["tooltip-format"].asString();
|
||||
label_.set_tooltip_markup(fmt::vformat(tooltip, store));
|
||||
} else {
|
||||
tooltip = "Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n";
|
||||
label_.set_tooltip_markup(
|
||||
fmt::format(fmt::runtime(tooltip), min_frequency, avg_frequency, max_frequency));
|
||||
}
|
||||
}
|
||||
updateLabelAndTooltip(
|
||||
format,
|
||||
"Minimum frequency: {min_frequency}\nAverage frequency: {avg_frequency}\nMaximum "
|
||||
"frequency: {max_frequency}\n",
|
||||
fmt::arg("icon", getIcon(avg_frequency, icons)), fmt::arg("max_frequency", max_frequency),
|
||||
fmt::arg("min_frequency", min_frequency), fmt::arg("avg_frequency", avg_frequency));
|
||||
}
|
||||
|
||||
// Call parent update
|
||||
|
||||
Reference in New Issue
Block a user