aboutsummaryrefslogtreecommitdiff
path: root/.config/yambar/scripts/volumecontrol
diff options
context:
space:
mode:
authorJustine Smithies <justine@smithies.me.uk>2024-05-10 19:47:01 +0100
committerJustine Smithies <justine@smithies.me.uk>2024-05-10 19:47:01 +0100
commitfb3afe0023747f7f7f8f85dfa0a38baf61cbfb71 (patch)
tree64dec010d085f29c41edec127e9f230a5f521cca /.config/yambar/scripts/volumecontrol
parent14f12f5974394861430ed7f324552266156f7580 (diff)
Updated to use pactl and --hint=string:x-canonical-private-synchronous:
Diffstat (limited to '.config/yambar/scripts/volumecontrol')
-rwxr-xr-x.config/yambar/scripts/volumecontrol81
1 files changed, 48 insertions, 33 deletions
diff --git a/.config/yambar/scripts/volumecontrol b/.config/yambar/scripts/volumecontrol
index 65b0082..60a5b83 100755
--- a/.config/yambar/scripts/volumecontrol
+++ b/.config/yambar/scripts/volumecontrol
@@ -6,64 +6,79 @@
# volumecontrol mute
function get_volume {
- amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
+ # amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
+ pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n 1
}
function is_mute {
- amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
+ # amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
+ pactl get-sink-mute @DEFAULT_SINK@ | grep 'Mute: yes' >> /dev/null
}
function send_notification {
volume=$(get_volume)
# Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character
-if [ "$volume" = "0" ]; then
- icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-muted.png"
-notify-send -i "$icon_name" -r 5556 -u normal "$volume"
- else
- if [ "$volume" -lt "10" ]; then
- icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-low.png"
-notify-send -i "$icon_name" -r 5556 -u normal "$volume"
- else
- if [ "$volume" -lt "30" ]; then
- icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-low.png"
- else
- if [ "$volume" -lt "70" ]; then
- icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-medium.png"
- else
- icon_name="/usr/share/icons/Adwaita/16x16/legacy/audio-volume-high.png"
- fi
- fi
- fi
-fi
+ if [[ $volume == "100" ]]; then
+ icon=""
+ elif [[ $volume -ge "89" && $volume -le "100" ]]; then
+ icon=""
+ elif [[ $volume -ge "79" && $volume -le "90" ]]; then
+ icon=""
+ elif [[ $volume -ge "69" && $volume -le "80" ]]; then
+ icon=""
+ elif [[ $volume -ge "59" && $volume -le "70" ]]; then
+ icon=""
+ elif [[ $volume -ge "49" && $volume -le "60" ]]; then
+ icon=""
+ elif [[ $volume -ge "39" && $volume -le "50" ]]; then
+ icon=""
+ elif [[ $volume -ge "29" && $volume -le "40" ]]; then
+ icon=""
+ elif [[ $volume -ge "19" && $volume -le "30" ]]; then
+ icon=""
+ elif [[ $volume -ge "9" && $volume -le "20" ]]; then
+ icon=""
+ elif [[ $volume -gt "0" && $volume -le "10" ]]; then
+ icon=""
+ elif [[ $volume -eq "0" ]]; then
+ icon=""
+ # volume="M "
+ fi
bar=$(seq -s "─" $(($volume/5)) | sed 's/[0-9]//g')
# Send the notification
-notify-send -i "$icon_name" -r 5556 -u normal "$bar $volume"
+notify-send --hint=string:x-canonical-private-synchronous:volumecontrol -u normal "$icon $bar $volume"
}
case $1 in
up)
# Set the volume on (if it was muted)
- amixer set Master on > /dev/null
+ # amixer set Master on > /dev/null
+ pactl set-sink-mute @DEFAULT_SINK@ 0
# Up the volume (+ 2%)
- amixer sset Master 2%+ > /dev/null
+ # amixer sset Master 2%+ > /dev/null
+ pactl set-sink-volume @DEFAULT_SINK@ +2%
send_notification
- canberra-gtk-play -i audio-volume-change
+ # canberra-gtk-play -i audio-volume-change
;;
down)
- amixer set Master on > /dev/null
- amixer sset Master 2%- > /dev/null
+ # amixer set Master on > /dev/null
+ pactl set-sink-mute @DEFAULT_SINK@ 0
+ # amixer sset Master 2%- > /dev/null
+ pactl set-sink-volume @DEFAULT_SINK@ -2%
send_notification
- canberra-gtk-play -i audio-volume-change
+ # canberra-gtk-play -i audio-volume-change
;;
mute)
# Toggle mute
- amixer set Master 1+ toggle > /dev/null
+ # amixer set Master 1+ toggle > /dev/null
+ pactl set-sink-mute @DEFAULT_SINK@ toggle
if is_mute ; then
- notify-send -i "/usr/share/icons/Adwaita/16x16/legacy/audio-volume-muted.png" -r 5556 -u normal "$bar Audio Muted"
+ icon="󰝟"
+ notify-send --hint=string:x-canonical-private-synchronous:volumecontrol -u normal "$icon Audio Muted"
else
send_notification
- canberra-gtk-play -i audio-volume-change
+ # canberra-gtk-play -i audio-volume-change
fi
;;
*)
@@ -92,13 +107,13 @@ case $1 in
elif [[ $volume -gt "0" && $volume -le "10" ]]; then
icon=""
elif [[ $volume -eq "0" ]]; then
- icon=""
+ icon="󰝟"
volume="M "
fi
if is_mute; then
- icon=""
+ icon="󰝟"
volume="M "
fi