mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-16 16:02:39 +02:00
cpu module: Reuse getCpuFrequency of cpu_frequency module
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "modules/cpu.hpp"
|
||||
#include "modules/cpu_frequency.hpp"
|
||||
|
||||
// In the 80000 version of fmt library authors decided to optimize imports
|
||||
// and moved declarations required for fmt::dynamic_format_arg_store in new
|
||||
@@ -21,7 +22,7 @@ auto waybar::modules::Cpu::update() -> void {
|
||||
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
|
||||
auto cpu_load = getCpuLoad();
|
||||
auto [cpu_usage, tooltip] = getCpuUsage();
|
||||
auto [max_frequency, min_frequency, avg_frequency] = getCpuFrequency();
|
||||
auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency();
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(tooltip);
|
||||
}
|
||||
@@ -90,20 +91,3 @@ std::tuple<std::vector<uint16_t>, std::string> waybar::modules::Cpu::getCpuUsage
|
||||
prev_times_ = curr_times;
|
||||
return {usage, tooltip};
|
||||
}
|
||||
|
||||
std::tuple<float, float, float> waybar::modules::Cpu::getCpuFrequency() {
|
||||
std::vector<float> frequencies = parseCpuFrequencies();
|
||||
if (frequencies.empty()) {
|
||||
return {0.f, 0.f, 0.f};
|
||||
}
|
||||
auto [min, max] = std::minmax_element(std::begin(frequencies), std::end(frequencies));
|
||||
float avg_frequency =
|
||||
std::accumulate(std::begin(frequencies), std::end(frequencies), 0.0) / frequencies.size();
|
||||
|
||||
// Round frequencies with double decimal precision to get GHz
|
||||
float max_frequency = std::ceil(*max / 10.0) / 100.0;
|
||||
float min_frequency = std::ceil(*min / 10.0) / 100.0;
|
||||
avg_frequency = std::ceil(avg_frequency / 10.0) / 100.0;
|
||||
|
||||
return {max_frequency, min_frequency, avg_frequency};
|
||||
}
|
||||
|
Reference in New Issue
Block a user