53 lines
1.5 KiB
Bash
Executable file
53 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# Display audio volume/mute status
|
|
# Depends on signals in sway config for XF86AudioMute, XF86AudioLowerVolume and
|
|
# XF86AudioRaiseVolume
|
|
|
|
. ~/bin/i3blocks/_utils
|
|
|
|
# Get default audio sink volume and mute status
|
|
audio_volume() {
|
|
local wpctl_output
|
|
wpctl_output=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
|
|
local volume
|
|
volume=$(echo "$wpctl_output" | awk '{print $NF * 100}')
|
|
local muted
|
|
muted=$(echo "$wpctl_output" | grep -c '\[MUTED\]')
|
|
|
|
local bg fg icon stat
|
|
|
|
if [[ "$muted" -ge 1 ]]; then
|
|
bg=$mute_bg
|
|
fg=$mute_fg
|
|
stat="$(printf '%.0f' "$volume")%"
|
|
elif [[ $(echo "$volume >= 80" | bc -l) == "1" ]]; then
|
|
bg=$crit_bg
|
|
fg=$crit_fg
|
|
stat="$(printf '%.0f' "$volume")%"
|
|
elif [[ $(echo "$volume >= 65" | bc -l) == "1" ]]; then
|
|
bg=$warn2_bg
|
|
fg=$warn2_fg
|
|
stat="$(printf '%.0f' "$volume")%"
|
|
elif [[ $(echo "$volume >= 50" | bc -l) == "1" ]]; then
|
|
bg=$warn1_bg
|
|
fg=$warn1_fg
|
|
stat="$(printf '%.0f' "$volume")%"
|
|
else
|
|
stat="$(printf '%.0f' "$volume")%"
|
|
fi
|
|
|
|
if [[ -n "$bg" ]]; then
|
|
echo -e "SND <span background=\"$bg\" color=\"$fg\"> $stat </span>\n"
|
|
else
|
|
echo -e "SND $stat \n"
|
|
fi
|
|
}
|
|
|
|
case "$BLOCK_BUTTON" in
|
|
1) wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
|
|
4) wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ --limit 1.0 ;;
|
|
5) wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- ;;
|
|
esac
|
|
|
|
audio_volume
|