Merge pull request #4837 from Cprakhar/fix/format-plugged-gt-format-full
fix: prioritize `plugged` status over `full` when battery is full and plugged in
This commit is contained in:
@@ -27,6 +27,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y
|
|||||||
default: false ++
|
default: false ++
|
||||||
Option to use the battery design capacity instead of its current maximal capacity.
|
Option to use the battery design capacity instead of its current maximal capacity.
|
||||||
|
|
||||||
|
*full-at-plugged*: ++
|
||||||
|
typeof: bool ++
|
||||||
|
default: false ++
|
||||||
|
When enabled, a battery that is *Full* while the adapter is online is reported with the *Plugged* status instead of *Full* (so you can style/format it separately). Disabled by default to preserve the existing *Full* behaviour.
|
||||||
|
|
||||||
*interval*: ++
|
*interval*: ++
|
||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
default: 60 ++
|
default: 60 ++
|
||||||
|
|||||||
@@ -701,13 +701,20 @@ auto waybar::modules::Battery::update() -> void {
|
|||||||
if (status == "Unknown") {
|
if (status == "Unknown") {
|
||||||
status = getAdapterStatus(capacity);
|
status = getAdapterStatus(capacity);
|
||||||
}
|
}
|
||||||
|
auto state = getState(capacity, true);
|
||||||
|
bool adapter_online = false;
|
||||||
|
if (!adapter_.empty()) {
|
||||||
|
std::ifstream(adapter_ / "online") >> adapter_online;
|
||||||
|
}
|
||||||
|
if (config_["full-at-plugged"].asBool() && status == "Full" && adapter_online) {
|
||||||
|
status = "Plugged";
|
||||||
|
}
|
||||||
auto status_pretty = status;
|
auto status_pretty = status;
|
||||||
|
|
||||||
// Transform to lowercase and replace space with dash
|
// Transform to lowercase and replace space with dash
|
||||||
std::ranges::transform(status.begin(), status.end(), status.begin(),
|
std::ranges::transform(status.begin(), status.end(), status.begin(),
|
||||||
[](char ch) { return ch == ' ' ? '-' : std::tolower(ch); });
|
[](char ch) { return ch == ' ' ? '-' : std::tolower(ch); });
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
auto state = getState(capacity, true);
|
|
||||||
processEvents(state, status, capacity);
|
processEvents(state, status, capacity);
|
||||||
setBarClass(state);
|
setBarClass(state);
|
||||||
auto time_remaining_formatted = formatTimeRemaining(time_remaining);
|
auto time_remaining_formatted = formatTimeRemaining(time_remaining);
|
||||||
|
|||||||
Reference in New Issue
Block a user