From 2fa581c7eaf5a8c44d322365a82ef0e2d538b269 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 22 May 2019 10:06:54 +0200 Subject: [PATCH] fix(battery): multiple paths --- resources/config | 1 + src/modules/battery.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/resources/config b/resources/config index a62f7c43..f4ec2ff2 100644 --- a/resources/config +++ b/resources/config @@ -96,6 +96,7 @@ "format": "{capacity}% {icon}", "format-charging": "{capacity}% ", "format-plugged": "{capacity}% ", + "format-alt": "{time} {icon}", // "format-good": "", // An empty format will hide the module // "format-full": "", "format-icons": ["", "", "", "", ""] diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index bd287d49..09e82a62 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -91,9 +91,12 @@ const std::tuple waybar::modules::Battery::getInfos std::string _status; std::ifstream(bat / "capacity") >> capacity; std::ifstream(bat / "status") >> _status; - std::ifstream(bat / "power_now") >> power_now; - std::ifstream(bat / "energy_now") >> energy_now; - std::ifstream(bat / "energy_full") >> energy_full; + auto rate_path = fs::exists(bat / "current_now") ? "current_now" : "power_now"; + std::ifstream(bat / rate_path) >> power_now; + auto now_path = fs::exists(bat / "charge_now") ? "charge_now" : "energy_now"; + std::ifstream(bat / now_path) >> energy_now; + auto full_path = fs::exists(bat / "charge_full") ? "charge_full" : "energy_full"; + std::ifstream(bat / full_path) >> energy_full; if (_status != "Unknown") { status = _status; }