From b30acd13148b4b5174331580678bb5b0ce26e027 Mon Sep 17 00:00:00 2001 From: shmibs Date: Thu, 3 Jul 2014 11:26:07 -0700 Subject: complete theme revamp switched to bar, changed term colours, and added a config_vars file to make sourcing theme colours / fonts / etc easier --- .config/herbstluftwm/autostart | 9 +- .config/herbstluftwm/calc.sh | 6 +- .config/herbstluftwm/config_vars | 15 ++ .config/herbstluftwm/panel.sh | 405 +++++++++++++++++++-------------- .config/herbstluftwm/panel/conky_stats | 9 + .config/herbstluftwm/switcher.sh | 7 +- .config/herbstluftwm/tray.sh | 7 +- 7 files changed, 273 insertions(+), 185 deletions(-) create mode 100755 .config/herbstluftwm/config_vars create mode 100644 .config/herbstluftwm/panel/conky_stats (limited to '.config/herbstluftwm') diff --git a/.config/herbstluftwm/autostart b/.config/herbstluftwm/autostart index 1b714e6..968338c 100755 --- a/.config/herbstluftwm/autostart +++ b/.config/herbstluftwm/autostart @@ -1,6 +1,6 @@ #!/bin/bash -source ~/.config/herbstluftwm/colours.sh +source ~/.config/herbstluftwm/config_vars hc() { herbstclient "$@" @@ -138,9 +138,10 @@ hc keybind Mod4-Right spawn banshee --next hc keybind Mod4-Down spawn banshee --toggle-playing # dmenu -hc keybind Mod4-0 spawn dmenu_run -p "Run:" -h 18 -nb $bg_normal -nf $fg_normal -sb $bg_focus -sf $fg_focus -hc keybind Mod4-9 spawn ~/.config/herbstluftwm/switcher.sh $bg_normal $fg_normal $bg_focus $fg_focus -hc keybind Mod4-8 spawn ~/.config/herbstluftwm/calc.sh $bg_normal $fg_normal $bg_focus $fg_focus +hc keybind Mod4-0 spawn dmenu_run -fn $dfont -p "Run:" -h 18 -nb $bg_normal -nf $fg_normal \ + -sb $bg_focus -sf $fg_focus +hc keybind Mod4-9 spawn ~/.config/herbstluftwm/switcher.sh +hc keybind Mod4-8 spawn ~/.config/herbstluftwm/calc.sh ############## end launchers ############## diff --git a/.config/herbstluftwm/calc.sh b/.config/herbstluftwm/calc.sh index 142065e..88d31df 100755 --- a/.config/herbstluftwm/calc.sh +++ b/.config/herbstluftwm/calc.sh @@ -1,5 +1,7 @@ #!/bin/bash +source ~/.config/herbstluftwm/config_vars + acc=0 in="first" prompt="calc:" @@ -25,7 +27,9 @@ command_check() { } while [ "$in" != "" ]; do - in=$(echo "" | dmenu -q -h 18 -nb $1 -nf $2 -sb $3 -sf $4 -p "$prompt") + in=$(echo "" | dmenu -fn $efont -q -h $bheight \ + -nb $bg_normal -nf $fg_normal \ + -sb $bg_focus -sf $fg_focus -p "$prompt") if [[ $(command_check "$in" "$acc") -eq 1 ]]; then break fi diff --git a/.config/herbstluftwm/config_vars b/.config/herbstluftwm/config_vars new file mode 100755 index 0000000..d5d7dff --- /dev/null +++ b/.config/herbstluftwm/config_vars @@ -0,0 +1,15 @@ +#!/bin/bash + +bg_normal='#333333' +fg_normal='#efefef' +bg_focus='#00aad4' +fg_focus='#efefef' +bg_urgent='#ff4070' +fg_urgent='#efefef' + +fg_grey='#ababab' + +bheight=18 + +dfont='-*-fixed-medium-*-*-*-12-*-*-*-*-*-*-*' +efont='-*-tamsyn-medium-*-*-*-14-*-*-*-*-*-*-*' diff --git a/.config/herbstluftwm/panel.sh b/.config/herbstluftwm/panel.sh index e77cf87..8e1211f 100755 --- a/.config/herbstluftwm/panel.sh +++ b/.config/herbstluftwm/panel.sh @@ -1,5 +1,9 @@ #!/bin/bash +########### +# SETUP # +########### + hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;} monitor=${1:-0} geometry=( $(herbstclient monitor_rect "$monitor") ) @@ -8,189 +12,238 @@ if [ -z "$geometry" ] ;then exit 1 fi # geometry has the format W H X Y -x=${geometry[0]} -y=${geometry[1]} -panel_width=${geometry[2]} -panel_height=18 -font="-*-fixed-medium-*-*-*-12-*-*-*-*-*-*-*" -bgcolor=$(hc get frame_border_normal_color) -selbg=$(hc get window_border_active_color) -selfg='#fefefe' - -#### -# Try to find textwidth binary. -# In e.g. Ubuntu, this is named dzen2-textwidth. -if which textwidth &> /dev/null ; then - textwidth="textwidth"; -elif which dzen2-textwidth &> /dev/null ; then - textwidth="dzen2-textwidth"; -else - echo "This script requires the textwidth tool of the dzen2 project." - exit 1 -fi -#### -# true if we are using the svn version of dzen2 -# depending on version/distribution, this seems to have version strings like -# "dzen-" or "dzen-x.x.x-svn" -if dzen2 -v 2>&1 | head -n 1 | grep -q '^dzen-\([^,]*-svn\|\),'; then - dzen2_svn="true" -else - dzen2_svn="" -fi +xpos=${geometry[0]} +ypos=${geometry[1]} +width=${geometry[2]} -if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then - # mawk needs "-W interactive" to line-buffer stdout correctly - # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504 - uniq_linebuffered() { - awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@" - } -else - # other awk versions (e.g. gawk) issue a warning with "-W interactive", so - # we don't want to use it there. - uniq_linebuffered() { - awk '$0 != l { print ; l=$0 ; fflush(); }' "$@" - } -fi +# grab standardised colours +source ~/.config/herbstluftwm/config_vars -hc pad $monitor $panel_height +# set alpha for background colours +alpha='#ff' +bg_normal=$(echo -n $alpha; echo "$bg_normal" | tr -d '#') +fg_normal=$(echo -n '#ff'; echo "$fg_normal" | tr -d '#') +bg_focus=$(echo -n $alpha; echo "$bg_focus" | tr -d '#') +fg_focus=$(echo -n '#ff'; echo "$fg_focus" | tr -d '#') +bg_urgent=$(echo -n '#ff'; echo "$bg_urgent" | tr -d '#') +fg_urgent=$(echo -n '#ff'; echo "$fg_urgent" | tr -d '#') -{ - ### Event generator ### - # based on different input data (mpc, date, hlwm hooks, ...) this generates events, formed like this: - # \t [...] - # e.g. - # date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29 - - #mpc idleloop player & - - while true ; do - # "date" output is checked once a second, but an event is only - # generated if the output changed compared to the previous run. - date +$'date\t^fg(#efefef)%a, %b %d, %H:%M' - sleep 1 || break - done > >(uniq_linebuffered) & - childpid=$! - hc --idle - kill $childpid -} 2> /dev/null | { - IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)" - visible=true - date="" - clients="" - focus_index="" - while true ; do - - ### Output ### - # This part prints dzen data based on the _previous_ data handling run, - # and then waits for the next event to happen. - - bordercolor="#26221C" - separator="^bg()^fg($selbg)|" - # draw tags - for i in "${tags[@]}" ; do - case ${i:0:1} in - '#') - echo -n "^bg($selbg)^fg($selfg)" - ;; - '+') - echo -n "^bg(#9CA668)^fg(#141414)" - ;; - ':') - echo -n "^bg()^fg(#ffffff)" - ;; - '!') - echo -n "^bg(#FF0675)^fg(#141414)" - ;; - *) - echo -n "^bg()^fg(#ababab)" - ;; - esac - # non-clickable tags, because i don't care - echo -n " ${i:1} " - done - echo -n "$separator^fg()" - - for i in "${!clients[@]}"; do - if [ $i -eq $focus_index ]; then - echo -n "^bg($selbg)^fg($selfg) ${clients[i]} ^bg()^fg()" - else - echo -n " ${clients[i]} " - fi +fg_grey=$(echo -n '#ff'; echo "$fg_grey" | tr -d '#') + +hc pad $monitor $bheight + +# global content variables +winlist="" + + + +################# +# SUBROUTINES # +################# + +# functions for retrieving and processing data +# upon events + +update_taglist() { + echo -n "%{l}%{B${bg_normal} F${fg_normal} U${fg_normal}}" + hc tag_status | tr '\t' '\n' | sed \ + -e '1d' \ + -e '$d' \ + -e 's/\(.*\)/\1 /' \ + -e 's/:/ /' \ + -e "s/[#+\-%]\(.*\)/%{B${bg_focus} F${fg_focus}} \1%{B${bg_normal} F${fg_normal}}/" \ + -e "s/!\(.*\)/%{B${bg_urgent} F${fg_urgent}} \1%{B${bg_normal} F${fg_normal}}/" \ + -e "s/\.\(.*\)/%{B${bg_normal} F${fg_grey}} \1%{B${bg_normal} F${fg_normal}}/" \ + | tr -d '\n' + echo "%{F${bg_focus}}|%{F${fg_normal}}" +} + +update_winlist() { + focus_id=$(hc get_attr clients.focus.winid) + + if [[ "$focus_id" == "" ]]; then + return + fi + + # grab current window list, limit to current desktop, + # clean up output, cut to length,add focused window + # formatting, and finally delete win ids and merge + # lines + + for c in $(herbstclient layout | grep -Eo '0x[0-9a-f]*'); do + xwininfo -id $c | sed -n 2p | sed -e 's/"//' -e 's/"$//' -e 's/$/\t/' | cut -c -70 | sed \ + -e 's/xwininfo: Window id: //' \ + -e 's/$/.../' -e 's/\t\.\.\.$//' \ + -e "s/${focus_id} \(.*\)/%{B${bg_focus} F${fg_focus}} \1 %{B${bg_normal} F${fg_normal}}/" \ + -e 's/0x[a-f0-9]* \(.*\)/ \1 /' | tr -d '\n' done +} + + + +####################### +# OUTPUT CONTAINERS # +####################### + +# all fields are put in separate elements + +# tag list +fields[1]=$(update_taglist) +# window list +fields[2]=$(update_winlist) +# align right +fields[3]="%{r}" +# when +fields[4]="" +# banshee np +fields[5]="" +# conky stats +fields[6]="" +# date +fields[7]="" +# vertical separator and gap for tray +fields[8]="%{F${bg_focus}}| %{F${fg_normal}}" - # small adjustments - right="$separator^bg() $date $separator" - right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g') - # get width of right aligned text.. and add some space.. - width=$($textwidth "$font" "$right_text_only ") - echo -n "^pa($(($panel_width - $width)))$right" - echo - - ### Data handling ### - # This part handles the events generated in the event loop, and sets - # internal variables based on them. The event and its arguments are - # read into the array cmd, then action is taken depending on the event - # name. - # "Special" events (quit_panel/togglehidepanel/reload) are also handled - # here. - - # wait for next event - IFS=$'\t' read -ra cmd || break - # find out event origin - case "${cmd[0]}" in - tag*) - #echo "resetting tags" >&2 - IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)" - ;; - date) - #echo "resetting date" >&2 - date="${cmd[@]:1}" - ;; - quit_panel) - exit - ;; - togglehidepanel) - currentmonidx=$(hc list_monitors | sed -n '/\[FOCUS\]$/s/:.*//p') - if [ "${cmd[1]}" -ne "$monitor" ] ; then - continue - fi - if [ "${cmd[1]}" = "current" ] && [ "$currentmonidx" -ne "$monitor" ] ; then - continue - fi - echo "^togglehide()" - if $visible ; then - visible=false - hc pad $monitor 0 - else - visible=true - hc pad $monitor $panel_height - fi - ;; - reload) - exit - ;; - focus_changed|window_title_changed) - clients=($(herbstclient layout | grep -Eo '0x[0-9a-f]*')) focus_client=$(herbstclient get_attr clients.focus.winid) - focus_index="" - hc_args="herbstclient chain" - for i in "${!clients[@]}"; do - if [ "${clients[i]}" == "$focus_client" ]; then - focus_index=$i + +###################### +# EVENT GENERATORS # +###################### + +# loops for generating a line of information, +# with the first element in the line as a +# unique identifier for the event type + +get_stat() { + { + conky -c ~/.config/herbstluftwm/panel/conky_stats + # suppress lines that do not differ from + # previous lines + } | awk '$0 != l { print ; l=$0 ; fflush(); }' +} + +get_date() { + { + while true; do + date +$'date\t%a, %b %d, %H:%M:%S' + sleep 1 + done + } | awk '$0 != l { print ; l=$0 ; fflush(); }' +} + +get_when() { + { + while true; do + if [[ "$(when --future=1 | sed '1,2d')" == "" ]]; then + echo -e 'when\t0' + else + echo -e 'when\t1' fi - hc_args="$hc_args"" .-. get_attr clients.""${clients[i]}"".instance .-. echo" + sleep 10 done + } | awk '$0 != l { print ; l=$0 ; fflush(); }' +} + + + +####################### +# EVENT MULTIPLEXER # +####################### + +# the loops defined above are launched and +# their outputs multiplexed + +{ + get_stat & + child[1]=$! + get_date & + child[2]=$! + get_when & + child[3]=$! + + hc --idle + + for id in ${child[@]}; do + kill $id + done +} 2> /dev/null | { + + + +################## +# EVENT PARSER # +################## - clients=($($hc_args)) - ;; - #player) - # ;; - esac - done +# those lines are then read, one by one, +# and the information contained used to +# generate the required fields - ### dzen2 ### - # After the data is gathered and processed, the output of the previous block - # gets piped to dzen2. + while true; do + + # split our read lines into an array + # for easy parsing + IFS=$'\t' read -ra event || break + + # determine event type and act + # accordingly + case "${event[0]}" in + date) + fields[7]="%{F${bg_focus}}|%{F${fg_normal} A:date:} ${event[@]:1} %{A}" + ;; + stats) + fields[6]="%{F${bg_focus}}|%{F${fg_normal} A:stats:} ${event[@]:1} %{A}" + ;; + when) + if [[ "${events[1]}" -eq 1 ]]; then + fields[4]="%{F${bg_focus}}|%{F${fg_normal} A:when:} * %{A}" + else + fields[4]="" + fi + ;; -} 2> /dev/null | dzen2 -w $panel_width -x $x -y $y -fn "$font" -h $panel_height \ - -e 'button3=;button4=exec:herbstclient use_index -1;button5=exec:herbstclient use_index +1' \ - -ta l -bg "$bgcolor" -fg '#efefef' + # hc events + focus_changed|window_title_changed) + fields[2]=$(update_winlist) + ;; + tag_changed|tag_flags) + fields[1]=$(update_taglist) + fields[2]=$(update_winlist) + ;; + + *) + ;; + esac + + # i wish i could just print the entire array + # this easily, but that inserts spaces + #echo "${fields[@]}" + echo -n "${fields[1]}${fields[2]}${fields[3]}${fields[4]}" + echo "${fields[5]}${fields[6]}${fields[7]}${fields[8]}" + + done + + # pass the events into bar +} 2> /dev/null | bar -f $dfont -g${width}x${bheight}+${xpos}+${ypos} \ + -B ${bg_normal} -F ${fg_normal} | \ +{ + +##################### +# COMMAND HANDLER # +##################### + +# finally, take the output from bar and execute commands + while read command; do + case "$command" in + date) + notify-send "$(cal)" + ;; + stats) + urxvt -e htop + ;; + when) + notify-send "$(when)" + ;; + *) + ;; + esac + done +} diff --git a/.config/herbstluftwm/panel/conky_stats b/.config/herbstluftwm/panel/conky_stats new file mode 100644 index 0000000..a425958 --- /dev/null +++ b/.config/herbstluftwm/panel/conky_stats @@ -0,0 +1,9 @@ +background no +out_to_console yes +out_to_x no +update_interval 2.0 +total_run_times 0 +use_spacer none + +TEXT +stats mem: %%${memperc} cpu: %%${cpu cpu0} diff --git a/.config/herbstluftwm/switcher.sh b/.config/herbstluftwm/switcher.sh index 4d570c2..a19fe6e 100755 --- a/.config/herbstluftwm/switcher.sh +++ b/.config/herbstluftwm/switcher.sh @@ -1,7 +1,12 @@ #!/bin/zsh +source ~/.config/herbstluftwm/config_vars + IFS=$'\r\n' clients=($(wmctrl -l | cut -c -10)) -number=$(wmctrl -l | cut -c 20- | nl -w 2 -s ") " | dmenu -i -h 18 -nb $1 -nf $2 -sb $3 -sf $4 -p "Select:" -l 40 | grep -oE '[0-9]' | head -1) +number=$(wmctrl -l | cut -c 20- | nl -w 2 -s ") " | \ + dmenu -fn $efont -i -h $bheight -nb $bg_normal -nf $fg_normal \ + -sb $bg_focus -sf $fg_focus -p "Select:" -l 40 | \ + grep -oE '[0-9]' | head -1) if [ $number ]; then herbstclient jumpto ${clients[$(expr $number - 1)]} fi diff --git a/.config/herbstluftwm/tray.sh b/.config/herbstluftwm/tray.sh index cef5fb5..61e6310 100755 --- a/.config/herbstluftwm/tray.sh +++ b/.config/herbstluftwm/tray.sh @@ -1,12 +1,13 @@ #!/bin/bash hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;} -bgcolor=$(hc get frame_border_normal_color) + +source ~/.config/herbstluftwm/config_vars run="" while [ -z "$run" ]; do sleep .5 - run=$(ps -e | grep dzen2) + run=$(ps -e | grep bar) echo "$run" done -trayer --edge top --align right --heighttype pixel --height 18 --widthtype pixel --width 18 --distancefrom right --distance 4 +trayer --edge top --align right --heighttype pixel --height $bheight --widthtype pixel --width $bheight --distancefrom right --distance 4 -- cgit v1.2.3