summaryrefslogtreecommitdiff
path: root/.config/eww/scripts/volume-listener
blob: 640548d7b9a315191a4b1f6b53a97bc54bfba49e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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