#!/usr/bin/env bash hc() { "${herbstclient_command[@]:-herbstclient}" "$@" } monitor_bound() { echo "$1" | cut -d' ' -f2 } hlwm_id() { while read -r bound; do hc list_monitors | grep "$bound" | sed -e 's/:.*$//g' done <<< "$(monitor_bound "$1")" } echo "${MONITOR:?"Polybar should set the MONITOR variable"}" this_monitor=$(polybar -m | grep "$MONITOR") monitor=$(hlwm_id "$this_monitor") get_layout() { current_layout=$(hc get_attr tags.focus.tiling.focused_frame.algorithm) case "$current_layout" in vertical) echo "V" ;; horizontal) echo "H" ;; max) echo "M" ;; grid) echo "G" ;; esac } layout=$(get_layout) herbstclient --idle "(tag_*|(focus|window_title|attribute)_changed)" 2>/dev/null | { while true; do # Read tags into $tags array IFS=$'\t' read -ra tags <<< "$(hc tag_status "$monitor")" { # Read the prefix from each tag for i in "${tags[@]}" ; do case ${i:1} in 'fl') ;& 'hidden') ;& 'scratchpad') continue ;; esac case ${i:0:1} in '#') echo -n "%{B#9fbc00}%{F#101010}" # Tag in focus on this monitor ;; '%') echo -n "%{B#9ca668}%{F#141414}" # Tag in focus on other monitor ;; '+') echo -n "%{B#9ca668}%{F#141414}" # tag viewed on this monitor ;; '-') echo -n "%{B#9ca668}%{F#141414}" # Tag viewed on other monitor ;; ':') echo -n "%{B#222}%{F#ffffff}" # Tag is not empty ;; '!') echo -n "%{B#ff0675}%{F#141414}" # Tag contains urgent window ;; *) echo -n "%{B#222}%{F#7a7a7a}" ;; esac echo "%{A1:herbstclient and . focus_monitor $monitor . use ${i:1}:} ${i:1} %{A -u -o F- B-}" done echo "%{F-}%{B-}" echo "| [$layout]" } | tr -d "\n" echo IFS=$'\t' read -ra cmd || break case "${cmd[0]}" in #focus_changed|window_title_changed) # layout=$(get_layout) ;; attribute_changed) if [[ "${cmd[1]}" == "tags.focus.tiling.focused_frame.algorithm" ]]; then case "${cmd[3]}" in vertical) layout="V" ;; horizontal) layout="H" ;; max) layout="M" ;; grid) layout="G" ;; esac #layout="${cmd[3]}" fi esac # wait for next event from herbstclient --idle # read -r || break done } 2>/dev/null