cpu: respect tooltip-format-<state> without overwriting it
The tooltip selection block redundantly reassigned tooltip_format to config_["tooltip-format"], overwriting the state-specific format (and emptying it when no global tooltip-format was set). A lone tooltip-format-<state> therefore produced an empty tooltip. Consolidate the tooltip handling into a single block that prefers tooltip-format-<state>, falls back to the global tooltip-format, then to the computed default tooltip, reusing the existing format arg store.
This commit is contained in:
+8
-39
@@ -28,15 +28,11 @@ auto waybar::modules::Cpu::update() -> void {
|
|||||||
auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency();
|
auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency();
|
||||||
|
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
std::string tooltip_format;
|
|
||||||
auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0];
|
auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0];
|
||||||
auto state = getState(total_usage);
|
auto state = getState(total_usage);
|
||||||
if (!state.empty() && config_["format-" + state].isString()) {
|
if (!state.empty() && config_["format-" + state].isString()) {
|
||||||
format = config_["format-" + state].asString();
|
format = config_["format-" + state].asString();
|
||||||
}
|
}
|
||||||
if (config_["tooltip-format-" + state].isString()) {
|
|
||||||
tooltip_format = config_["tooltip-format-" + state].asString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (format.empty()) {
|
if (format.empty()) {
|
||||||
event_box_.hide();
|
event_box_.hide();
|
||||||
@@ -62,47 +58,20 @@ auto waybar::modules::Cpu::update() -> void {
|
|||||||
label_.set_markup(fmt::vformat(format, store));
|
label_.set_markup(fmt::vformat(format, store));
|
||||||
|
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
if (config_["tooltip-format"].isString()) {
|
std::string tooltip_format;
|
||||||
tooltip = config_["tooltip-format"].asString();
|
if (!state.empty() && config_["tooltip-format-" + state].isString()) {
|
||||||
label_.set_tooltip_markup(fmt::vformat(tooltip, store));
|
tooltip_format = config_["tooltip-format-" + state].asString();
|
||||||
|
} else if (config_["tooltip-format"].isString()) {
|
||||||
|
tooltip_format = config_["tooltip-format"].asString();
|
||||||
|
}
|
||||||
|
if (!tooltip_format.empty()) {
|
||||||
|
label_.set_tooltip_markup(fmt::vformat(tooltip_format, store));
|
||||||
} else {
|
} else {
|
||||||
label_.set_tooltip_markup(tooltip);
|
label_.set_tooltip_markup(tooltip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tooltipEnabled()) {
|
|
||||||
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
|
|
||||||
tooltip_format = config_["tooltip-format"].asString();
|
|
||||||
}
|
|
||||||
if (!tooltip_format.empty()) {
|
|
||||||
tooltip_format = config_["tooltip-format"].asString();
|
|
||||||
|
|
||||||
auto icons = std::vector<std::string>{state};
|
|
||||||
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
|
||||||
store.push_back(fmt::arg("load", load1));
|
|
||||||
store.push_back(fmt::arg("usage", total_usage));
|
|
||||||
store.push_back(fmt::arg("icon", getIcon(total_usage, 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));
|
|
||||||
for (size_t i = 1; i < cpu_usage.size(); ++i) {
|
|
||||||
auto core_i = i - 1;
|
|
||||||
auto core_format = fmt::format("usage{}", core_i);
|
|
||||||
store.push_back(fmt::arg(core_format.c_str(), cpu_usage[i]));
|
|
||||||
auto icon_format = fmt::format("icon{}", core_i);
|
|
||||||
store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons)));
|
|
||||||
}
|
|
||||||
auto tooltip_text = fmt::vformat(tooltip_format, store);
|
|
||||||
|
|
||||||
if (label_.get_tooltip_text() != tooltip_text) {
|
|
||||||
label_.set_tooltip_markup(tooltip_text);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
label_.set_tooltip_text(tooltip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call parent update
|
// Call parent update
|
||||||
ALabel::update();
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user