#!/bin/sh
steps="5"
dev=@DEFAULT_SINK@
! [ "$1" = '-m' ] || { dev=@DEFAULT_SOURCE@; shift; }

send_signal(){
  if [ "$dev" == "@DEFAULT_SINK@" ]; then
	  pkill -RTMIN+2 slstatus
  elif [ "$dev" == "@DEFAULT_SOURCE@" ]; then
	  pkill -RTMIN+3 slstatus
  fi
}

case "$1" in
	mute) wpctl set-mute "$dev" toggle; send_signal ;;
	up) wpctl set-volume -l 1.0 "$dev" "$steps"%+; send_signal ;;
	down) wpctl set-volume -l 1.0 "$dev" "$steps"%-; send_signal ;;
	-h|*) echo "usage: setvol [-m] up|down|mute" >&2; exit 1; ;;
esac
