From 98060310c60abace73d44437ee866ea0ba4d250d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Pla=C3=A7ais?= Date: Thu, 9 Aug 2018 21:14:20 +0200 Subject: [PATCH 1/2] Fix formula used to compute RAM used and available --- src/modules/memory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index c71a58fc..b29e3c58 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -16,10 +16,10 @@ auto waybar::modules::Memory::update() -> void { struct sysinfo info; if (!sysinfo(&info)) { - int available = ((double)info.freeram / (double)info.totalram) * 100; + int available = 100 - ((double)info.freeram / (double)info.totalram) * 100; auto format = _config["format"] ? _config["format"].asString() : "{}%"; _label.set_text(fmt::format(format, available)); - auto used = (info.totalram - (info.totalram - info.freeram)) / std::pow(1024, 3); + auto used = (info.totalram - info.freeram) / std::pow(1024, 3); _label.set_tooltip_text(fmt::format("{:.{}f}Gb used", used, 1)); } } From 7d3c0b0bb97d1fe66069114f8fb00cbd5b20c825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Pla=C3=A7ais?= Date: Thu, 9 Aug 2018 21:47:28 +0200 Subject: [PATCH 2/2] Clarify variable names and percentage formula in memory module --- src/modules/memory.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index b29e3c58..17df1507 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -16,11 +16,11 @@ auto waybar::modules::Memory::update() -> void { struct sysinfo info; if (!sysinfo(&info)) { - int available = 100 - ((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() : "{}%"; - _label.set_text(fmt::format(format, available)); - auto used = (info.totalram - info.freeram) / std::pow(1024, 3); - _label.set_tooltip_text(fmt::format("{:.{}f}Gb used", used, 1)); + _label.set_text(fmt::format(format, used_ram_percentage)); + auto used_ram_gigabytes = (info.totalram - info.freeram) / std::pow(1024, 3); + _label.set_tooltip_text(fmt::format("{:.{}f}Gb used", used_ram_gigabytes, 1)); } }