Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pipewire-microphone #440

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion polybar-scripts/pipewire-microphone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ A script for showing and toggling the mute state of the PipeWire default microph
## Dependencies

* pactl (libpulse)
* pw-cat (pipewire)


## Module
Expand Down
23 changes: 5 additions & 18 deletions polybar-scripts/pipewire-microphone/pipewire-microphone.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
#!/bin/sh

get_mic_default() {
pw-cat --record --list-targets | sed -n -E "1 s/^.*: (.*)/\1/p"
pactl info | awk '/Default Source:/ {print $3}'
}

is_mic_muted() {
mic_name="$(get_mic_default)"

pactl list sources | \
awk -v mic_name="${mic_name}" '{
if ($0 ~ "Name: " mic_name) {
matched_mic_name = 1;
} else if (matched_mic_name && /Mute/) {
print $2;
exit;
}
}'
pactl get-source-mute "$(get_mic_default)" | awk '{print $2}'
}

get_mic_status() {
is_muted="$(is_mic_muted)"

if [ "${is_muted}" = "yes" ]; then
if [ "$(is_mic_muted)" = "yes" ]; then
printf "%s\n" "#1"
else
printf "%s\n" "#2"
Expand All @@ -30,9 +18,8 @@ get_mic_status() {

listen() {
get_mic_status

LANG=EN; pactl subscribe | while read -r event; do
if printf "%s\n" "${event}" | grep --quiet "source" || printf "%s\n" "${event}" | grep --quiet "server"; then
if printf "%s\n" "${event}" | grep -qE '(source|server)'; then
get_mic_status
fi
done
Expand All @@ -42,7 +29,7 @@ toggle() {
pactl set-source-mute @DEFAULT_SOURCE@ toggle
}

case "$1" in
case "${1}" in
--toggle)
toggle
;;
Expand Down