-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavolume
executable file
·73 lines (65 loc) · 2.06 KB
/
pavolume
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
#!/bin/bash
#
# filename: pavolume
# Usage:
# pulsevolbar [0-100|up|down|toggle|mute|unmute|default]
#
#
#Customize this stuff
SECS="2" # sleep $SECS
BG="#444444" # background colour of window
FG="#857E7E" # foreground colour of text/icon
BAR_FG="#77A2D4" # foreground colour of volume bar
BAR_BG="#0F55A6" # background colour of volume bar
HEIGHT="30" # window height
WIDTH="250" # window width
BAR_WIDTH="150" # width of volume bar
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON_VOL=~/.pulse/icons/volume.xpm
ICON_VOL_MUTE=~/.pulse/icons/mute.xpm
ICON=$ICON_VOL
# No need to customize this variable
PIPE="/tmp/pavolume.dfg"
# Lets find the appropriate positioning for the volume bar
#XRES=`xdpyinfo|grep 'dimensions:'|awk '{print $2}'|cut -dx -f1`
XRES=$(xrandr | grep "\\*" | awk '{print $1}' | uniq | awk -F x '{print $1}')
XPOS=$[$XRES / 2 - $WIDTH / 2] # horizontal positioning
#YRES=`xdpyinfo|grep 'dimensions:'|awk '{print $2}'|cut -dx -f2`
YRES=$(xrandr | grep "\\*" | awk '{print $1}' | uniq | awk -F x '{print $2}')
YPOS=$[$YRES * 4 / 5] # vertical positioning
PAVOL="${SCRIPTS}/pavolume.rb"
# Gets the current volume, sets it into VOLUME
function get_volume()
{
VOLUME=$(${PAVOL} 2>/dev/null | grep "^0" | awk '{print $4}' | sed 's/%//')
}
# Get muted, sets icon
function get_muted()
{
MUTED=$(${PAVOL} 2>/dev/null | grep "^0" | awk '{print $3}')
if [[ $MUTED == "yes" ]]; then
ICON=$ICON_VOL_MUTE
else
ICON=$ICON_VOL
fi
}
if [[ $1 == "up" ]]; then
${PAVOL} up q 2>/dev/null
elif [[ $1 == "down" ]]; then
${PAVOL} down q 2>/dev/null
elif [[ $1 == "toggle" ]]; then
${PAVOL} toggle q 2>/dev/null
elif [[ $1 == "default" ]]; then
${PAVOL} 50 q 2>/dev/null
fi
# showing in dzen2
if [ ! -e "$PIPE" ]; then
mkfifo "$PIPE"
(dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
rm -f "$PIPE") &
fi
get_volume
get_muted
echo $ICON
# feed the pipe
(echo $VOLUME | gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH" ; sleep "$SECS" ) > "$PIPE"