config_sway/bin/sway_volume

97 lines
2.4 KiB
Text
Raw Normal View History

#!/bin/bash
2021-01-04 18:46:33 +01:00
source $HOME/.config/sway/bin/sway_helpers
SINK=$(pactl info | grep "Default Sink" | cut -d ' ' -f 3)
2021-05-14 12:00:51 +02:00
SOURCE=$(pactl info | grep "Default Source" | cut -d ' ' -f 3)
ICON_PATH=$HOME/.local/share/icons/Tela-circle-dark/16/actions
2021-02-24 11:30:20 +01:00
NOTIFY_APP="dunstify -a volume -h string:x-dunst-stack-tag:volume"
2021-03-16 12:50:55 +01:00
APP="pavucontrol"
SOUND=$HOME/.config/sway/bin/audio-volume-change.oga
# echo -e '\u25cf'
VOL1="●"
# echo -e '\u25cc'
VOL2="◌"
function notify() {
2021-05-14 12:00:51 +02:00
SINK_VOLUME=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//')
SOURCE_VOLUME=$(pactl list sources | grep "Name: $SOURCE" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//')
MUTE=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep 'Mute:' | cut -d " " -f 2)
2021-05-14 12:00:51 +02:00
SOURCE_MUTE=$(pactl list sources | grep "Name: $SOURCE" -A 8 | grep 'Mute:' | cut -d " " -f 2)
2021-05-14 12:00:51 +02:00
ICON=$ICON_PATH/audio-volume-high.svg
SINK_ICON=""
if [ "$MUTE" = "yes" ]; then
ICON=$ICON_PATH/audio-volume-muted.svg
2021-05-14 12:00:51 +02:00
elif [ $SINK_VOLUME -le 33 ]; then
2021-03-10 13:55:20 +01:00
ICON=$ICON_PATH/audio-volume-low.svg
2021-05-14 12:00:51 +02:00
SINK_ICON=""
elif [ $SINK_VOLUME -le 67 ]; then
2021-03-10 13:55:20 +01:00
ICON=$ICON_PATH/audio-volume-medium.svg
2021-05-14 12:00:51 +02:00
SINK_ICON=""
fi
SOURCE_ICON=""
if [ "$SOURCE_MUTE" = "yes" ]; then
SOURCE_ICON=""
2021-03-10 13:55:20 +01:00
fi
2021-05-14 12:00:51 +02:00
TITLE="${SINK_ICON} ${SINK_VOLUME}% / ${SOURCE_ICON} ${SOURCE_VOLUME}%"
2021-02-18 16:24:25 +01:00
# $NOTIFY_APP -i $ICON -a "Volume" "$TEXT"
2021-05-14 12:00:51 +02:00
$NOTIFY_APP -i $ICON "$TITLE" "$(getProgressString 10 "$VOL1" "$VOL2" $SINK_VOLUME)"
}
## helpers
function _toggle() {
a=$1
if [ $(pgrep $a) ]; then
killall $a
else
$a &> /dev/null &
fi
}
## main
if [ -z "$SINK" ]; then
_log VOLUME ERROR args: $*
exit 1
fi
case $1 in
2021-05-14 12:00:51 +02:00
# decrease
d*)
pactl set-sink-volume $SINK -5%
paplay $SOUND &
notify
;;
2021-05-14 12:00:51 +02:00
# increase
i*)
VOLUME=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//')
INC=$((100 - $VOLUME))
if [ $INC -gt 5 ]; then
INC=5
fi
pactl set-sink-volume $SINK +${INC}%
paplay $SOUND &
notify
;;
2021-05-14 12:00:51 +02:00
# mute
m*)
pactl set-sink-mute $SINK toggle
paplay $SOUND &
notify
;;
2021-05-14 12:00:51 +02:00
# source-mute
s*)
pactl set-source-mute $SOURCE toggle
paplay $SOUND &
notify
;;
# show gui
gui)
_check_app $APP
_toggle $APP
;;
*)
echo "invalid command: \"$1\""
echo "arguments: [decrease|increase|mute|gui]"
;;
esac