mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
27 lines
642 B
C++
27 lines
642 B
C++
#include "modules/memory.hpp"
|
|
#include <iostream>
|
|
|
|
waybar::modules::Memory::Memory(Json::Value config)
|
|
: _config(config)
|
|
{
|
|
_label.get_style_context()->add_class("memory");
|
|
_thread = [this] {
|
|
update();
|
|
_thread.sleep_for(chrono::seconds(30));
|
|
};
|
|
};
|
|
|
|
auto waybar::modules::Memory::update() -> void
|
|
{
|
|
struct sysinfo info;
|
|
if (!sysinfo(&info)) {
|
|
int available = ((double)info.freeram / (double)info.totalram) * 100;
|
|
auto format = _config["format"] ? _config["format"].asString() : "{}%";
|
|
_label.set_text(fmt::format(format, available));
|
|
}
|
|
}
|
|
|
|
waybar::modules::Memory::operator Gtk::Widget &() {
|
|
return _label;
|
|
}
|