blob: a42ea1e2768a1a5a9af342a4dc69f05f6783ccf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#!/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_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
# Check which tag the monitor is on now
monitor_tag="$(herbstclient attr "monitors.$monitor.tag")"
# 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"
|