Waybar/src/modules/memory.cpp

25 lines
540 B
C++
Raw Normal View History

2018-08-08 23:42:52 +00:00
#include "modules/memory.hpp"
#include <iostream>
waybar::modules::Memory::Memory()
{
2018-08-09 08:50:16 +00:00
_label.get_style_context()->add_class("memory");
2018-08-08 23:42:52 +00:00
_thread = [this] {
2018-08-09 10:05:48 +00:00
update();
2018-08-08 23:42:52 +00:00
_thread.sleep_for(chrono::seconds(30));
};
};
2018-08-09 10:05:48 +00:00
auto waybar::modules::Memory::update() -> void
{
struct sysinfo info;
if (!sysinfo(&info)) {
double available = (double)info.freeram / (double)info.totalram;
_label.set_text(fmt::format("{:.{}f}% ", available * 100, 0));
}
}
2018-08-08 23:42:52 +00:00
waybar::modules::Memory::operator Gtk::Widget &() {
return _label;
}