From 492d151079430f9c5df23a848bfb04533df1a46c Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Thu, 14 Mar 2019 18:08:12 -0700 Subject: [PATCH 1/2] fix(pulseaudio) use case-insensitive comparison for icon lookup --- src/modules/pulseaudio.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 0e82ead..e287213 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -187,8 +187,10 @@ const std::string waybar::modules::Pulseaudio::getPortIcon() const "hifi", "phone", }; + std::string nameLC = port_name_; + std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); for (auto const& port : ports) { - if (port_name_.find(port) != std::string::npos) { + if (nameLC.find(port) != std::string::npos) { return port; } } From 9ad80849b1ced209c8075ddcc14e236953836937 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Thu, 14 Mar 2019 18:35:16 -0700 Subject: [PATCH 2/2] fix(pulseaudio): Avoid allocation of string vector on every call of getPortIcon() --- src/modules/pulseaudio.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index e287213..b5dfe49 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -1,4 +1,5 @@ #include "modules/pulseaudio.hpp" +#include waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value &config) : ALabel(config, "{volume}%"), @@ -174,19 +175,20 @@ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context, sinkInfoCb, data); } +static const std::array ports = { + "headphones", + "speaker", + "hdmi", + "headset", + "handsfree", + "portable", + "car", + "hifi", + "phone", +}; + const std::string waybar::modules::Pulseaudio::getPortIcon() const { - std::vector ports = { - "headphones", - "speaker", - "hdmi", - "headset", - "handsfree", - "portable", - "car", - "hifi", - "phone", - }; std::string nameLC = port_name_; std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); for (auto const& port : ports) {