diff options
| author | 2014-05-01 23:19:09 +0200 | |
|---|---|---|
| committer | 2014-05-01 23:19:09 +0200 | |
| commit | 72355fa057416a3eddfe34563d3bfdea1ea620a6 (patch) | |
| tree | 75cbb2855f81c7cc6ac3ea0ee2a97372a10b7f91 /.config/herbstluftwm/panel.sh | |
| parent | 824adfd4e807fbf986286289a7d8d106a2a73205 (diff) | |
| download | dotfiles-72355fa057416a3eddfe34563d3bfdea1ea620a6.tar.gz dotfiles-72355fa057416a3eddfe34563d3bfdea1ea620a6.tar.bz2 dotfiles-72355fa057416a3eddfe34563d3bfdea1ea620a6.zip | |
Updates
- VIM config
- Herbstluft config
Diffstat (limited to '.config/herbstluftwm/panel.sh')
| -rwxr-xr-x | .config/herbstluftwm/panel.sh | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/.config/herbstluftwm/panel.sh b/.config/herbstluftwm/panel.sh new file mode 100755 index 0000000..cc4fb1e --- /dev/null +++ b/.config/herbstluftwm/panel.sh | |||
| @@ -0,0 +1,189 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;} | ||
| 4 | monitor=${1:-0} | ||
| 5 | geometry=( $(herbstclient monitor_rect "$monitor") ) | ||
| 6 | if [ -z "$geometry" ] ;then | ||
| 7 | echo "Invalid monitor $monitor" | ||
| 8 | exit 1 | ||
| 9 | fi | ||
| 10 | # geometry has the format W H X Y | ||
| 11 | x=${geometry[0]} | ||
| 12 | y=${geometry[1]} | ||
| 13 | panel_width=${geometry[2]} | ||
| 14 | panel_height=24 | ||
| 15 | font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*" | ||
| 16 | bgcolor=$(hc get frame_border_normal_color) | ||
| 17 | selbg=$(hc get window_border_active_color) | ||
| 18 | selfg='#101010' | ||
| 19 | |||
| 20 | ######################################################################################## | ||
| 21 | # Try to find textwidth binary. | ||
| 22 | # In e.g. Ubuntu, this is named dzen2-textwidth. | ||
| 23 | if which textwidth &> /dev/null ; then | ||
| 24 | textwidth="textwidth"; | ||
| 25 | elif which dzen2-textwidth &> /dev/null ; then | ||
| 26 | textwidth="dzen2-textwidth"; | ||
| 27 | else | ||
| 28 | echo "This script requires the textwidth tool of the dzen2 project." | ||
| 29 | exit 1 | ||
| 30 | fi | ||
| 31 | |||
| 32 | ######################################################################################## | ||
| 33 | # true if we are using the svn version of dzen2 | ||
| 34 | # depending on version/distribution, this seems to have version strings like | ||
| 35 | # "dzen-" or "dzen-x.x.x-svn" | ||
| 36 | if dzen2 -v 2>&1 | head -n 1 | grep -q '^dzen-\([^,]*-svn\|\),'; then | ||
| 37 | dzen2_svn="true" | ||
| 38 | else | ||
| 39 | dzen2_svn="" | ||
| 40 | fi | ||
| 41 | |||
| 42 | ######################################################################################## | ||
| 43 | if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then | ||
| 44 | # mawk needs "-W interactive" to line-buffer stdout correctly | ||
| 45 | # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504 | ||
| 46 | uniq_linebuffered() { | ||
| 47 | awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@" | ||
| 48 | } | ||
| 49 | else | ||
| 50 | # other awk versions (e.g. gawk) issue a warning with "-W interactive", so | ||
| 51 | # we don't want to use it there. | ||
| 52 | uniq_linebuffered() { | ||
| 53 | awk '$0 != l { print ; l=$0 ; fflush(); }' "$@" | ||
| 54 | } | ||
| 55 | fi | ||
| 56 | |||
| 57 | ######################################################################################## | ||
| 58 | hc pad $monitor $panel_height | ||
| 59 | |||
| 60 | ######################################################################################## | ||
| 61 | { | ||
| 62 | ### Event generator ### | ||
| 63 | # based on different input data (mpc, date, hlwm hooks, ...) this generates events, formed like this: | ||
| 64 | # <eventname>\t<data> [...] | ||
| 65 | # e.g. | ||
| 66 | # date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29 | ||
| 67 | |||
| 68 | #mpc idleloop player & | ||
| 69 | while true ; do | ||
| 70 | # "date" output is checked once a second, but an event is only | ||
| 71 | # generated if the output changed compared to the previous run. | ||
| 72 | date +$'date\t^fg(#efefef)%H:%M:%S^fg(#909090), %Y-%m-^fg(#efefef)%d' | ||
| 73 | sleep 1 || break | ||
| 74 | done > >(uniq_linebuffered) & | ||
| 75 | childpid=$! | ||
| 76 | hc --idle | ||
| 77 | kill $childpid | ||
| 78 | } 2> /dev/null | { | ||
| 79 | |||
| 80 | IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)" | ||
| 81 | visible=true | ||
| 82 | date="" | ||
| 83 | windowtitle="" | ||
| 84 | while true ; do | ||
| 85 | |||
| 86 | ### Output ###################################################################### | ||
| 87 | # This part prints dzen data based on the _previous_ data handling run, | ||
| 88 | # and then waits for the next event to happen. | ||
| 89 | |||
| 90 | bordercolor="#26221C" | ||
| 91 | separator="^bg()^fg($selbg)|" | ||
| 92 | # draw tags | ||
| 93 | for i in "${tags[@]}" ; do | ||
| 94 | case ${i:0:1} in | ||
| 95 | '#') | ||
| 96 | echo -n "^bg($selbg)^fg($selfg)" | ||
| 97 | ;; | ||
| 98 | '+') | ||
| 99 | echo -n "^bg(#9CA668)^fg(#141414)" | ||
| 100 | ;; | ||
| 101 | ':') | ||
| 102 | echo -n "^bg()^fg(#ffffff)" | ||
| 103 | ;; | ||
| 104 | '!') | ||
| 105 | echo -n "^bg(#FF0675)^fg(#141414)" | ||
| 106 | ;; | ||
| 107 | *) | ||
| 108 | echo -n "^bg()^fg(#ababab)" | ||
| 109 | ;; | ||
| 110 | esac | ||
| 111 | if [ ! -z "$dzen2_svn" ] ; then | ||
| 112 | # clickable tags if using SVN dzen | ||
| 113 | echo -n "^ca(1,\"${herbstclient_command[@]:-herbstclient}\" " | ||
| 114 | echo -n "focus_monitor \"$monitor\" && " | ||
| 115 | echo -n "\"${herbstclient_command[@]:-herbstclient}\" " | ||
| 116 | echo -n "use \"${i:1}\") ${i:1} ^ca()" | ||
| 117 | else | ||
| 118 | # non-clickable tags if using older dzen | ||
| 119 | echo -n " ${i:1} " | ||
| 120 | fi | ||
| 121 | done | ||
| 122 | echo -n "$separator" | ||
| 123 | echo -n "^bg()^fg() ${windowtitle//^/^^}" | ||
| 124 | # small adjustments | ||
| 125 | right="$separator^bg() $date $separator" | ||
| 126 | right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g') | ||
| 127 | # get width of right aligned text.. and add some space.. | ||
| 128 | width=$($textwidth "$font" "$right_text_only ") | ||
| 129 | echo -n "^pa($(($panel_width - $width)))$right" | ||
| 130 | echo | ||
| 131 | |||
| 132 | ### Data handling ### | ||
| 133 | # This part handles the events generated in the event loop, and sets | ||
| 134 | # internal variables based on them. The event and its arguments are | ||
| 135 | # read into the array cmd, then action is taken depending on the event | ||
| 136 | # name. | ||
| 137 | # "Special" events (quit_panel/togglehidepanel/reload) are also handled | ||
| 138 | # here. | ||
| 139 | |||
| 140 | # wait for next event | ||
| 141 | IFS=$'\t' read -ra cmd || break | ||
| 142 | # find out event origin | ||
| 143 | case "${cmd[0]}" in | ||
| 144 | tag*) | ||
| 145 | #echo "resetting tags" >&2 | ||
| 146 | IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)" | ||
| 147 | ;; | ||
| 148 | date) | ||
| 149 | #echo "resetting date" >&2 | ||
| 150 | date="${cmd[@]:1}" | ||
| 151 | ;; | ||
| 152 | quit_panel) | ||
| 153 | exit | ||
| 154 | ;; | ||
| 155 | togglehidepanel) | ||
| 156 | currentmonidx=$(hc list_monitors | sed -n '/\[FOCUS\]$/s/:.*//p') | ||
| 157 | if [ "${cmd[1]}" -ne "$monitor" ] ; then | ||
| 158 | continue | ||
| 159 | fi | ||
| 160 | if [ "${cmd[1]}" = "current" ] && [ "$currentmonidx" -ne "$monitor" ] ; then | ||
| 161 | continue | ||
| 162 | fi | ||
| 163 | echo "^togglehide()" | ||
| 164 | if $visible ; then | ||
| 165 | visible=false | ||
| 166 | hc pad $monitor 0 | ||
| 167 | else | ||
| 168 | visible=true | ||
| 169 | hc pad $monitor $panel_height | ||
| 170 | fi | ||
| 171 | ;; | ||
| 172 | reload) | ||
| 173 | exit | ||
| 174 | ;; | ||
| 175 | focus_changed|window_title_changed) | ||
| 176 | windowtitle="${cmd[@]:2}" | ||
| 177 | ;; | ||
| 178 | #player) | ||
| 179 | # ;; | ||
| 180 | esac | ||
| 181 | done | ||
| 182 | |||
| 183 | ### dzen2 ### | ||
| 184 | # After the data is gathered and processed, the output of the previous block | ||
| 185 | # gets piped to dzen2. | ||
| 186 | |||
| 187 | } 2> /dev/null | dzen2 -w $panel_width -x $x -y $y -fn "$font" -h $panel_height \ | ||
| 188 | -e 'button3=;button4=exec:herbstclient use_index -1;button5=exec:herbstclient use_index +1' \ | ||
| 189 | -ta l -bg "$bgcolor" -fg '#efefef' | ||
