sway_volume: toggle between sinks
This commit is contained in:
parent
52f7138b77
commit
b0e36f7ca6
2 changed files with 27 additions and 7 deletions
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
source $HOME/.config/sway/bin/sway_helpers
|
source $HOME/.config/sway/bin/sway_helpers
|
||||||
SINK=$(pactl info | grep "Default Sink" | cut -d ' ' -f 3)
|
|
||||||
SOURCE=$(pactl info | grep "Default Source" | cut -d ' ' -f 3)
|
|
||||||
ICON_PATH=$HOME/.local/share/icons/Tela-circle-dark/16/actions
|
ICON_PATH=$HOME/.local/share/icons/Tela-circle-dark/16/actions
|
||||||
NOTIFY_APP="dunstify -a volume -h string:x-dunst-stack-tag:volume"
|
NOTIFY_APP="dunstify -a volume -h string:x-dunst-stack-tag:volume"
|
||||||
APP="pavucontrol"
|
APP="pavucontrol"
|
||||||
|
@ -12,11 +10,21 @@ VOL1="●"
|
||||||
# echo -e '\u25cc'
|
# echo -e '\u25cc'
|
||||||
VOL2="◌"
|
VOL2="◌"
|
||||||
|
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
|
||||||
function notify() {
|
function notify() {
|
||||||
|
SINK=$(_get_default_sink)
|
||||||
SINK_VOLUME=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//')
|
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/%//')
|
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)
|
MUTE=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep 'Mute:' | cut -d " " -f 2)
|
||||||
SOURCE_MUTE=$(pactl list sources | grep "Name: $SOURCE" -A 8 | grep 'Mute:' | cut -d " " -f 2)
|
SOURCE_MUTE=$(pactl list sources | grep "Name: $SOURCE" -A 8 | grep 'Mute:' | cut -d " " -f 2)
|
||||||
|
NICK=$(_get_sink_nick $SINK)
|
||||||
|
|
||||||
ICON=$ICON_PATH/audio-volume-high.svg
|
ICON=$ICON_PATH/audio-volume-high.svg
|
||||||
SINK_ICON=""
|
SINK_ICON=""
|
||||||
|
@ -35,11 +43,16 @@ function notify() {
|
||||||
fi
|
fi
|
||||||
TITLE="${SINK_ICON} ${SINK_VOLUME}% / ${SOURCE_ICON} ${SOURCE_VOLUME}%"
|
TITLE="${SINK_ICON} ${SINK_VOLUME}% / ${SOURCE_ICON} ${SOURCE_VOLUME}%"
|
||||||
# $NOTIFY_APP -i $ICON -a "Volume" "$TEXT"
|
# $NOTIFY_APP -i $ICON -a "Volume" "$TEXT"
|
||||||
$NOTIFY_APP -i $ICON "$TITLE" "$(getProgressString 10 "$VOL1" "$VOL2" $SINK_VOLUME)"
|
$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
|
||||||
}
|
}
|
||||||
|
|
||||||
## helpers
|
## helpers
|
||||||
function _toggle() {
|
function _toggle_app() {
|
||||||
a=$1
|
a=$1
|
||||||
if [ $(pgrep $a) ]; then
|
if [ $(pgrep $a) ]; then
|
||||||
killall $a
|
killall $a
|
||||||
|
@ -49,6 +62,8 @@ function _toggle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
## main
|
## main
|
||||||
|
SINK=$(pactl info | grep "Default Sink" | cut -d ' ' -f 3)
|
||||||
|
SOURCE=$(pactl info | grep "Default Source" | cut -d ' ' -f 3)
|
||||||
if [ -z "$SINK" ]; then
|
if [ -z "$SINK" ]; then
|
||||||
_log VOLUME ERROR args: $*
|
_log VOLUME ERROR args: $*
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -84,10 +99,15 @@ case $1 in
|
||||||
paplay $SOUND &
|
paplay $SOUND &
|
||||||
notify
|
notify
|
||||||
;;
|
;;
|
||||||
|
# toggle between sinks
|
||||||
|
t*)
|
||||||
|
_toggle_sink $SINK
|
||||||
|
notify
|
||||||
|
;;
|
||||||
# show gui
|
# show gui
|
||||||
gui)
|
g*)
|
||||||
_check_app $APP
|
_check_app $APP
|
||||||
_toggle $APP
|
_toggle_app $APP
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "invalid command: \"$1\""
|
echo "invalid command: \"$1\""
|
||||||
|
|
|
@ -160,7 +160,7 @@
|
||||||
"min-length": 7,
|
"min-length": 7,
|
||||||
"max-length": 12,
|
"max-length": 12,
|
||||||
"on-click": "$HOME/.config/sway/bin/sway_volume mute",
|
"on-click": "$HOME/.config/sway/bin/sway_volume mute",
|
||||||
"on-click-middle": "$HOME/.config/sway/bin/sway_volume source-mute",
|
"on-click-middle": "$HOME/.config/sway/bin/sway_volume toggle-sink",
|
||||||
"on-click-right": "$HOME/.config/sway/bin/sway_volume gui",
|
"on-click-right": "$HOME/.config/sway/bin/sway_volume gui",
|
||||||
"on-scroll-up": "$HOME/.config/sway/bin/sway_volume increase",
|
"on-scroll-up": "$HOME/.config/sway/bin/sway_volume increase",
|
||||||
"on-scroll-down": "$HOME/.config/sway/bin/sway_volume decrease-mute"
|
"on-scroll-down": "$HOME/.config/sway/bin/sway_volume decrease-mute"
|
||||||
|
|
Loading…
Reference in a new issue