feat(battery): capacity icons

pull/18/head
Alexis 2018-08-11 13:15:31 +02:00
parent 67fa8bd4c3
commit b381e2a596
3 changed files with 12 additions and 2 deletions

View File

@ -19,6 +19,7 @@ namespace waybar::modules {
auto update() -> void;
operator Gtk::Widget&();
private:
std::string _getIcon(uint32_t percentage);
static inline const fs::path _data_dir = "/sys/class/power_supply/";
std::vector<fs::path> _batteries;
util::SleeperThread _thread;

View File

@ -14,7 +14,8 @@
"format": "{}% "
},
"battery": {
"format": "{}% "
"format": "{value}% {icon}",
"format-icons": ["", "", "", "", ""]
},
"network": {
"interface": "wlp2s0",

View File

@ -44,7 +44,8 @@ auto waybar::modules::Battery::update() -> void
}
auto format = _config["format"] ? _config["format"].asString() : "{}%";
auto value = total / _batteries.size();
_label.set_text(fmt::format(format, value));
_label.set_text(fmt::format(format, fmt::arg("value", value),
fmt::arg("icon", _getIcon(value))));
_label.set_tooltip_text(charging ? "Charging" : "Discharging");
if (charging)
_label.get_style_context()->add_class("charging");
@ -59,6 +60,13 @@ auto waybar::modules::Battery::update() -> void
}
}
std::string waybar::modules::Battery::_getIcon(uint32_t percentage)
{
if (!_config["format-icons"] || !_config["format-icons"].isArray()) return "";
auto step = 100 / _config["format-icons"].size();
return _config["format-icons"][percentage / step].asString();
}
waybar::modules::Battery::operator Gtk::Widget &()
{
return _label;