waybar/src/modules/memory.cpp

20 lines
484 B
C++
Raw Normal View History

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