Skip to content

Commit

Permalink
Merge pull request #2494 from KanuX-14/battery_fix
Browse files Browse the repository at this point in the history
Fix battery not showing for some devices
  • Loading branch information
Alexays committed Sep 19, 2023
2 parents 4d32991 + 28a2d15 commit 9b8adc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions man/waybar-battery.5.scd
Expand Up @@ -100,6 +100,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y
default: true ++
Option to disable tooltip on hover.

*bat-compatibility*: ++
typeof: bool ++
default: false ++
Option to enable battery compatibility if not detected.

# FORMAT REPLACEMENTS

*{capacity}*: Capacity in percentage
Expand Down
12 changes: 10 additions & 2 deletions src/modules/battery.cpp
Expand Up @@ -100,9 +100,11 @@ void waybar::modules::Battery::refreshBatteries() {
}
auto dir_name = node.path().filename();
auto bat_defined = config_["bat"].isString();
bool bat_compatibility = config_["bat-compatibility"].asBool();
if (((bat_defined && dir_name == config_["bat"].asString()) || !bat_defined) &&
(fs::exists(node.path() / "capacity") || fs::exists(node.path() / "charge_now")) &&
fs::exists(node.path() / "uevent") && fs::exists(node.path() / "status") &&
fs::exists(node.path() / "uevent") &&
(fs::exists(node.path() / "status") || bat_compatibility) &&
fs::exists(node.path() / "type")) {
std::string type;
std::ifstream(node.path() / "type") >> type;
Expand Down Expand Up @@ -252,7 +254,13 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
for (auto const& item : batteries_) {
auto bat = item.first;
std::string _status;
std::getline(std::ifstream(bat / "status"), _status);

/* Check for adapter status if battery is not available */
if(!std::ifstream(bat / "status")) {
std::getline(std::ifstream(adapter_ / "status"), _status);
} else {
std::getline(std::ifstream(bat / "status"), _status);
}

// Some battery will report current and charge in μA/μAh.
// Scale these by the voltage to get μW/μWh.
Expand Down

0 comments on commit 9b8adc1

Please sign in to comment.