Merge panel into herbstluftwm autostart.

Commit
442a79af7ca18cd2fc442d51ba2cc0b80ad066c9
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
panel.sh
index 88f56ef0..00000000 100755..000000
@@ -1,191 +0,0 @@
1 Removed: #!/usr/bin/env bash
2 Removed:
3 Removed: quote() {
4 Removed: local q="$(printf '%q ' "$@")"
5 Removed: printf '%s' "${q% }"
6 Removed: }
7 Removed:
8 Removed:
9 Removed: hc_quoted="$(quote "${herbstclient_command[@]:-herbstclient}")"
10 Removed: hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
11 Removed: monitor=${1:-0}
12 Removed: geometry=( $(hc monitor_rect "$monitor") )
13 Removed: if [ -z "$geometry" ] ;then
14 Removed: echo "Invalid monitor $monitor"
15 Removed: exit 1
16 Removed: fi
17 Removed: # geometry has the format W H X Y
18 Removed: x=${geometry[0]}
19 Removed: y=${geometry[1]}
20 Removed: panel_width=${geometry[2]}
21 Removed: panel_height=32
22 Removed: font="-*-hack-*-*-*-*-12-*-*-*-*-*-*-*"
23 Removed: # extract colors from hlwm and omit alpha-value
24 Removed: bgcolor=$(hc get frame_border_normal_color|sed 's,^\(\#[0-9a-f]\{6\}\)[0-9a-f]\{2\}$,\1,')
25 Removed: selbg=$(hc get window_border_active_color|sed 's,^\(\#[0-9a-f]\{6\}\)[0-9a-f]\{2\}$,\1,')
26 Removed: selfg='#101010'
27 Removed:
28 Removed: ####
29 Removed: # Try to find textwidth binary.
30 Removed: # In e.g. Ubuntu, this is named dzen2-textwidth.
31 Removed: if which textwidth &> /dev/null ; then
32 Removed: textwidth="textwidth";
33 Removed: elif which dzen2-textwidth &> /dev/null ; then
34 Removed: textwidth="dzen2-textwidth";
35 Removed: elif which xftwidth &> /dev/null ; then # For guix
36 Removed: textwidth="xftwidth";
37 Removed: else
38 Removed: echo "This script requires the textwidth tool of the dzen2 project."
39 Removed: exit 1
40 Removed: fi
41 Removed: ####
42 Removed: # true if we are using the svn version of dzen2
43 Removed: # depending on version/distribution, this seems to have version strings like
44 Removed: # "dzen-" or "dzen-x.x.x-svn"
45 Removed: if dzen2 -v 2>&1 | head -n 1 | grep -q '^dzen-\([^,]*-svn\|\),'; then
46 Removed: dzen2_svn="true"
47 Removed: else
48 Removed: dzen2_svn=""
49 Removed: fi
50 Removed:
51 Removed: if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then
52 Removed: # mawk needs "-W interactive" to line-buffer stdout correctly
53 Removed: # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504
54 Removed: uniq_linebuffered() {
55 Removed: awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@"
56 Removed: }
57 Removed: else
58 Removed: # other awk versions (e.g. gawk) issue a warning with "-W interactive", so
59 Removed: # we don't want to use it there.
60 Removed: uniq_linebuffered() {
61 Removed: awk '$0 != l { print ; l=$0 ; fflush(); }' "$@"
62 Removed: }
63 Removed: fi
64 Removed:
65 Removed: hc pad $monitor $panel_height
66 Removed:
67 Removed: {
68 Removed: ### Event generator ###
69 Removed: # based on different input data (mpc, date, hlwm hooks, ...) this generates events, formed like this:
70 Removed: # <eventname>\t<data> [...]
71 Removed: # e.g.
72 Removed: # date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29
73 Removed:
74 Removed: #mpc idleloop player &
75 Removed: while true ; do
76 Removed: # "date" output is checked once a second, but an event is only
77 Removed: # generated if the output changed compared to the previous run.
78 Removed: date +$'date\t^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d'
79 Removed: sleep 1 || break
80 Removed: done > >(uniq_linebuffered) &
81 Removed: childpid=$!
82 Removed: hc --idle
83 Removed: kill $childpid
84 Removed: } 2> /dev/null | {
85 Removed: IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
86 Removed: visible=true
87 Removed: date=""
88 Removed: windowtitle=""
89 Removed: while true ; do
90 Removed:
91 Removed: ### Output ###
92 Removed: # This part prints dzen data based on the _previous_ data handling run,
93 Removed: # and then waits for the next event to happen.
94 Removed:
95 Removed: separator="^bg()^fg($selbg)|"
96 Removed: # draw tags
97 Removed: for i in "${tags[@]}" ; do
98 Removed: case ${i:0:1} in
99 Removed: '#')
100 Removed: echo -n "^bg($selbg)^fg($selfg)"
101 Removed: ;;
102 Removed: '+')
103 Removed: echo -n "^bg(#9CA668)^fg(#141414)"
104 Removed: ;;
105 Removed: ':')
106 Removed: echo -n "^bg()^fg(#ffffff)"
107 Removed: ;;
108 Removed: '!')
109 Removed: echo -n "^bg(#FF0675)^fg(#141414)"
110 Removed: ;;
111 Removed: *)
112 Removed: echo -n "^bg()^fg(#ababab)"
113 Removed: ;;
114 Removed: esac
115 Removed: if [ ! -z "$dzen2_svn" ] ; then
116 Removed: # clickable tags if using SVN dzen
117 Removed: echo -n "^ca(1,$hc_quoted focus_monitor \"$monitor\" && "
118 Removed: echo -n "$hc_quoted use \"${i:1}\") ${i:1} ^ca()"
119 Removed: else
120 Removed: # non-clickable tags if using older dzen
121 Removed: echo -n " ${i:1} "
122 Removed: fi
123 Removed: done
124 Removed: echo -n "$separator"
125 Removed: echo -n "^bg()^fg() ${windowtitle//^/^^}"
126 Removed: # small adjustments
127 Removed: right="$separator^bg() $date $separator"
128 Removed: right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g')
129 Removed: # get width of right aligned text.. and add some space..
130 Removed: width=$($textwidth "$font" "$right_text_only ")
131 Removed: echo -n "^pa($(($panel_width - $width)))$right"
132 Removed: echo
133 Removed:
134 Removed: ### Data handling ###
135 Removed: # This part handles the events generated in the event loop, and sets
136 Removed: # internal variables based on them. The event and its arguments are
137 Removed: # read into the array cmd, then action is taken depending on the event
138 Removed: # name.
139 Removed: # "Special" events (quit_panel/togglehidepanel/reload) are also handled
140 Removed: # here.
141 Removed:
142 Removed: # wait for next event
143 Removed: IFS=$'\t' read -ra cmd || break
144 Removed: # find out event origin
145 Removed: case "${cmd[0]}" in
146 Removed: tag*)
147 Removed: #echo "resetting tags" >&2
148 Removed: IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
149 Removed: ;;
150 Removed: date)
151 Removed: #echo "resetting date" >&2
152 Removed: date="${cmd[@]:1}"
153 Removed: ;;
154 Removed: quit_panel)
155 Removed: exit
156 Removed: ;;
157 Removed: togglehidepanel)
158 Removed: currentmonidx=$(hc list_monitors | sed -n '/\[FOCUS\]$/s/:.*//p')
159 Removed: if [ "${cmd[1]}" -ne "$monitor" ] ; then
160 Removed: continue
161 Removed: fi
162 Removed: if [ "${cmd[1]}" = "current" ] && [ "$currentmonidx" -ne "$monitor" ] ; then
163 Removed: continue
164 Removed: fi
165 Removed: echo "^togglehide()"
166 Removed: if $visible ; then
167 Removed: visible=false
168 Removed: hc pad $monitor 0
169 Removed: else
170 Removed: visible=true
171 Removed: hc pad $monitor $panel_height
172 Removed: fi
173 Removed: ;;
174 Removed: reload)
175 Removed: exit
176 Removed: ;;
177 Removed: focus_changed|window_title_changed)
178 Removed: windowtitle="${cmd[@]:2}"
179 Removed: ;;
180 Removed: #player)
181 Removed: # ;;
182 Removed: esac
183 Removed: done
184 Removed:
185 Removed: ### dzen2 ###
186 Removed: # After the data is gathered and processed, the output of the previous block
187 Removed: # gets piped to dzen2.
188 Removed:
189 Removed: } 2> /dev/null | dzen2 -w $panel_width -x $x -y $y -fn "$font" -h $panel_height \
190 Removed: -e "button3=;button4=exec:$hc_quoted use_index -1;button5=exec:$hc_quoted use_index +1" \
191 Removed: -ta l -bg "$bgcolor" -fg '#efefef'