feat(cpu): add {icons} format replacement for all per-core icons
Concatenates all per-core icons into a single {icons} placeholder,
so configs work across machines with different core counts without
manually specifying {icon0}{icon1}...{iconN}.
Closes #4240
This commit is contained in:
@@ -106,6 +106,8 @@ The *cpu* module displays the current CPU utilization.
|
|||||||
|
|
||||||
*{icon*{n}*}*: Icon for CPU core n usage. Use like {icon0}.
|
*{icon*{n}*}*: Icon for CPU core n usage. Use like {icon0}.
|
||||||
|
|
||||||
|
*{icon0}{icon1}{icon2}{icon3}*: All per-core icons concatenated. Equivalent to {icon0}{icon1}...{icon*N*} but adapts to the number of cores automatically.
|
||||||
|
|
||||||
# EXAMPLES
|
# EXAMPLES
|
||||||
|
|
||||||
Basic configuration:
|
Basic configuration:
|
||||||
@@ -128,6 +130,16 @@ CPU usage per core rendered as icons:
|
|||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Automatically determine number of icons according to number of logical cores:
|
||||||
|
|
||||||
|
```
|
||||||
|
"cpu": {
|
||||||
|
"interval": 1,
|
||||||
|
"format": "{icons} {usage:>2}% ",
|
||||||
|
"format-icons": ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"],
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
# STYLE
|
# STYLE
|
||||||
|
|
||||||
- *#cpu*
|
- *#cpu*
|
||||||
|
|||||||
+5
-1
@@ -48,13 +48,17 @@ auto waybar::modules::Cpu::update() -> void {
|
|||||||
store.push_back(fmt::arg("avg_frequency", avg_frequency));
|
store.push_back(fmt::arg("avg_frequency", avg_frequency));
|
||||||
std::vector<std::string> arg_names;
|
std::vector<std::string> arg_names;
|
||||||
arg_names.reserve(cpu_usage.size() * 2);
|
arg_names.reserve(cpu_usage.size() * 2);
|
||||||
|
std::string all_icons;
|
||||||
for (size_t i = 1; i < cpu_usage.size(); ++i) {
|
for (size_t i = 1; i < cpu_usage.size(); ++i) {
|
||||||
auto core_i = i - 1;
|
auto core_i = i - 1;
|
||||||
arg_names.push_back(fmt::format("usage{}", core_i));
|
arg_names.push_back(fmt::format("usage{}", core_i));
|
||||||
store.push_back(fmt::arg(arg_names.back().c_str(), cpu_usage[i]));
|
store.push_back(fmt::arg(arg_names.back().c_str(), cpu_usage[i]));
|
||||||
|
auto core_icon = getIcon(cpu_usage[i], icons);
|
||||||
|
all_icons += core_icon;
|
||||||
arg_names.push_back(fmt::format("icon{}", core_i));
|
arg_names.push_back(fmt::format("icon{}", core_i));
|
||||||
store.push_back(fmt::arg(arg_names.back().c_str(), getIcon(cpu_usage[i], icons)));
|
store.push_back(fmt::arg(arg_names.back().c_str(), core_icon));
|
||||||
}
|
}
|
||||||
|
store.push_back(fmt::arg("icons", all_icons));
|
||||||
label_.set_markup(fmt::vformat(format, store));
|
label_.set_markup(fmt::vformat(format, store));
|
||||||
|
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
|
|||||||
@@ -38,13 +38,17 @@ auto waybar::modules::CpuUsage::update() -> void {
|
|||||||
store.push_back(fmt::arg("icon", getIcon(total_usage, icons)));
|
store.push_back(fmt::arg("icon", getIcon(total_usage, icons)));
|
||||||
std::vector<std::string> arg_names;
|
std::vector<std::string> arg_names;
|
||||||
arg_names.reserve(cpu_usage.size() * 2);
|
arg_names.reserve(cpu_usage.size() * 2);
|
||||||
|
std::string all_icons;
|
||||||
for (size_t i = 1; i < cpu_usage.size(); ++i) {
|
for (size_t i = 1; i < cpu_usage.size(); ++i) {
|
||||||
auto core_i = i - 1;
|
auto core_i = i - 1;
|
||||||
arg_names.push_back(fmt::format("usage{}", core_i));
|
arg_names.push_back(fmt::format("usage{}", core_i));
|
||||||
store.push_back(fmt::arg(arg_names.back().c_str(), cpu_usage[i]));
|
store.push_back(fmt::arg(arg_names.back().c_str(), cpu_usage[i]));
|
||||||
|
auto core_icon = getIcon(cpu_usage[i], icons);
|
||||||
|
all_icons += core_icon;
|
||||||
arg_names.push_back(fmt::format("icon{}", core_i));
|
arg_names.push_back(fmt::format("icon{}", core_i));
|
||||||
store.push_back(fmt::arg(arg_names.back().c_str(), getIcon(cpu_usage[i], icons)));
|
store.push_back(fmt::arg(arg_names.back().c_str(), core_icon));
|
||||||
}
|
}
|
||||||
|
store.push_back(fmt::arg("icons", all_icons));
|
||||||
label_.set_markup(fmt::vformat(format, store));
|
label_.set_markup(fmt::vformat(format, store));
|
||||||
|
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user