Skip to content

Commit

Permalink
Merge pull request #3353 from locked-out/muted_icons
Browse files Browse the repository at this point in the history
Support for muted icons for pulseaudio devices/ports
  • Loading branch information
Alexays committed Jun 13, 2024
2 parents 0bc43c1 + 01438f7 commit 79a6229
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions man/waybar-pulseaudio.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ If they are found in the current PulseAudio port name, the corresponding icons w
- *hifi*
- *phone*

Additionally, suffixing a device name or port with *-muted* will cause the icon
to be selected when the corresponding audio device is muted. This applies to *default* as well.

# EXAMPLES

Expand All @@ -152,10 +154,12 @@ If they are found in the current PulseAudio port name, the corresponding icons w
"format-muted": "",
"format-icons": {
"alsa_output.pci-0000_00_1f.3.analog-stereo": "",
"alsa_output.pci-0000_00_1f.3.analog-stereo-muted": "",
"headphones": "",
"handsfree": "",
"headset": "",
"phone": "",
"phone-muted": "",
"portable": "",
"car": "",
"default": ["", ""]
Expand Down
16 changes: 14 additions & 2 deletions src/modules/pulseaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,27 @@ static const std::array<std::string, 9> ports = {
};

const std::vector<std::string> waybar::modules::Pulseaudio::getPulseIcon() const {
std::vector<std::string> res = {backend->getCurrentSinkName(), backend->getDefaultSourceName()};
std::vector<std::string> res;
auto sink_muted = backend->getSinkMuted();
if (sink_muted) {
res.emplace_back(backend->getCurrentSinkName() + "-muted");
}
res.push_back(backend->getCurrentSinkName());
res.push_back(backend->getDefaultSourceName());
std::string nameLC = backend->getSinkPortName() + backend->getFormFactor();
std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower);
for (auto const &port : ports) {
if (nameLC.find(port) != std::string::npos) {
if (sink_muted) {
res.emplace_back(port + "-muted");
}
res.push_back(port);
return res;
break;
}
}
if (sink_muted) {
res.emplace_back("default-muted");
}
return res;
}

Expand Down

0 comments on commit 79a6229

Please sign in to comment.