summaryrefslogtreecommitdiff
path: root/.config/eww/scripts/volume-listener
blob: 9c0368ccec4219b5463154dbdca842bf8f2bd9ce (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
#!/bin/sh

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 @DEFAULT_AUDIO_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