aboutsummaryrefslogtreecommitdiffstats
path: root/.config/herbstluftwm/panel.sh
diff options
context:
space:
mode:
Diffstat (limited to '.config/herbstluftwm/panel.sh')
-rwxr-xr-x.config/herbstluftwm/panel.sh85
1 files changed, 41 insertions, 44 deletions
diff --git a/.config/herbstluftwm/panel.sh b/.config/herbstluftwm/panel.sh
index 7dfed18..7a4627d 100755
--- a/.config/herbstluftwm/panel.sh
+++ b/.config/herbstluftwm/panel.sh
@@ -1,28 +1,23 @@
1#!/bin/bash 1#!/bin/bash
2 2
3hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;} 3hc() {
4monitor=${1:-0} 4 "${herbstclient_command[@]:-herbstclient}" "$@" ;
5geometry=( $(herbstclient monitor_rect "$monitor") ) 5}
6if [ -z "$geometry" ] ;then
7 echo "Invalid monitor $monitor"
8 exit 1
9fi
10# geometry has the format W H X Y
11x=${geometry[0]}
12y=${geometry[1]}
13panel_width=${geometry[2]}
14 6
15add_alpha_channel(){ 7add_alpha_channel(){
16 echo "$1" | \ 8 echo "$1" | \
17 sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/" 9 sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/"
18} 10}
19 11
12monitor=${1:-0}
20panel_height=$2 13panel_height=$2
21light=$(add_alpha_channel $3) 14padding=$3
22llight=$(add_alpha_channel $4) 15
23accent=$(add_alpha_channel $5) 16light=$(add_alpha_channel $4)
24ldark=$(add_alpha_channel $6) 17llight=$(add_alpha_channel $5)
25dark=$(add_alpha_channel $7) 18accent=$(add_alpha_channel $6)
19ldark=$(add_alpha_channel $7)
20dark=$(add_alpha_channel $8)
26 21
27font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*" 22font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*"
28#font="" 23#font=""
@@ -32,7 +27,17 @@ selected_txt=$dark
32normal_txt=$light 27normal_txt=$light
33inactive_txt=$llight 28inactive_txt=$llight
34 29
35hc pad $monitor $panel_height 30geometry=( $(herbstclient monitor_rect "$monitor") )
31if [ -z "$geometry" ] ;then
32 echo "Invalid monitor $monitor"
33 exit 1
34fi
35# geometry has the format W H X Y
36x=$(echo "${geometry[0]} + $padding" | bc)
37y=$(echo "${geometry[1]} + $padding" | bc)
38panel_width=$(echo "${geometry[2]} - (2 * $padding)" | bc)
39
40hc pad $monitor $(echo "$panel_height + $padding" | bc)
36 41
37if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then 42if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then
38 # mawk needs "-W interactive" to line-buffer stdout correctly 43 # mawk needs "-W interactive" to line-buffer stdout correctly
@@ -79,7 +84,7 @@ fi
79 # Network 84 # Network
80 iwconfig=$(iwconfig wlp3s0) 85 iwconfig=$(iwconfig wlp3s0)
81 if [ -z $iwconfig ] ; then 86 if [ -z $iwconfig ] ; then
82 echo -e "wireless\toff" 87 echo -e "net\toff"
83 else 88 else
84 ssid=$(\ 89 ssid=$(\
85 echo $iwconfig | \ 90 echo $iwconfig | \
@@ -89,33 +94,25 @@ fi
89 ) 94 )
90 if [ $ssid = "off/any" ] ; then 95 if [ $ssid = "off/any" ] ; then
91 ifconf=$ 96 ifconf=$
92 echo -e "wireless\t%{F$normal_txt}Wlan: No connection%{F-}" 97 echo -e "net\t%{F$normal_txt}Net: No connection%{F-}"
93 else 98 else
94 IFS=',' read -a quality_info <<< $(\ 99 echo -e "net\t%{F$normal_txt}Net: $ssid%{F-}"
95 echo $iwconfig | \
96 sed "s/.*Link Quality=\([0-9]*\)\/\([0-9]*\).*/\1,\2/"\
97 )
98 cur_qual=${quality_info[0]}
99 max_qual=${quality_info[1]}
100 quality_p=$(echo "$cur_qual*100/$max_qual" | bc)
101 echo -e "wireless\t%{F$normal_txt}Wlan: $quality_p%% %{F$inactive_txt}($ssid)%{F-}"
102 fi 100 fi
103 fi 101 fi
104 102
105 # Battery 103 # Battery
106 IFS=' ' read -a batinfo <<< $(acpi -b) 104 if $(test -e /sys/class/power_supply/BAT1) ; then
107 if [ -z $batinfo ] ; then 105 charge=$(cat /sys/class/power_supply/BAT1/capacity)
108 echo -e "battery\toff"
109 else
110 charge=$(echo ${batinfo[3]} | tr -d '%,')
111 if [ $charge -lt 15 ] ; then 106 if [ $charge -lt 15 ] ; then
112 bat_color=$accent 107 bat_color=$accent
113 else 108 else
114 bat_color=$normal_txt 109 bat_color=$normal_txt
115 fi 110 fi
116 state=$(echo ${batinfo[2]} | tr -d ',') 111 state=$(cat /sys/class/power_supply/BAT1/status)
117 remaining=$(echo ${batinfo[4]}) 112 remaining=$(echo ${batinfo[4]})
118 echo -e "battery\t%{F$normal_txt}$state: %{F$bat_color}$charge%{F$normal_txt}%% %{F$inactive_txt}($remaining)%{F-}" 113 echo -e "battery\t%{F$normal_txt}$state: %{F$bat_color}$charge%{F$normal_txt}%% %{F-}"
114 else
115 echo -e "battery\toff"
119 fi 116 fi
120 117
121 # Time 118 # Time
@@ -132,7 +129,7 @@ fi
132 date="" 129 date=""
133 volume="" 130 volume=""
134 battery="" 131 battery=""
135 wireless="" 132 net=""
136 windowtitle="" 133 windowtitle=""
137 while true ; do 134 while true ; do
138 separator="%{F$accent}|%{F-}" 135 separator="%{F$accent}|%{F-}"
@@ -159,9 +156,9 @@ fi
159 done 156 done
160 echo -n "$separator" 157 echo -n "$separator"
161 echo -n "%{B-}%{F-} ${windowtitle//^/^^}" 158 echo -n "%{B-}%{F-} ${windowtitle//^/^^}"
162 159
163 #Right part of panel 160 #Right part of panel
164 right="$volume$wireless$battery$date " 161 right="$volume$net$battery$date "
165 echo -n "%{r}$right" 162 echo -n "%{r}$right"
166 echo 163 echo
167 164
@@ -180,12 +177,12 @@ fi
180 volume="$volume $separator%{B-} " 177 volume="$volume $separator%{B-} "
181 fi 178 fi
182 ;; 179 ;;
183 wireless) 180 net)
184 wireless="${cmd[@]:1}" 181 net="${cmd[@]:1}"
185 if [ $wireless = "off" ] ; then 182 if [ $net = "off" ] ; then
186 wireless="" 183 net=""
187 else 184 else
188 wireless="$wireless $separator%{B-} " 185 net="$net $separator%{B-} "
189 fi 186 fi
190 ;; 187 ;;
191 battery) 188 battery)