voidrice/.local/bin/statusbar/sb-volume

40 lines
956 B
Text
Raw Normal View History

#!/bin/sh
2019-11-23 21:23:24 +00:00
# Prints the current volume or 🔇 if muted.
2020-04-09 21:03:51 +00:00
2019-11-23 21:23:24 +00:00
case $BLOCK_BUTTON in
1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" ;;
2023-01-15 05:26:57 +00:00
2) wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
4) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+ ;;
5) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%- ;;
3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted.
2019-11-23 21:23:24 +00:00
- Middle click to mute.
- Scroll to change." ;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
2019-11-23 21:23:24 +00:00
esac
2022-10-02 19:25:29 +00:00
vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)"
2019-11-23 21:23:24 +00:00
2022-10-02 19:25:29 +00:00
# If muted, print 🔇 and exit.
[ "$vol" != "${vol%\[MUTED\]}" ] && echo 🔇 && exit
2019-11-23 21:23:24 +00:00
2022-10-02 19:25:29 +00:00
vol="${vol#Volume: }"
2022-10-02 19:25:29 +00:00
split() {
# For ommiting the . without calling and external program.
IFS=$2
set -- $1
printf '%s' "$@"
}
vol="$(printf "%.0f" "$(split "$vol" ".")")"
2022-10-02 19:25:29 +00:00
case 1 in
$((vol >= 70)) ) icon="🔊" ;;
$((vol >= 30)) ) icon="🔉" ;;
$((vol >= 1)) ) icon="🔈" ;;
* ) echo 🔇 && exit ;;
esac
2019-11-23 21:23:24 +00:00
2021-10-18 12:50:15 +00:00
echo "$icon$vol%"