sway: add OSD to the pactl volume control bindings

This commit is contained in:
Aleksei Bavshin 2022-06-28 20:15:47 -07:00
commit 3a04082a7e
No known key found for this signature in database
GPG key ID: 4F071603387A382A
3 changed files with 48 additions and 5 deletions

32
scripts/notify-volume Executable file
View file

@ -0,0 +1,32 @@
#!/bin/sh
set -ex
if ! command -v notify-send >/dev/null || ! command -v pactl > /dev/null; then
exit 0;
fi
# pactl output depends on the current locale
export LANG=C.UTF-8 LC_ALL=C.UTF-8
SINK=${1:-@DEFAULT_SINK@}
VOLUME=$(pactl get-sink-volume "$SINK")
# get first percent value
VOLUME=${VOLUME%%%*}
VOLUME=${VOLUME##* }
TEXT="Volume: ${VOLUME}%"
case $(pactl get-sink-mute "$SINK") in
*yes)
TEXT="Volume: muted"
VOLUME=0
;;
esac
notify-send \
--app-name sway \
--expire-time 800 \
--hint string:x-canonical-private-synchronous:volume \
--hint "int:value:$VOLUME" \
--transient \
"${TEXT}"