mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(battery): capacity icons
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user