summaryrefslogblamecommitdiff
path: root/.config/eww/scripts/volume-listener
blob: 640548d7b9a315191a4b1f6b53a97bc54bfba49e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
         
                                  








                                              
                                                



















                                                                                           
#!/bin/sh

readonly SINK=@DEFAULT_AUDIO_SINK@

stdbuf -oL amixer events \
	| stdbuf -oL sed 's/event value: //' \
	| while IFS= read -r line
	do
		IFS='=,'
		set -- $line
		x=${6#\'}
		x=${x%\'}
		case "$x" in
		'Master Playback'*)
			wpctl get-volume $SINK \
				| awk '
					/MUTED/ {
						print "icon="
						print "percentage=Muted"
						exit
					}
					{
						printf "icon="
						if ($2 < 0.33)
							print ""
						else if ($2 <= 0.66)
							print ""
						else
							print ""
						printf "percentage=%s%d%%\n", pad, $2 * 100
					}
				' \
				| jo
			;;
		esac
	done