waybar/src/modules/cpu.cpp

26 lines
534 B
C++
Raw Normal View History

2018-08-09 01:54:33 +02:00
#include "modules/cpu.hpp"
#include <iostream>
waybar::modules::Cpu::Cpu()
{
2018-08-09 10:50:16 +02:00
_label.get_style_context()->add_class("cpu");
2018-08-09 01:54:33 +02:00
_thread = [this] {
2018-08-09 12:05:48 +02:00
update();
2018-08-09 10:50:16 +02:00
_thread.sleep_for(chrono::seconds(10));
2018-08-09 01:54:33 +02:00
};
};
2018-08-09 12:05:48 +02:00
auto waybar::modules::Cpu::update() -> void
{
struct sysinfo info;
if (!sysinfo(&info)) {
float f_load = 1.f / (1 << SI_LOAD_SHIFT);
_label.set_text(fmt::format("{:.{}f}% ",
info.loads[0] * f_load * 100 / get_nprocs(), 0));
}
}
2018-08-09 01:54:33 +02:00
waybar::modules::Cpu::operator Gtk::Widget &() {
return _label;
}