speedwm-personal/modules/module_vol

72 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
# volume module for status/stellar
#
# load config
. $HOME/.config/speedwm-de/statusrc
BINDIR="$(dirname $(command -v speedwm_status))/"
ARG1="$1"
# click
CLICK() {
# values
VOL_VOLUME="$(speedwm-audioctrl -getvol)"
VOL_ISPULSE="$(speedwm-audioctrl -getbackend)"
ICON="$ITEM4_ICON"
BUTTON="$(cat /tmp/speedwm-button)"
case "$TERMINAL" in
"") TERMINAL=st
esac
case "$BUTTON" in
"3") $TERMINAL speedwm-audioctrl -runmixer ; exit ;;
esac
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
FULL_VOL="${ICON}${ICONSPACING}$VOL_VOLUME"
notify-send "$FULL_VOL"
echo "Notification sent successfully!"
echo "INFO: $FULL_VOL"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1
}
# information itself
PRINT() {
if [ "$ENABLE_ITEM4" = "true" ]; then
if [ -e "${BINDIR}pactl" ]; then
echo "$SEPARATOR $ITEM4_ICON $(echo $(pactl get-sink-volume 0 | awk '{print $5;exit}'))"
else
echo "$SEPARATOR $ITEM4_ICON $(echo $(amixer -c 0 get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")%)"
fi
fi
# get mute
if [ "$ITEM4_SHOW_MUTE" = "true" ]; then
if [ -e "${BINDIR}pactl" ]; then
pactl get-sink-mute 0 | grep -q yes && echo " $ITEM4_MUTE_TEXT"
fi
fi
}
# argument 1
case "$ARG1" in
"") CLICK ;;
"--print") PRINT > /tmp/module_vol ;;
"--click") CLICK ;;
esac