mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
add power to battery formatter
This commit is contained in:
parent
66e5fda418
commit
3bcf390484
@ -34,7 +34,7 @@ class Battery : public ALabel {
|
|||||||
void refreshBatteries();
|
void refreshBatteries();
|
||||||
void worker();
|
void worker();
|
||||||
const std::string getAdapterStatus(uint8_t capacity) const;
|
const std::string getAdapterStatus(uint8_t capacity) const;
|
||||||
const std::tuple<uint8_t, float, std::string> getInfos();
|
const std::tuple<uint8_t, float, std::string, float> getInfos();
|
||||||
const std::string formatTimeRemaining(float hoursRemaining);
|
const std::string formatTimeRemaining(float hoursRemaining);
|
||||||
|
|
||||||
int global_watch;
|
int global_watch;
|
||||||
|
@ -135,7 +135,7 @@ void waybar::modules::Battery::refreshBatteries() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos() {
|
const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::getInfos() {
|
||||||
std::lock_guard<std::mutex> guard(battery_list_mutex_);
|
std::lock_guard<std::mutex> guard(battery_list_mutex_);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -210,10 +210,10 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
|
|||||||
status = "Full";
|
status = "Full";
|
||||||
}
|
}
|
||||||
|
|
||||||
return {cap, time_remaining, status};
|
return {cap, time_remaining, status, total_power / 1e6};
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::error("Battery: {}", e.what());
|
spdlog::error("Battery: {}", e.what());
|
||||||
return {0, 0, "Unknown"};
|
return {0, 0, "Unknown", 0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::modules::Battery::update() -> void {
|
auto waybar::modules::Battery::update() -> void {
|
||||||
auto [capacity, time_remaining, status] = getInfos();
|
auto [capacity, time_remaining, status, power] = getInfos();
|
||||||
if (status == "Unknown") {
|
if (status == "Unknown") {
|
||||||
status = getAdapterStatus(capacity);
|
status = getAdapterStatus(capacity);
|
||||||
}
|
}
|
||||||
@ -302,6 +302,7 @@ auto waybar::modules::Battery::update() -> void {
|
|||||||
auto icons = std::vector<std::string>{status + "-" + state, status, state};
|
auto icons = std::vector<std::string>{status + "-" + state, status, state};
|
||||||
label_.set_markup(fmt::format(format,
|
label_.set_markup(fmt::format(format,
|
||||||
fmt::arg("capacity", capacity),
|
fmt::arg("capacity", capacity),
|
||||||
|
fmt::arg("power", power),
|
||||||
fmt::arg("icon", getIcon(capacity, icons)),
|
fmt::arg("icon", getIcon(capacity, icons)),
|
||||||
fmt::arg("time", time_remaining_formatted)));
|
fmt::arg("time", time_remaining_formatted)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user