-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2
58 lines (48 loc) · 1.64 KB
/
2
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
#!/bin/bash
INSTANCE="${BLOCK_INSTANCE:-instance}"
STEP="${step:-5}" # use "step" set in i3blocks.conf, with 5 as default
echo 1 $BLOCK_BUTTON
echo 1 $BLOCK_BUTTON
# First round the old volume down to the next "$STEP"
INSTANCE=$(pacmd info | grep Default\ sink | grep -oE '[^ ]+$')
INSTANCE_NUM=$(pactl list short | grep "${INSTANCE}\s" | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,')
# Round to nearest ${STEP}
volume=$(pactl list sinks | perl -000ne "if(/#$INSTANCE_NUM\s/)"'{/(\d*)%/; print "$1\n"}')
volume=$(echo "$volume/$STEP*$STEP" | bc)
pactl set-sink-volume ${INSTANCE} $volume%
# Process the "mouse event"
# scroll up
if [[ "${BLOCK_BUTTON}" -eq 4 ]]; then
pactl set-sink-volume ${INSTANCE} +$STEP%
pactl set-sink-mute ${INSTANCE} off
# right click
elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then
pactl set-sink-mute ${INSTANCE} toggle
# scroll down
elif [[ "${BLOCK_BUTTON}" -eq 5 ]]; then
pactl set-sink-volume ${INSTANCE} -$STEP%
pactl set-sink-mute ${INSTANCE} off
fi
# Recalculate the mute status and volume
status=$(pactl list sinks | perl -000ne "if(/#$INSTANCE_NUM\s/)"'{/Mute: (no|yes)/; print "$1\n"}')
volume=$(pactl list sinks | perl -000ne "if(/#$INSTANCE_NUM\s/)"'{/(\d*)%/; print "$1\n"}')
RED=$( xrdb -query | grep ^\*color1: | cut -f 2)
WHITE=$( xrdb -query | grep ^\*color15: | cut -f 2)
# print the status text
if [[ "${status}" == "no" ]]; then
if [[ "${volume}" == "0" ]]; then
echo " ${volume}%"
echo " ${volume}%"
elif [[ "${volume}" -lt 70 ]]; then
echo " ${volume}%"
echo " ${volume}%"
else
echo " ${volume}%"
echo " ${volume}%"
fi
echo $WHITE
else
echo " MUTE"
echo " MUTE"
echo $RED
fi