mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Style code (#25)
This commit is contained in:
@ -1,27 +1,27 @@
|
||||
#include "modules/cpu.hpp"
|
||||
|
||||
waybar::modules::Cpu::Cpu(Json::Value config)
|
||||
: _config(config)
|
||||
: config_(std::move(config))
|
||||
{
|
||||
_label.set_name("cpu");
|
||||
int interval = _config["interval"] ? _config["inveral"].asInt() : 10;
|
||||
_thread = [this, interval] {
|
||||
label_.set_name("cpu");
|
||||
uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 10;
|
||||
thread_ = [this, interval] {
|
||||
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Cpu::update));
|
||||
_thread.sleep_for(chrono::seconds(interval));
|
||||
thread_.sleep_for(chrono::seconds(interval));
|
||||
};
|
||||
};
|
||||
|
||||
auto waybar::modules::Cpu::update() -> void
|
||||
{
|
||||
struct sysinfo info;
|
||||
if (!sysinfo(&info)) {
|
||||
float f_load = 1.f / (1 << SI_LOAD_SHIFT);
|
||||
int load = info.loads[0] * f_load * 100 / get_nprocs();
|
||||
auto format = _config["format"] ? _config["format"].asString() : "{}%";
|
||||
_label.set_text(fmt::format(format, load));
|
||||
struct sysinfo info = {};
|
||||
if (sysinfo(&info) == 0) {
|
||||
float f_load = 1.f / (1U << SI_LOAD_SHIFT);
|
||||
uint16_t load = info.loads[0] * f_load * 100 / get_nprocs();
|
||||
auto format = config_["format"] ? config_["format"].asString() : "{}%";
|
||||
label_.set_text(fmt::format(format, load));
|
||||
}
|
||||
}
|
||||
|
||||
waybar::modules::Cpu::operator Gtk::Widget &() {
|
||||
return _label;
|
||||
return label_;
|
||||
}
|
||||
|
Reference in New Issue
Block a user