From f6d8c4a0447a7bb56f8717a6f21920bc6d7ba310 Mon Sep 17 00:00:00 2001 From: jkre Date: Wed, 13 Dec 2023 23:58:40 +0100 Subject: [PATCH] use capacity as default for battery percentage, less complicated and matches desktop percent exactly --- src/linux/btop_collect.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 0d58596..3961d91 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -757,7 +757,14 @@ namespace Cpu { long seconds = -1; //? Try to get battery percentage - if (b.use_energy_or_charge) { + if (percent < 0) { + try { + percent = stoll(readfile(b.base_dir / "capacity", "-1")); + } + catch (const std::invalid_argument&) { } + catch (const std::out_of_range&) { } + } + if (b.use_energy_or_charge and percent < 0) { try { percent = round(100.0 * stoll(readfile(b.energy_now, "-1")) / stoll(readfile(b.energy_full, "1"))); } @@ -771,13 +778,6 @@ namespace Cpu { catch (const std::invalid_argument&) { } catch (const std::out_of_range&) { } } - if (percent < 0) { - try { - percent = stoll(readfile(b.base_dir / "capacity", "-1")); - } - catch (const std::invalid_argument&) { } - catch (const std::out_of_range&) { } - } if (percent < 0) { has_battery = false; return {0, 0, ""};