From 6bf64cd04d153499f85f1a41e5061e98cb108e66 Mon Sep 17 00:00:00 2001 From: RX14 Date: Sun, 19 May 2019 16:10:01 +0100 Subject: [PATCH] Allow formatting memory with used and available memory --- src/modules/memory.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index de5fb24..e0878f8 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -16,9 +16,14 @@ auto waybar::modules::Memory::update() -> void { parseMeminfo(); if (memtotal_ > 0 && memfree_ >= 0) { int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_; - getState(used_ram_percentage); - label_.set_markup(fmt::format(format_, used_ram_percentage)); auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2); + auto available_ram_gigabytes = memfree_ / std::pow(1024, 2); + + getState(used_ram_percentage); + label_.set_markup(fmt::format(format_, used_ram_percentage, + fmt::arg("percentage", used_ram_percentage), + fmt::arg("used", used_ram_gigabytes), + fmt::arg("avail", available_ram_gigabytes))); if (tooltipEnabled()) { label_.set_tooltip_text(fmt::format("{:.{}f}Gb used", used_ram_gigabytes, 1)); }