-
Notifications
You must be signed in to change notification settings - Fork 3
/
volume.nix
47 lines (43 loc) · 1.19 KB
/
volume.nix
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
37
38
39
40
41
42
43
44
45
46
47
{
writeShellApplication,
bc,
libnotify,
wireplumber,
}:
writeShellApplication {
name = "volume";
text = ''
${wireplumber}/bin/wpctl "$1" "$2" "$3"
current_volume=$(${wireplumber}/bin/wpctl get-volume "$2")
case "''${2,,}" in
*"source"*) type=source ;;
*) type=sink ;;
esac
case "$3" in
*"%+") image=${./assets}/audio-"$type"-increase.svg ;;
*"%-") image=${./assets}/audio-"$type"-decrease.svg ;;
*) image=${./assets}/audio-"$type"-default.svg ;;
esac
value=$(grep -o '[0-9]\.[0-9]*' <<< "$current_volume" || echo 0.0)
value=$(${bc}/bin/bc <<< "scale=0; $value*100/1")
if grep -q MUTED <<< "$current_volume"; then
image=${./assets}/audio-"$type"-mute.svg
fi
if [[ "$value" -gt 100 ]]; then
note=volume-overdrive
indicator_value=$((value - 100))
else
note=volume
indicator_value="$value"
fi
${libnotify}/bin/notify-send \
"Volume" "$value%" \
--transient \
--hint=string:image-path:"$image" \
--hint=int:value:"$indicator_value" \
--hint="string:wired-tag:indicator" \
--hint="string:wired-note:$note" \
--expire-time=1000 \
|| true
'';
}