mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #996 from martin2250/master
add power formatter to battery module
This commit is contained in:
commit
69a366dced
@ -31,11 +31,11 @@ class Battery : public ALabel {
|
||||
private:
|
||||
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
|
||||
|
||||
void refreshBatteries();
|
||||
void worker();
|
||||
const std::string getAdapterStatus(uint8_t capacity) const;
|
||||
const std::tuple<uint8_t, float, std::string> getInfos();
|
||||
const std::string formatTimeRemaining(float hoursRemaining);
|
||||
void refreshBatteries();
|
||||
void worker();
|
||||
const std::string getAdapterStatus(uint8_t capacity) const;
|
||||
const std::tuple<uint8_t, float, std::string, float> getInfos();
|
||||
const std::string formatTimeRemaining(float hoursRemaining);
|
||||
|
||||
int global_watch;
|
||||
std::map<fs::path,int> batteries_;
|
||||
|
@ -96,6 +96,8 @@ The *battery* module displays the current capacity and state (eg. charging) of y
|
||||
|
||||
*{capacity}*: Capacity in percentage
|
||||
|
||||
*{power}*: Power in watts
|
||||
|
||||
*{icon}*: Icon, as defined in *format-icons*.
|
||||
|
||||
*{time}*: Estimate of time until full or empty. Note that this is based on the power draw at the last refresh time, not an average.
|
||||
|
@ -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_);
|
||||
|
||||
try {
|
||||
@ -210,10 +210,10 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
|
||||
status = "Full";
|
||||
}
|
||||
|
||||
return {cap, time_remaining, status};
|
||||
return {cap, time_remaining, status, total_power / 1e6};
|
||||
} catch (const std::exception& e) {
|
||||
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 [capacity, time_remaining, status] = getInfos();
|
||||
auto [capacity, time_remaining, status, power] = getInfos();
|
||||
if (status == "Unknown") {
|
||||
status = getAdapterStatus(capacity);
|
||||
}
|
||||
@ -302,6 +302,7 @@ auto waybar::modules::Battery::update() -> void {
|
||||
auto icons = std::vector<std::string>{status + "-" + state, status, state};
|
||||
label_.set_markup(fmt::format(format,
|
||||
fmt::arg("capacity", capacity),
|
||||
fmt::arg("power", power),
|
||||
fmt::arg("icon", getIcon(capacity, icons)),
|
||||
fmt::arg("time", time_remaining_formatted)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user