mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(Pulseadio): port icons
This commit is contained in:
@ -36,14 +36,25 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& ev)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string waybar::ALabel::getIcon(uint16_t percentage)
|
||||
std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt)
|
||||
{
|
||||
if (!config_["format-icons"] || !config_["format-icons"].isArray()) {
|
||||
return "";
|
||||
auto format_icons = config_["format-icons"];
|
||||
if (format_icons.isObject()) {
|
||||
if (!alt.empty() && format_icons[alt]) {
|
||||
format_icons = format_icons[alt];
|
||||
} else {
|
||||
format_icons = format_icons["default"];
|
||||
}
|
||||
}
|
||||
auto size = config_["format-icons"].size();
|
||||
auto idx = std::clamp(percentage / (100 / size), 0U, size - 1);
|
||||
return config_["format-icons"][idx].asString();
|
||||
if (format_icons.isArray()) {
|
||||
auto size = format_icons.size();
|
||||
auto idx = std::clamp(percentage / (100 / size), 0U, size - 1);
|
||||
format_icons = format_icons[idx];
|
||||
}
|
||||
if (format_icons.isString()) {
|
||||
return format_icons.asString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
waybar::ALabel::operator Gtk::Widget &() {
|
||||
|
@ -89,6 +89,7 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context* /*context*/,
|
||||
pa->volume_ = volume * 100.0f;
|
||||
pa->muted_ = i->mute != 0;
|
||||
pa->desc_ = i->description;
|
||||
pa->port_name_ = i->active_port->name;
|
||||
pa->dp.emit();
|
||||
}
|
||||
}
|
||||
@ -104,6 +105,27 @@ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context,
|
||||
sinkInfoCb, data);
|
||||
}
|
||||
|
||||
const std::string waybar::modules::Pulseaudio::getPortIcon() const
|
||||
{
|
||||
std::vector<std::string> ports = {
|
||||
"headphones",
|
||||
"speaker",
|
||||
"hdmi",
|
||||
"headset",
|
||||
"handsfree",
|
||||
"portable",
|
||||
"car",
|
||||
"hifi",
|
||||
"phone",
|
||||
};
|
||||
for (auto port : ports) {
|
||||
if (port_name_.find(port) != std::string::npos) {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
auto waybar::modules::Pulseaudio::update() -> void
|
||||
{
|
||||
auto format = format_;
|
||||
@ -111,11 +133,16 @@ auto waybar::modules::Pulseaudio::update() -> void
|
||||
format =
|
||||
config_["format-muted"] ? config_["format-muted"].asString() : format;
|
||||
label_.get_style_context()->add_class("muted");
|
||||
} else if (port_name_.find("a2dp_sink") != std::string::npos) {
|
||||
format = config_["format-bluetooth"]
|
||||
? config_["format-bluetooth"].asString() : format;
|
||||
label_.get_style_context()->add_class("bluetooth");
|
||||
} else {
|
||||
label_.get_style_context()->remove_class("muted");
|
||||
label_.get_style_context()->add_class("bluetooth");
|
||||
}
|
||||
label_.set_label(fmt::format(format,
|
||||
fmt::arg("volume", volume_),
|
||||
fmt::arg("icon", getIcon(volume_))));
|
||||
fmt::arg("icon", getIcon(volume_, getPortIcon()))));
|
||||
label_.set_tooltip_text(desc_);
|
||||
}
|
||||
|
Reference in New Issue
Block a user