speedwm-personal/modules/module_vol

78 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/sh
# volume module for status/stellar
# load config
module_config
[ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc
[ "$ENABLE_ITEM4" != "true" ] && exit
[ -e "/tmp/module_vol_hidden" ] && exit
command -v pactl > /dev/null && BACKEND=pactl || BACKEND=amixer
command -v awk > /dev/null || exit
# click
CLICK() {
command -v speedwm-audioctrl > /dev/null || return
# values
VOL_VOLUME="$(speedwm-audioctrl -getvol)"
VOL_ISPULSE="$(speedwm-audioctrl -getbackend)"
2022-12-01 22:51:43 +01:00
GETDATA
[ -e "/tmp/speedwm-button" ] && BUTTON="$(cat /tmp/speedwm-button)" || BUTTON="0"
[ -z "$TERMINAL" ] && TERMINAL=st
2022-12-16 17:35:03 +01:00
[ -n "$ICON" ] && ICONSPACING=" " # one character spacing
# check value of button
case "$BUTTON" in
"3") $TERMINAL speedwm-audioctrl -runmixer ; exit ;;
esac
# send the notification
SEND_NOTIF() {
FULL_VOL="${ICON}${ICONSPACING}$VOL_VOLUME"
notify-send "$FULL_VOL"
# some information
echo "Notification sent successfully!"
echo "INFO: $FULL_VOL"
return
}
command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification."
return
}
2022-12-01 22:51:43 +01:00
# get data
GETDATA() {
[ "$BACKEND" = "pactl" ] && VOL="$(pactl get-sink-volume @DEFAULT_SINK@ | awk '{ print $5; exit }' | sed "s/\%//g")" || VOL="$(amixer -c 0 get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")"
[ "$VOL" -gt "99" ] && ICON="$ITEM4_ICON_100 "
[ "$VOL" -lt "100" ] && ICON="$ITEM4_ICON_75"
[ "$VOL" -lt "51" ] && ICON="$ITEM4_ICON_50"
[ "$VOL" -lt "26" ] && ICON="$ITEM4_ICON_25"
2022-12-01 22:51:43 +01:00
[ "$VOL" -lt "1" ] && ICON="$ITEM4_ICON_0"
2022-12-01 22:51:43 +01:00
# mute status
[ "$BACKEND" = "pactl" ] && pactl get-sink-mute @DEFAULT_SINK@ | grep -q yes && ICON="$ITEM4_ICON_MUTED" && MUTEDATA=" $ITEM4_MUTE_TEXT" || MUTEDATA=""
[ "$ITEM4_SHOW_MUTE" != "true" ] && MUTEDATA=""
}
# information itself
PRINT() {
2022-12-01 22:51:43 +01:00
GETDATA
VOL="${VOL}%"
echo "$ITEM4_SEPARATOR $ICON $VOL$MUTEDATA"
}
# argument 1
case "$1" in
"") CLICK ;;
"--print-file") PRINT > /tmp/module_vol ;;
"--print") PRINT ;;
"--click") CLICK ;;
esac