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:
parent
67fa8bd4c3
commit
b381e2a596
@ -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;
|
||||
|
@ -14,7 +14,8 @@
|
||||
"format": "{}% "
|
||||
},
|
||||
"battery": {
|
||||
"format": "{}% "
|
||||
"format": "{value}% {icon}",
|
||||
"format-icons": ["", "", "", "", ""]
|
||||
},
|
||||
"network": {
|
||||
"interface": "wlp2s0",
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user