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;
|
auto update() -> void;
|
||||||
operator Gtk::Widget&();
|
operator Gtk::Widget&();
|
||||||
private:
|
private:
|
||||||
|
std::string _getIcon(uint32_t percentage);
|
||||||
static inline const fs::path _data_dir = "/sys/class/power_supply/";
|
static inline const fs::path _data_dir = "/sys/class/power_supply/";
|
||||||
std::vector<fs::path> _batteries;
|
std::vector<fs::path> _batteries;
|
||||||
util::SleeperThread _thread;
|
util::SleeperThread _thread;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
"format": "{}% "
|
"format": "{}% "
|
||||||
},
|
},
|
||||||
"battery": {
|
"battery": {
|
||||||
"format": "{}% "
|
"format": "{value}% {icon}",
|
||||||
|
"format-icons": ["", "", "", "", ""]
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"interface": "wlp2s0",
|
"interface": "wlp2s0",
|
||||||
|
@ -44,7 +44,8 @@ auto waybar::modules::Battery::update() -> void
|
|||||||
}
|
}
|
||||||
auto format = _config["format"] ? _config["format"].asString() : "{}%";
|
auto format = _config["format"] ? _config["format"].asString() : "{}%";
|
||||||
auto value = total / _batteries.size();
|
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");
|
_label.set_tooltip_text(charging ? "Charging" : "Discharging");
|
||||||
if (charging)
|
if (charging)
|
||||||
_label.get_style_context()->add_class("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 &()
|
waybar::modules::Battery::operator Gtk::Widget &()
|
||||||
{
|
{
|
||||||
return _label;
|
return _label;
|
||||||
|
Loading…
Reference in New Issue
Block a user