2020-12-22 17:04:22 +01:00
|
|
|
#!/bin/bash
|
2021-01-04 18:46:33 +01:00
|
|
|
source $HOME/.config/sway/bin/sway_helpers
|
2021-02-16 08:49:15 +01:00
|
|
|
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
|
|
|
|
|
2021-03-01 11:09:18 +01:00
|
|
|
# echo -e '\u25cf'
|
|
|
|
VOL1="●"
|
|
|
|
# echo -e '\u25cc'
|
|
|
|
VOL2="◌"
|
2021-02-26 19:12:44 +01:00
|
|
|
|
2024-12-27 11:33:16 +01:00
|
|
|
function _get_default_sink() {
|
|
|
|
pactl info | grep "Default Sink" | cut -d ' ' -f 3
|
|
|
|
}
|
|
|
|
|
|
|
|
function _get_sink_nick() {
|
|
|
|
pactl -f json list sinks | jq -c ".[] | select(.name | contains(\"$1\")) | .properties.\"device.nick\"" | sed 's/"//g'
|
|
|
|
}
|
|
|
|
|
2021-02-16 08:49:15 +01:00
|
|
|
function notify() {
|
2024-12-27 11:33:16 +01:00
|
|
|
SINK=$(_get_default_sink)
|
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/%//')
|
2021-02-16 08:49:15 +01:00
|
|
|
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)
|
2024-12-27 11:33:16 +01:00
|
|
|
NICK=$(_get_sink_nick $SINK)
|
2021-02-16 08:49:15 +01:00
|
|
|
|
2021-05-14 12:00:51 +02:00
|
|
|
ICON=$ICON_PATH/audio-volume-high.svg
|
|
|
|
SINK_ICON=""
|
2021-02-16 08:49:15 +01:00
|
|
|
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"
|
2024-12-27 11:33:16 +01:00
|
|
|
$NOTIFY_APP -i $ICON "$TITLE" "$NICK\n$(getProgressString 10 "$VOL1" "$VOL2" $SINK_VOLUME)"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _toggle_sink() {
|
|
|
|
sink_next=$(pactl list sinks | grep node\.name | grep -oE '"[a-zA-Z0-9_.-]*"' | grep -v $1 | sed 's/"//g' | sort -R)
|
|
|
|
pactl set-default-sink $sink_next
|
2021-02-16 08:49:15 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 18:27:42 +01:00
|
|
|
## helpers
|
2024-12-27 11:33:16 +01:00
|
|
|
function _toggle_app() {
|
2021-01-04 17:37:20 +01:00
|
|
|
a=$1
|
|
|
|
if [ $(pgrep $a) ]; then
|
|
|
|
killall $a
|
|
|
|
else
|
|
|
|
$a &> /dev/null &
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-04 18:27:42 +01:00
|
|
|
## main
|
2024-12-27 11:33:16 +01:00
|
|
|
SINK=$(pactl info | grep "Default Sink" | cut -d ' ' -f 3)
|
|
|
|
SOURCE=$(pactl info | grep "Default Source" | cut -d ' ' -f 3)
|
2021-01-04 18:27:42 +01:00
|
|
|
if [ -z "$SINK" ]; then
|
|
|
|
_log VOLUME ERROR args: $*
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-22 17:04:22 +01:00
|
|
|
case $1 in
|
2021-05-14 12:00:51 +02:00
|
|
|
# decrease
|
2020-12-22 17:04:22 +01:00
|
|
|
d*)
|
2021-01-04 18:27:42 +01:00
|
|
|
pactl set-sink-volume $SINK -5%
|
2021-02-03 12:16:47 +01:00
|
|
|
paplay $SOUND &
|
2021-02-16 08:49:15 +01:00
|
|
|
notify
|
2020-12-22 17:04:22 +01:00
|
|
|
;;
|
2021-05-14 12:00:51 +02:00
|
|
|
# increase
|
2020-12-22 17:04:22 +01:00
|
|
|
i*)
|
2021-02-26 19:12:44 +01:00
|
|
|
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}%
|
2021-02-03 12:16:47 +01:00
|
|
|
paplay $SOUND &
|
2021-02-16 08:49:15 +01:00
|
|
|
notify
|
2020-12-22 17:04:22 +01:00
|
|
|
;;
|
2021-05-14 12:00:51 +02:00
|
|
|
# mute
|
2020-12-22 17:04:22 +01:00
|
|
|
m*)
|
2021-01-04 18:27:42 +01:00
|
|
|
pactl set-sink-mute $SINK toggle
|
2021-02-03 12:16:47 +01:00
|
|
|
paplay $SOUND &
|
2021-02-16 08:49:15 +01:00
|
|
|
notify
|
2020-12-22 17:04:22 +01:00
|
|
|
;;
|
2021-05-14 12:00:51 +02:00
|
|
|
# source-mute
|
|
|
|
s*)
|
|
|
|
pactl set-source-mute $SOURCE toggle
|
|
|
|
paplay $SOUND &
|
|
|
|
notify
|
|
|
|
;;
|
2024-12-27 11:33:16 +01:00
|
|
|
# toggle between sinks
|
|
|
|
t*)
|
|
|
|
_toggle_sink $SINK
|
|
|
|
notify
|
|
|
|
;;
|
2021-05-14 12:00:51 +02:00
|
|
|
# show gui
|
2024-12-27 11:33:16 +01:00
|
|
|
g*)
|
2021-01-04 18:27:42 +01:00
|
|
|
_check_app $APP
|
2024-12-27 11:33:16 +01:00
|
|
|
_toggle_app $APP
|
2021-01-04 17:37:20 +01:00
|
|
|
;;
|
2020-12-22 17:04:22 +01:00
|
|
|
*)
|
2021-01-04 18:27:42 +01:00
|
|
|
echo "invalid command: \"$1\""
|
|
|
|
echo "arguments: [decrease|increase|mute|gui]"
|
2020-12-22 17:04:22 +01:00
|
|
|
;;
|
|
|
|
esac
|