diff options
| author | 2014-05-16 21:16:18 +0200 | |
|---|---|---|
| committer | 2014-05-16 21:16:18 +0200 | |
| commit | a5edc4a0bc951023af8652d294e89ac37180abdd (patch) | |
| tree | fe617f9b8c307523e0b51ec3eb3101178578ca1e /.config/herbstluftwm | |
| parent | 8f4a4d47cbe50f24d5d87a326e01ec3a4360714b (diff) | |
| download | dotfiles-a5edc4a0bc951023af8652d294e89ac37180abdd.tar.gz dotfiles-a5edc4a0bc951023af8652d294e89ac37180abdd.tar.bz2 dotfiles-a5edc4a0bc951023af8652d294e89ac37180abdd.zip | |
Converted panel.sh to work with Bar Aint Recursive
Diffstat (limited to '.config/herbstluftwm')
| -rwxr-xr-x | .config/herbstluftwm/panel.sh | 144 |
1 files changed, 33 insertions, 111 deletions
diff --git a/.config/herbstluftwm/panel.sh b/.config/herbstluftwm/panel.sh index 97fb5ba..7dfed18 100755 --- a/.config/herbstluftwm/panel.sh +++ b/.config/herbstluftwm/panel.sh | |||
| @@ -12,12 +12,17 @@ x=${geometry[0]} | |||
| 12 | y=${geometry[1]} | 12 | y=${geometry[1]} |
| 13 | panel_width=${geometry[2]} | 13 | panel_width=${geometry[2]} |
| 14 | 14 | ||
| 15 | add_alpha_channel(){ | ||
| 16 | echo "$1" | \ | ||
| 17 | sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/" | ||
| 18 | } | ||
| 19 | |||
| 15 | panel_height=$2 | 20 | panel_height=$2 |
| 16 | light=$3 | 21 | light=$(add_alpha_channel $3) |
| 17 | llight=$4 | 22 | llight=$(add_alpha_channel $4) |
| 18 | accent=$5 | 23 | accent=$(add_alpha_channel $5) |
| 19 | ldark=$6 | 24 | ldark=$(add_alpha_channel $6) |
| 20 | dark=$7 | 25 | dark=$(add_alpha_channel $7) |
| 21 | 26 | ||
| 22 | font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*" | 27 | font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*" |
| 23 | #font="" | 28 | #font="" |
| @@ -27,29 +32,8 @@ selected_txt=$dark | |||
| 27 | normal_txt=$light | 32 | normal_txt=$light |
| 28 | inactive_txt=$llight | 33 | inactive_txt=$llight |
| 29 | 34 | ||
| 30 | ######################################################################################## | 35 | hc pad $monitor $panel_height |
| 31 | # Try to find textwidth binary. | ||
| 32 | # In e.g. Ubuntu, this is named dzen2-textwidth. | ||
| 33 | if which textwidth &> /dev/null ; then | ||
| 34 | textwidth="textwidth"; | ||
| 35 | elif which dzen2-textwidth &> /dev/null ; then | ||
| 36 | textwidth="dzen2-textwidth"; | ||
| 37 | else | ||
| 38 | echo "This script requires the textwidth tool of the dzen2 project." | ||
| 39 | exit 1 | ||
| 40 | fi | ||
| 41 | |||
| 42 | ######################################################################################## | ||
| 43 | # true if we are using the svn version of dzen2 | ||
| 44 | # depending on version/distribution, this seems to have version strings like | ||
| 45 | # "dzen-" or "dzen-x.x.x-svn" | ||
| 46 | if dzen2 -v 2>&1 | head -n 1 | grep -q '^dzen-\([^,]*-svn\|\),'; then | ||
| 47 | dzen2_svn="true" | ||
| 48 | else | ||
| 49 | dzen2_svn="" | ||
| 50 | fi | ||
| 51 | 36 | ||
| 52 | ######################################################################################## | ||
| 53 | if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then | 37 | if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then |
| 54 | # mawk needs "-W interactive" to line-buffer stdout correctly | 38 | # mawk needs "-W interactive" to line-buffer stdout correctly |
| 55 | # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504 | 39 | # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504 |
| @@ -64,13 +48,8 @@ else | |||
| 64 | } | 48 | } |
| 65 | fi | 49 | fi |
| 66 | 50 | ||
| 67 | ######################################################################################## | ||
| 68 | hc pad $monitor $panel_height | ||
| 69 | |||
| 70 | ######################################################################################## | ||
| 71 | { | 51 | { |
| 72 | ### Event generator ### | 52 | ### Event generator ### |
| 73 | # based on different input data (mpc, date, hlwm hooks, ...) this generates events, formed like this: | ||
| 74 | # <eventname>\t<data> [...] | 53 | # <eventname>\t<data> [...] |
| 75 | # e.g. | 54 | # e.g. |
| 76 | # date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29 | 55 | # date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29 |
| @@ -89,9 +68,9 @@ hc pad $monitor $panel_height | |||
| 89 | if [ -z $vol ] ; then | 68 | if [ -z $vol ] ; then |
| 90 | echo -e "volume\toff" | 69 | echo -e "volume\toff" |
| 91 | elif [ $vol -le 0 ] ; then | 70 | elif [ $vol -le 0 ] ; then |
| 92 | echo -e "volume\t^fg($normal_txt)Volume muted" | 71 | echo -e "volume\t%{F$normal_txt}Volume muted" |
| 93 | else | 72 | else |
| 94 | echo -e "volume\t^fg($normal_txt)Volume: $vol%" | 73 | echo -e "volume\t%{F$normal_txt}Volume: $vol%%%{F-}" |
| 95 | fi | 74 | fi |
| 96 | else | 75 | else |
| 97 | echo -e "volume\toff" | 76 | echo -e "volume\toff" |
| @@ -110,7 +89,7 @@ hc pad $monitor $panel_height | |||
| 110 | ) | 89 | ) |
| 111 | if [ $ssid = "off/any" ] ; then | 90 | if [ $ssid = "off/any" ] ; then |
| 112 | ifconf=$ | 91 | ifconf=$ |
| 113 | echo -e "wireless\t^fg($normal_txt)Wlan: No connection" | 92 | echo -e "wireless\t%{F$normal_txt}Wlan: No connection%{F-}" |
| 114 | else | 93 | else |
| 115 | IFS=',' read -a quality_info <<< $(\ | 94 | IFS=',' read -a quality_info <<< $(\ |
| 116 | echo $iwconfig | \ | 95 | echo $iwconfig | \ |
| @@ -119,7 +98,7 @@ hc pad $monitor $panel_height | |||
| 119 | cur_qual=${quality_info[0]} | 98 | cur_qual=${quality_info[0]} |
| 120 | max_qual=${quality_info[1]} | 99 | max_qual=${quality_info[1]} |
| 121 | quality_p=$(echo "$cur_qual*100/$max_qual" | bc) | 100 | quality_p=$(echo "$cur_qual*100/$max_qual" | bc) |
| 122 | echo -e "wireless\t^fg($normal_txt)Wlan: $quality_p% ^fg($inactive_txt)($ssid)" | 101 | echo -e "wireless\t%{F$normal_txt}Wlan: $quality_p%% %{F$inactive_txt}($ssid)%{F-}" |
| 123 | fi | 102 | fi |
| 124 | fi | 103 | fi |
| 125 | 104 | ||
| @@ -136,11 +115,11 @@ hc pad $monitor $panel_height | |||
| 136 | fi | 115 | fi |
| 137 | state=$(echo ${batinfo[2]} | tr -d ',') | 116 | state=$(echo ${batinfo[2]} | tr -d ',') |
| 138 | remaining=$(echo ${batinfo[4]}) | 117 | remaining=$(echo ${batinfo[4]}) |
| 139 | echo -e "battery\t^fg($normal_txt)$state: ^fg($bat_color)$charge^fg($normal_txt)% ^fg($inactive_txt)($remaining)" | 118 | echo -e "battery\t%{F$normal_txt}$state: %{F$bat_color}$charge%{F$normal_txt}%% %{F$inactive_txt}($remaining)%{F-}" |
| 140 | fi | 119 | fi |
| 141 | 120 | ||
| 142 | # Time | 121 | # Time |
| 143 | echo -e $(date +$"date\t^fg($normal_txt)%H:%M:%S^fg($inactive_txt) (%d-%m-%Y)") | 122 | echo -e $(date +$"date\t%{F$normal_txt}%H:%M:%S %{F$inactive_txt}(%d-%m-%Y)%{F-}") |
| 144 | sleep 1 || break | 123 | sleep 1 || break |
| 145 | done > >(uniq_linebuffered) & | 124 | done > >(uniq_linebuffered) & |
| 146 | childpid=$! | 125 | childpid=$! |
| @@ -156,64 +135,38 @@ hc pad $monitor $panel_height | |||
| 156 | wireless="" | 135 | wireless="" |
| 157 | windowtitle="" | 136 | windowtitle="" |
| 158 | while true ; do | 137 | while true ; do |
| 159 | 138 | separator="%{F$accent}|%{F-}" | |
| 160 | ### Output ###################################################################### | ||
| 161 | # This part prints dzen data based on the _previous_ data handling run, | ||
| 162 | # and then waits for the next event to happen. | ||
| 163 | |||
| 164 | bordercolor="#26221C" | ||
| 165 | separator="^bg()^fg($accent)|" | ||
| 166 | # draw tags | 139 | # draw tags |
| 167 | for i in "${tags[@]}" ; do | 140 | for i in "${tags[@]}" ; do |
| 168 | case ${i:0:1} in | 141 | case ${i:0:1} in |
| 169 | '#') | 142 | '#') |
| 170 | echo -n "^bg($selected_bg)^fg($selected_txt)" | 143 | echo -n "%{U$accent+u}%{B-}%{F$normal_txt}" |
| 171 | ;; | 144 | ;; |
| 172 | '+') | 145 | '+') |
| 173 | echo -n "^bg($accent)^fg($normal_bg)" | 146 | echo -n "%{B$accent}%{F$normal_bg}" |
| 174 | ;; | 147 | ;; |
| 175 | ':') | 148 | ':') |
| 176 | echo -n "^bg()^fg($normal_txt)" | 149 | echo -n "%{B-}%{F$normal_txt}" |
| 177 | ;; | 150 | ;; |
| 178 | '!') | 151 | '!') |
| 179 | echo -n "^bg($normal_txt)^fg($normal_bg)" | 152 | echo -n "%{B$normal_txt}%{F$normal_bg}" |
| 180 | ;; | 153 | ;; |
| 181 | *) | 154 | *) |
| 182 | echo -n "^bg()^fg($inactive_txt)" | 155 | echo -n "%{B-}%{F$inactive_txt}" |
| 183 | ;; | 156 | ;; |
| 184 | esac | 157 | esac |
| 185 | if [ ! -z "$dzen2_svn" ] ; then | 158 | echo -n " ${i:1} %{F-}%{B-}%{U-u}" |
| 186 | # clickable tags if using SVN dzen | ||
| 187 | echo -n "^ca(1,\"${herbstclient_command[@]:-herbstclient}\" " | ||
| 188 | echo -n "focus_monitor \"$monitor\" && " | ||
| 189 | echo -n "\"${herbstclient_command[@]:-herbstclient}\" " | ||
| 190 | echo -n "use \"${i:1}\") ${i:1} ^ca()" | ||
| 191 | else | ||
| 192 | # non-clickable tags if using older dzen | ||
| 193 | echo -n " ${i:1} " | ||
| 194 | fi | ||
| 195 | done | 159 | done |
| 196 | echo -n "$separator" | 160 | echo -n "$separator" |
| 197 | echo -n "^bg()^fg() ${windowtitle//^/^^}" | 161 | echo -n "%{B-}%{F-} ${windowtitle//^/^^}" |
| 198 | # small adjustments | 162 | |
| 163 | #Right part of panel | ||
| 199 | right="$volume$wireless$battery$date " | 164 | right="$volume$wireless$battery$date " |
| 200 | right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g') | 165 | echo -n "%{r}$right" |
| 201 | # get width of right aligned text.. and add some space.. | ||
| 202 | width=$($textwidth "$font" "$right_text_only") | ||
| 203 | echo -n "^pa($(($panel_width - $width)))$right" | ||
| 204 | echo | 166 | echo |
| 205 | 167 | ||
| 206 | ### Data handling ### | ||
| 207 | # This part handles the events generated in the event loop, and sets | ||
| 208 | # internal variables based on them. The event and its arguments are | ||
| 209 | # read into the array cmd, then action is taken depending on the event | ||
| 210 | # name. | ||
| 211 | # "Special" events (quit_panel/togglehidepanel/reload) are also handled | ||
| 212 | # here. | ||
| 213 | |||
| 214 | # wait for next event | 168 | # wait for next event |
| 215 | IFS=$'\t' read -ra cmd || break | 169 | IFS=$'\t' read -ra cmd || break |
| 216 | # find out event origin | ||
| 217 | case "${cmd[0]}" in | 170 | case "${cmd[0]}" in |
| 218 | tag*) | 171 | tag*) |
| 219 | #echo "resetting tags" >&2 | 172 | #echo "resetting tags" >&2 |
| @@ -224,7 +177,7 @@ hc pad $monitor $panel_height | |||
| 224 | if [ $volume == "off" ] ; then | 177 | if [ $volume == "off" ] ; then |
| 225 | volume="" | 178 | volume="" |
