feat: cpu module

This commit is contained in:
Alexis
2018-08-09 01:54:33 +02:00
parent 17fc77cb5e
commit d5bfc754c6
5 changed files with 58 additions and 11 deletions

View File

@ -8,6 +8,7 @@
#include "modules/workspaces.hpp"
#include "modules/battery.hpp"
#include "modules/memory.hpp"
#include "modules/cpu.hpp"
static void handle_geometry(void *data, struct wl_output *wl_output, int32_t x,
int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel,
@ -149,10 +150,12 @@ auto waybar::Bar::setup_widgets() -> void
auto &workspace_selector = *new waybar::modules::WorkspaceSelector(*this);
auto &battery = *new waybar::modules::Battery();
auto &memory = *new waybar::modules::Memory();
auto &cpu = *new waybar::modules::Cpu();
left.pack_start(workspace_selector, false, true, 0);
// center.pack_start(workspace_selector, true, false, 10);
right.pack_end(clock, false, false, 0);
right.pack_end(battery, false, false, 0);
right.pack_end(memory, false, false, 0);
right.pack_end(cpu, false, false, 0);
}

20
src/modules/cpu.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "modules/cpu.hpp"
#include <iostream>
waybar::modules::Cpu::Cpu()
{
_label.get_style_context()->add_class("cpu-widget");
_thread = [this] {
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(), 1));
}
_thread.sleep_for(chrono::seconds(30));
};
};
waybar::modules::Cpu::operator Gtk::Widget &() {
return _label;
}