modules/power_profiles_daemon: add custom format from config

We move to a single icon label format to save space on the bar. We
still display the profile name and the driver in the tooltip.
pull/2971/head
Félix Baylac Jacqué 2024-03-01 11:13:57 +01:00
parent 162b41c4d0
commit 61fed6a214
3 changed files with 30 additions and 2 deletions

View File

@ -32,6 +32,9 @@ class PowerProfilesDaemon : public ALabel {
std::vector<Profile>::iterator activeProfile_;
// Current CSS class applied to the label
std::string currentStyle_;
// Format strings
std::string labelFormat_;
std::string tooltipFormat_;
// DBus Proxy used to track the current active profile
Glib::RefPtr<Gio::DBus::Proxy> powerProfilesProxy_;
sigc::connection powerProfileChangeSignal_;

View File

@ -148,6 +148,17 @@
"battery#bat2": {
"bat": "BAT2"
},
"power_profiles_daemon": {
"format": "{icon}",
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
"tooltip": true,
"format-icons": {
"default": "",
"performance": "",
"balanced": "",
"power-saver": ""
}
},
"network": {
// "interface": "wlp2*", // (Optional) To force the use of this interface
"format-wifi": "{essid} ({signalStrength}%) ",

View File

@ -17,6 +17,18 @@ namespace waybar::modules {
PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Value& config)
: ALabel(config, "power-profiles-daemon", id, "{profile}", 0, false, true) {
if (config_["format"].isString()) {
format_ = config_["format"].asString();
} else {
format_ = "{icon}";
}
if (config_["tooltip-format"].isString()) {
tooltipFormat_ = config_["tooltip-format"].asString();
} else {
tooltipFormat_ = "Power profile: {profile}\nDriver: {driver}";
}
// NOTE: the DBus adresses are under migration. They should be
// changed to org.freedesktop.UPower.PowerProfiles at some point.
//
@ -110,9 +122,11 @@ auto PowerProfilesDaemon::update() -> void {
// Set label
fmt::dynamic_format_arg_store<fmt::format_context> store;
store.push_back(fmt::arg("profile", profile.name));
label_.set_markup(fmt::vformat("⚡ {profile}", store));
store.push_back(fmt::arg("driver", profile.driver));
store.push_back(fmt::arg("icon", getIcon(0, profile.name)));
label_.set_markup(fmt::vformat(format_, store));
if (tooltipEnabled()) {
label_.set_tooltip_text(fmt::format("Driver: {}", profile.driver));
label_.set_tooltip_text(fmt::vformat(tooltipFormat_, store));
}
// Set CSS class