Merge pull request #4 from Alexays/fix-memory-usage

Fix formula used to compute RAM used and available
pull/7/head
Alex 2018-08-09 22:05:47 +02:00 committed by GitHub
commit 4594f7b456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -16,11 +16,11 @@ auto waybar::modules::Memory::update() -> void
{ {
struct sysinfo info; struct sysinfo info;
if (!sysinfo(&info)) { if (!sysinfo(&info)) {
int available = ((double)info.freeram / (double)info.totalram) * 100; int used_ram_percentage = 100 * (info.totalram - info.freeram) / info.totalram;
auto format = _config["format"] ? _config["format"].asString() : "{}%"; auto format = _config["format"] ? _config["format"].asString() : "{}%";
_label.set_text(fmt::format(format, available)); _label.set_text(fmt::format(format, used_ram_percentage));
auto used = (info.totalram - (info.totalram - info.freeram)) / std::pow(1024, 3); auto used_ram_gigabytes = (info.totalram - info.freeram) / std::pow(1024, 3);
_label.set_tooltip_text(fmt::format("{:.{}f}Gb used", used, 1)); _label.set_tooltip_text(fmt::format("{:.{}f}Gb used", used_ram_gigabytes, 1));
} }
} }