Merge pull request #222 from alebastr/pulseaudio-ci-icon-lookup

fix(pulseaudio) use case-insensitive comparison for icon lookup
This commit is contained in:
Alex 2019-03-15 09:43:02 +01:00 committed by GitHub
commit 3257968a28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 12 deletions

View File

@ -1,4 +1,5 @@
#include "modules/pulseaudio.hpp" #include "modules/pulseaudio.hpp"
#include <array>
waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value &config) waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value &config)
: ALabel(config, "{volume}%"), : ALabel(config, "{volume}%"),
@ -174,21 +175,24 @@ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context,
sinkInfoCb, data); sinkInfoCb, data);
} }
static const std::array<std::string, 9> ports = {
"headphones",
"speaker",
"hdmi",
"headset",
"handsfree",
"portable",
"car",
"hifi",
"phone",
};
const std::string waybar::modules::Pulseaudio::getPortIcon() const const std::string waybar::modules::Pulseaudio::getPortIcon() const
{ {
std::vector<std::string> ports = { std::string nameLC = port_name_;
"headphones", std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower);
"speaker",
"hdmi",
"headset",
"handsfree",
"portable",
"car",
"hifi",
"phone",
};
for (auto const& port : ports) { for (auto const& port : ports) {
if (port_name_.find(port) != std::string::npos) { if (nameLC.find(port) != std::string::npos) {
return port; return port;
} }
} }