about summary refs log tree commit diff
path: root/swaywm/local/bin/volume
blob: eb662b490d428fcd3dc167f0a25d9f27d7acd2f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash

function get_volume {
    pactl get-sink-volume @DEFAULT_SINK@ | awk '/Volume:/ {print $5}' | cut -d '/' -f 1 | sed 's/%//g'
}

function is_mute {
    #amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
    pactl list sinks | grep -A 10 'State: ' | grep -q 'Mute: yes'
}

function is_mic_mute {
    pactl list sources | grep -A 10 'State: ' | grep -q 'Mute: yes'
}

function get_icon {
    volume=$(get_volume)
    if is_mute; then
        echo "audio-volume-muted-symbolic"
    elif (( volume <= 39 )); then
        echo "audio-volume-low-symbolic"
    elif (( volume <= 74 )); then
        echo "audio-volume-medium-symbolic"
    elif (( volume <= 100 )); then
        echo "audio-volume-high-symbolic"
    else
        echo "audio-volume-overamplified-symbolic"
    fi
}

function send_notification {
    volume=$(get_volume)
    icon=$(get_icon)
    # Make the bar with the special character ─ (it's not dash -)
    # https://en.wikipedia.org/wiki/Box-drawing_character
    bar=$(seq -s "─" $(($volume / 5)) | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i "$icon" -t 2500 -r 2593 -u normal "    $bar"
}

case $1 in
    up)
	# Set the volume on (if it was muted)
	#amixer -D pulse set Master on > /dev/null
	# Up the volume (+ 5%)
	# amixer -D pu lse sset Master 5%+ > /dev/null
        volume=$(get_volume)
        if [[ $volume -le 99 ]]; then
            pactl set-sink-volume @DEFAULT_SINK@ +5%
        else
            pactl set-sink-volume @DEFAULT_SINK@ 100%
        fi
        send_notification
	;;
    down)
	# amixer -D pulse set Master on > /dev/null
	# amixer -D pulse sset Master 5%- > /dev/null
        pactl set-sink-volume @DEFAULT_SINK@ -5%
	send_notification
	;;
    mute)
    	# Toggle mute
        pactl set-sink-mute @DEFAULT_SINK@ toggle
	if is_mute ; then
	    dunstify -i audio-volume-muted -t 2500 -r 2593 -u normal "Mute"
	else
	    send_notification
	fi
	;;
    mute-mic)
        pactl set-source-mute @DEFAULT_SOURCE@ toggle
        if is_mic_mute ; then
            dunstify -i microphone-sensitivity-muted-symbolic -t 2500 -r 2593 -u normal "Microphone Muted"
        else
            dunstify -i microphone-sensitivity-high-symbolic -t 2500 -r 2593 -u normal "Microphone Unmuted"
        fi
        ;;
esac