| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | source "$(dirname "$0")/_lib.sh" |
| 4 | STEP=5 |
| 5 | |
| 6 | sink=@DEFAULT_AUDIO_SINK@ |
| 7 | src=@DEFAULT_AUDIO_SOURCE@ |
| 8 | |
| 9 | if has wpctl; then |
| 10 | case $1 in |
| 11 | up) wpctl set-mute "$sink" 0; wpctl set-volume -l 1.5 "$sink" "$STEP%+" ;; |
| 12 | down) wpctl set-volume "$sink" "$STEP%-" ;; |
| 13 | mute) wpctl set-mute "$sink" toggle ;; |
| 14 | mic) wpctl set-mute "$src" toggle ;; |
| 15 | *) echo "usage: $0 up|down|mute|mic"; exit 1 ;; |
| 16 | esac |
| 17 | read -r _ vol muted < <(wpctl get-volume "$sink") |
| 18 | vol=$(awk -v v="$vol" 'BEGIN{printf "%d", v*100+0.5}') |
| 19 | [[ -n $muted ]] && muted=1 || muted=0 |
| 20 | mic_muted=$(wpctl get-volume "$src" | grep -q MUTED && echo 1 || echo 0) |
| 21 | elif has pamixer; then |
| 22 | case $1 in |
| 23 | up) pamixer -u -i "$STEP" ;; |
| 24 | down) pamixer -d "$STEP" ;; |
| 25 | mute) pamixer -t ;; |
| 26 | mic) pamixer --default-source -t ;; |
| 27 | esac |
| 28 | vol=$(pamixer --get-volume) |
| 29 | [[ $(pamixer --get-mute) == true ]] && muted=1 || muted=0 |
| 30 | [[ $(pamixer --default-source --get-mute) == true ]] && mic_muted=1 || mic_muted=0 |
| 31 | else |
| 32 | notify volume dialog-error "Volume" "Install wireplumber or pamixer"; exit 1 |
| 33 | fi |
| 34 | |
| 35 | if [[ $1 == mic ]]; then |
| 36 | if (( mic_muted )); then notify mic microphone-sensitivity-muted "Microphone muted" |
| 37 | else notify mic audio-input-microphone "Microphone on"; fi |
| 38 | elif (( muted )); then |
| 39 | notify volume audio-volume-muted "Muted" |
| 40 | else |
| 41 | if (( vol >= 70 )); then icon=audio-volume-high |
| 42 | elif (( vol >= 30 )); then icon=audio-volume-medium |
| 43 | else icon=audio-volume-low; fi |
| 44 | notify volume "$icon" "Volume" "$vol%" "$vol" |
| 45 | fi |