From ab294bfc104d20e1178cb4c6bc4de2fd879cb892 Mon Sep 17 00:00:00 2001 From: jkre Date: Wed, 13 Dec 2023 23:51:18 +0100 Subject: [PATCH] add battery percentage calculation in charge case --- src/linux/btop_collect.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index ae11f61..0d58596 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -764,6 +764,13 @@ namespace Cpu { catch (const std::invalid_argument&) { } catch (const std::out_of_range&) { } } + if (b.use_energy_or_charge == true and percent < 0) { + try { + percent = round(100.0 * stoll(readfile(b.charge_now, "-1")) / stoll(readfile(b.charge_full, "1"))); + } + catch (const std::invalid_argument&) { } + catch (const std::out_of_range&) { } + } if (percent < 0) { try { percent = stoll(readfile(b.base_dir / "capacity", "-1"));