Super hacky shell wrapper around lemonbar that aims to poll as little as possible, minimising bar updates to the screen and reduce resource usage.
git clone https://mcol.xyz/code/lemontools
Log | Files | Refs | README | LICENSE

commit 5a4eb21bbc1d6bb0d7454b166f65e2549a2d63a4
parent e63da256fd12df7a4b521ffd68e159ee0d9ec643
Author: mcol <mcol@posteo.net>
Date:   Tue,  8 Jan 2019 22:59:12 +0000

made function to deal with clicks so modules only output what is needed and no redundant text

Diffstat:
Mmodules | 23++++++++++++++++++++++-
Mstart-lemonbar | 93+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Mthemes/fisherman.bar | 7+++++--
3 files changed, 83 insertions(+), 40 deletions(-)

diff --git a/modules b/modules @@ -128,13 +128,34 @@ _bspwm() { } -_mpc() { +_mpctest() { if ! which mpc > /dev/null then echo "mpc=" > $fifo return fi + get_clicks mpc + + while true; do + if pgrep mpd > /dev/null + then + current=$(/usr/bin/mpc current | sed "s/'/''/g") + echo "mpctest='${mpc_pre}${current}${mpc_post}'" + mpc idle player > /dev/null + else + sleep 30 + fi + done > "$fifo" +} + + +_mpc() { + if ! which mpc > /dev/null + then + echo "mpc=" > $fifo + return + fi while true; do if pgrep mpd > /dev/null then diff --git a/start-lemonbar b/start-lemonbar @@ -45,8 +45,31 @@ exit sleep_until() { - seconds=$(( $(date -d "$*" +%s) - $(date +%s) )) # Use $* to eliminate need for quotes - sleep $seconds + local seconds=$(( $(date -d "$*" +%s) - $(date +%s) )) # Use $* to eliminate need for quotes + sleep $seconds +} + + +get_clicks() { + # Give this the module name and it will return the prefix and suffix + # required for specified click commands + local mod=$1 + local pre= + local post= + opts=(click_${mod} click_${mod}_2 click_${mod}_3 scroll_${mod}_u scroll_${mod}_d) + + for i in {1..5} + do + # if a click variable has been set, add it + if eval "[ -n \"\$${opts[(($i-1))]}\" ]" + then + pre=${pre}%{A$i:${!opts[(($i-1))]}:} + post=${post}%{A} + fi + done + + eval ${mod}_pre=\"$pre\" + eval ${mod}_post=\"$post\" } @@ -121,10 +144,10 @@ start_feed() { start_bar() { printf "Lemonbar started.\n" start_feed | $bar | while read msg - do - # execute outputs from bar, logging to $logfile - $msg &> $logfile & - done +do + # execute outputs from bar, logging to $logfile + $msg &> $logfile & +done } @@ -214,45 +237,41 @@ done #---------------------------------------------------------------------------------- -# Construct bar command -#---------------------------------------------------------------------------------- - -# path to binary can be given as bar_path, or defaults to 'lemonbar' -bar=${bar_path:-lemonbar} -bar+=' -p' - -# bar is placed at bottom of screen if $bottom = true -[[ $bottom == true ]] && bar+=' -b' - -# bar geometry -# this was an undocumented fix I may have to fix if I don't want 100% width -[[ $num_monitors > 1 ]] && width= -bar+=" -g ${width}x${height}+${posx}+${posy}" - -# colours, if specified in theme -[[ -n "$background" ]] && bar+=" -B $background" # background colour -[[ -n "$foreground" ]] && bar+=" -F $foreground" # foreground colour -[[ -n "$underline" ]] && bar+=" -U $underline" # underline colour - -# fonts, defaulting to Liberation Sans, size 9, with optional fallback font -bar+=" -f ${font:-LiberationSans}-${font_size:-9}" -[[ -n "$font2" ]] && bar+=" -f $font2-${font_size2:-9}" - -# max clickable_areas defaults to 20 but can be specified in theme -bar+=" -a ${clickable_areas:-20}" - - - -#---------------------------------------------------------------------------------- -# Run! +# Construct and run bar #---------------------------------------------------------------------------------- if ${debug:-false} then start_feed else + # path to binary can be given as bar_path, or defaults to 'lemonbar' + bar=${bar_path:-lemonbar} + bar+=' -p' + + # bar is placed at bottom of screen if $bottom = true + [[ $bottom == true ]] && bar+=' -b' + + # bar geometry + # this was an undocumented fix I may have to fix if I don't want 100% width + [[ $num_monitors > 1 ]] && width= + bar+=" -g ${width}x${height}+${posx}+${posy}" + + # colours, if specified in theme + [[ -n "$background" ]] && bar+=" -B $background" # background colour + [[ -n "$foreground" ]] && bar+=" -F $foreground" # foreground colour + [[ -n "$underline" ]] && bar+=" -U $underline" # underline colour + + # fonts, defaulting to Liberation Sans, size 9, with optional fallback font + bar+=" -f ${font:-LiberationSans}-${font_size:-9}" + [[ -n "$font2" ]] && bar+=" -f $font2-${font_size2:-9}" + + # max clickable_areas defaults to 20 but can be specified in theme + bar+=" -a ${clickable_areas:-20}" + + # start bar start_bar fi + # vim: filetype=sh diff --git a/themes/fisherman.bar b/themes/fisherman.bar @@ -22,13 +22,16 @@ margin_l='' margin_r='' modules_l=( bspwm ) -modules_c=( mpc ) +modules_c=( mpctest ) modules_r=( headphones servers wireguard battery longdate clock ) click_clock=urxvt click_wireguard=nmcli_rofi -click_mpc='scratch -g cantata' click_longdate= +click_mpc='scratch -g cantata' +click_mpc_r='mpd-ctrl -n toggle' +scroll_mpc_u='mpd-ctrl -n prev' +scroll_mpc_d='mpd-ctrl -n next' bspwm_focussed_bg=$foreground bspwm_focussed_fg=$background