aboutsummaryrefslogtreecommitdiff
path: root/.config/herbstluftwm/panel-bot.sh
diff options
context:
space:
mode:
Diffstat (limited to '.config/herbstluftwm/panel-bot.sh')
-rwxr-xr-x.config/herbstluftwm/panel-bot.sh84
1 files changed, 84 insertions, 0 deletions
diff --git a/.config/herbstluftwm/panel-bot.sh b/.config/herbstluftwm/panel-bot.sh
new file mode 100755
index 0000000..4a3bc18
--- /dev/null
+++ b/.config/herbstluftwm/panel-bot.sh
@@ -0,0 +1,84 @@
+#!/usr/bin/env bash
+
+hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ; }
+quote() { local q="$(printf '%q ' "$@")"; printf '%s' "${q% }" ; }
+uniq_linebuffered() { awk '$0 != l { print ; l=$0 ; fflush(); }' "$@"; }
+
+monitor=${1:-0}
+
+hc attr "monitors.$monitor" > /dev/null || { printf "Invalid monitor $monitor" && exit 1 ; }
+
+monitor_tag="$(herbstclient attr "monitors.$monitor.tag")"
+monitor_offset_x=$(hc monitor_rect "$monitor" | awk '{print $1 }')
+monitor_offset_y=$(hc monitor_rect "$monitor" | awk '{print $2 }')
+monitor_width=$(hc monitor_rect "$monitor" | awk '{ print $3 }')
+monitor_height=$(hc monitor_rect "$monitor" | awk '{ print $4 }')
+panel_height=21
+panel_color_bg="$(hc get frame_border_normal_color)"
+panel_color_fg="#efefef"
+panel_color_focus="$(hc get frame_border_active_color)"
+panel_font="Liberation Mono:size=9"
+panel_offset_x=$(( monitor_offset_x ))
+panel_offset_y=$(( monitor_offset_y + monitor_height - panel_height ))
+
+{
+ hc --idle
+} 2> /dev/null | {
+ while :
+ do
+ # Wait for an event
+ IFS=$'\t' read -ra event || break
+
+ # Declare clients as an array
+ declare -a clients
+
+ # Collect all clients on the monitor
+ for client in $(hc attr clients | grep '0x')
+ do
+ [[ "$(hc attr "clients.$client.tag")" != $monitor_tag ]] && continue
+
+ clients+=("$client")
+ done
+
+ name_offset_interval=$(( monitor_width / ${#clients[@]} ))
+
+ # Look up current focus window
+ focus="$(hc attr clients.focus.winid)"
+
+ # Loop through the clients to create a representation
+ index=0
+
+ for client in "${clients[@]}"
+ do
+
+ if [[ "$client" == "$focus." ]]
+ then
+ color_fg="$panel_color_focus"
+ else
+ color_fg="$panel_color_fg"
+ fi
+
+ name=" $(hc attr "clients.$client.title") "
+ name_width=$(xftwidth "$panel_font" "$name")
+ name_offset=$(( name_offset_interval * index ))
+
+ printf "^pa(%s)^bg(%s)^fg(%s)^ca(1,%s)%s^ca()" \
+ "$name_offset" \
+ "$panel_color_bg" \
+ "$color_fg" \
+ "herbstclient jumpto '$client'" \
+ "$name"
+
+ index=$(( index + 1 ))
+ done
+
+ # Add a newline
+ printf "\n"
+
+ # Clean up some variables
+ unset clients
+ unset index
+ done
+} | dzen2 -w "$monitor_width" -x "$panel_offset_x" -y "$panel_offset_y" -fn "$panel_font" -h "$panel_height" \
+ -e "button3=;button4=exec:$hc_quoted use_index -1;button5=exec:$hc_quoted use_index +1" \
+ -ta l -bg "$panel_color_bg" -fg "$panel_color_fg"