Unix3r

Build. Break. Learn. Repeat.

Starting0%
Skip to content

unix3r/dotfiles

Public
main
U Unix3r Initial commit: sway + waybar dotfiles (Catppuccin Mocha) eb290df
45 lines · 1.6 KB Raw History
1#!/usr/bin/env bash
2# volume.sh up|down|mute|mic — PipeWire (wpctl) with pamixer fallback
3source "$(dirname "$0")/_lib.sh"
4STEP=5
5
6sink=@DEFAULT_AUDIO_SINK@
7src=@DEFAULT_AUDIO_SOURCE@
8
9if 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)
21elif 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
31else
32 notify volume dialog-error "Volume" "Install wireplumber or pamixer"; exit 1
33fi
34
35if [[ $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
38elif (( muted )); then
39 notify volume audio-volume-muted "Muted"
40else
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"
45fi