-
Notifications
You must be signed in to change notification settings - Fork 2
/
bspwm_panel
executable file
·263 lines (235 loc) · 8.19 KB
/
bspwm_panel
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
PANEL_FIFO=/tmp/panel-fifo
PANEL_HEIGHT=24
if [[ -n "$CHROMEBOOK" ]]; then
PANEL_WIDTH=1366
else
PANEL_WIDTH=1920
fi
PANEL_FONT_FAMILY="-*-terminus-*-r-normal-*-18-*-*-*-c-*-*-1"
ALPHA_BLACK='#80000000'
RED='#FFFF0000'
WHITE='#FFFFFFFF'
COLOR_FOREGROUND=$WHITE
COLOR_BACKGROUND=$ALPHA_BLACK
#COLOR_ACTIVE_MONITOR_FG='#FFFFFF00'
COLOR_ACTIVE_MONITOR_FG='#FFFFA500'
COLOR_ACTIVE_MONITOR_BG=$ALPHA_BLACK
COLOR_INACTIVE_MONITOR_FG='#FFFF0000'
COLOR_INACTIVE_MONITOR_BG=$ALPHA_BLACK
#COLOR_FOCUSED_OCCUPIED_FG='#FF00FF00'
#COLOR_FOCUSED_OCCUPIED_BG='#FF585858'
COLOR_FOCUSED_OCCUPIED_FG='#FFFFA500'
COLOR_FOCUSED_OCCUPIED_BG=$ALPHA_BLACK
#COLOR_FOCUSED_FREE_FG='#FF00FF00'
#COLOR_FOCUSED_FREE_BG='#FF585858'
COLOR_FOCUSED_FREE_FG='#FFFFA500'
COLOR_FOCUSED_FREE_BG=$ALPHA_BLACK
COLOR_OCCUPIED_FG=$WHITE
COLOR_OCCUPIED_BG=$ALPHA_BLACK
COLOR_FREE_FG='#FF000000'
#COLOR_FREE_FG='#FF585858'
COLOR_FREE_BG=$ALPHA_BLACK
COLOR_FOCUSED_URGENT_FG='#FF000000'
COLOR_FOCUSED_URGENT_BG='#FFFF0000'
COLOR_URGENT_FG='#FF000000'
COLOR_URGENT_BG='#FFFF0000'
COLOR_LAYOUT_FG='#FF00FFFF'
COLOR_LAYOUT_BG=$ALPHA_BLACK
COLOR_TITLE_FG=$WHITE
COLOR_TITLE_BG=$ALPHA_BLACK
COLOR_STATUS_FG=$WHITE
COLOR_STATUS_BG=$ALPHA_BLACK
sep="%{F#FF005FAF}--%{F-}"
#obrack="%{F#FF585858}[%{F-}"
#cbrack="%{F#FF585858}]%{F-}"
obrack="%{F#FF000000}[%{F-}"
cbrack="%{F#FF000000}]%{F-}"
if [[ $(pgrep -cx panel) -gt 1 ]]; then
printf "The panel is already running.\n" >&2
exit 1
fi
function handle_signal()
{
bspc config -m ^1 top_padding 0
rm -f "$PANEL_FIFO"
trap - TERM
kill 0
}
trap 'handle_signal' INT TERM QUIT EXIT
[[ -e "$PANEL_FIFO" ]] && rm -f "$PANEL_FIFO"
mkfifo "$PANEL_FIFO"
#bspc config -m ^1 top_padding $PANEL_HEIGHT
bspc config top_padding $PANEL_HEIGHT
function memory_usage()
{
while true; do
#printf("%d %d %d %d %d\n",
# (100 - ((mfree / mtotal) * 100)), # mem used
# ( (mactive / mtotal) * 100), # mem active
# ( (minactive / mtotal) * 100), # mem inactive
# ( (mcached / mtotal) * 100), # mem cached
# (100 - ((swfree / swtotal) * 100))); # swap used
awk '/MemTotal:/ {mtotal=$2}; # total usable ram
/MemFree:/ {mfree=$2}; # total ram that is free
/Active:/ {mactive=$2}; # total ram that is active/used
/Inactive:/ {minactive=$2}; # total ram that is inactive/unused
/^Cached:/ {mcached=$2}; # total ram used for caching
/SwapTotal:/ {swtotal=$2}; # total usable swap
/SwapFree:/ {swfree=$2}; # total swap that is free
END {
printf("MU%d\n", (100 - ((mfree / mtotal) * 100))); # mem used
printf("MS%d\n", (100 - ((swfree / swtotal) * 100))); # swap used
}' /proc/meminfo
sleep 2
done
}
function disk_usage()
{
while true; do
echo "D`df / | tail -1 | awk '{ print $5; }' | cut -d% -f1`"
sleep 2
done
}
function clock()
{
while true; do
date +'S%a %m/%d %H:%M'
sleep 1
done
}
bspc subscribe report > "$PANEL_FIFO" &
xtitle -sf 'T%s' > "$PANEL_FIFO" &
#clock -sf 'S%a %H:%M' > "$PANEL_FIFO" &
clock > "$PANEL_FIFO" &
memory_usage > "$PANEL_FIFO" &
disk_usage > "$PANEL_FIFO" &
function panel_bar()
{
sleep 1 # Let the FIFO queue up...
while read -r line; do
case $line in
S*)
# clock output
fg=$COLOR_STATUS_FG
bg=$COLOR_STATUS_BG
sys_infos="%{F$fg}%{B$bg}${obrack}${line#?}${cbrack}%{B-}%{F-}"
;;
T*)
# xtitle output
fg=$COLOR_TITLE_FG
bg=$COLOR_TITLE_BG
title="%{F$fg}%{B$bg}${line#?}%{B-}%{F-}"
;;
D*)
# disk usage output
disk="${obrack}%{F$RED}d${cbrack} ${line#?}%"
;;
M*)
# memory usage output
line=${line#?}
case $line in
U*)
mem_used="${obrack}%{F$RED}m${cbrack} ${line#?}%"
;;
S*)
mem_swap="${obrack}%{F$RED}s${cbrack} ${line#?}%"
;;
esac
;;
W*)
# bspwm internal state
wm_infos=""
IFS=':'
set -- ${line#?}
while [[ $# -gt 0 ]]; do
cmd=''
item=$1
name=${item#?}
case $item in
M*)
# focused monitor
fg=$COLOR_ACTIVE_MONITOR_FG
bg=$COLOR_ACTIVE_MONITOR_BG
name="[${name}]"
;;
m*)
# unfocused monitor
fg=$COLOR_INACTIVE_MONITOR_FG
bg=$COLOR_INACTIVE_MONITOR_BG
name="[${name}]"
;;
O*)
# occupied focused desktop
fg=$COLOR_FOCUSED_OCCUPIED_FG
bg=$COLOR_FOCUSED_OCCUPIED_BG
cmd="bspc desktop -f ${name}"
#cmd="bspc desktop ${name} -m focused -f \; bspc query -m focused -D | sort -n | xargs bspc monitor focused -o"
;;
o*)
# occupied unfocused desktop
fg=$COLOR_OCCUPIED_FG
bg=$COLOR_OCCUPIED_BG
cmd="bspc desktop -f ${name}"
#cmd="bspc desktop ${name} -m focused -f \; bspc query -m focused -D | sort -n | xargs bspc monitor focused -o"
;;
F*)
# free focused desktop
fg=$COLOR_FOCUSED_FREE_FG
bg=$COLOR_FOCUSED_FREE_BG
cmd="bspc desktop -f ${name}"
#cmd="bspc desktop ${name} -m focused -f \; bspc query -m focused -D | sort -n | xargs bspc monitor focused -o"
;;
f*)
# free unfocused desktop
fg=$COLOR_FREE_FG
bg=$COLOR_FREE_BG
cmd="bspc desktop -f ${name}"
#cmd="bspc desktop ${name} -m focused -f \; bspc query -m focused -D | sort -n | xargs bspc monitor focused -o"
;;
U*)
# urgent focused desktop
fg=$COLOR_FOCUSED_URGENT_FG
bg=$COLOR_FOCUSED_URGENT_BG
cmd="bspc desktop -f ${name}"
#cmd="bspc desktop ${name} -m focused -f \; bspc query -m focused -D | sort -n | xargs bspc monitor focused -o"
;;
u*)
# urgent unfocused desktop
fg=$COLOR_URGENT_FG
bg=$COLOR_URGENT_BG
cmd="bspc desktop -f ${name}"
#cmd="bspc desktop ${name} -m focused -f \; bspc query -m focused -D | sort -n | xargs bspc monitor focused -o"
;;
L*)
# layout of focused desktop
fg=$COLOR_LAYOUT_FG
bg=$COLOR_LAYOUT_BG
;;
*)
shift
continue
;;
esac
if [[ -n "$cmd" ]]; then
wm_infos+="%{F$fg}%{B$bg}%{A:$cmd:}${name} %{A}%{B-}%{F-}"
else
wm_infos+="%{F$fg}%{B$bg}${name} %{B-}%{F-}"
fi
shift
done
;;
esac
printf "%s\n" "%{S0}%{l}${disk} ${mem_used} ${mem_swap} ${sep} ${title} %{r}${wm_infos}${sys_infos}%{S1}%{l}${disk} ${mem_used} ${mem_swap} ${sep} ${title} %{r}${wm_infos}${sys_infos}"
done
}
#lemonbar -g ${PANEL_WIDTH}x${PANEL_HEIGHT} \
cat "$PANEL_FIFO" | \
panel_bar | \
lemonbar \
-a 50 \
-f "$PANEL_FONT_FAMILY" \
-F "$COLOR_FOREGROUND" \
-B "$COLOR_BACKGROUND" | \
while read line; do eval "$line"; done &
wait