-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwmiirc
322 lines (291 loc) · 7.49 KB
/
wmiirc
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/sh -f
# Configure wmii
# Configuration Variables
MODKEY=Mod4
UP=k
DOWN=j
LEFT=h
RIGHT=l
# Colors tuples: "<text> <background> <border>"
WMII_NORMCOLORS='#888888 #222222 #333333'
WMII_FOCUSCOLORS='#ffffff #285577 #4c7899'
WMII_BACKGROUND='#333333'
WMII_FONT='-*-fixed-medium-r-semicondensed--13-*-*-*-*-*-*-*'
set -- $(echo $WMII_NORMCOLORS $WMII_FOCUSCOLORS)
WMII_MENU="dmenu -b -fn '$WMII_FONT' -nf '$1' -nb '$2' -sf '$4' -sb '$5'"
WMII_9MENU="wmii9menu -font '$WMII_FONT' -nf '$1' -nb '$2' -sf '$4' -sb '$5' -br '$6'"
WMII_TERM="xterm"
TRANS_INC="transset-df -a --inc .1"
TRANS_DEC="transset-df -a --min .1 --dec .1"
LOCK_SCREEN="xscreensaver-command -lock"
# Column Rules
wmiir write /colrules <<!
/.*/ -> 58+42
!
# Tagging Rules
wmiir write /tagrules <<!
/MPlayer.*/ -> ~
/Psi.*/ -> ~
/xterm.*/ -> ~
/.*/ -> sel
/.*/ -> 1
!
BATT_AC_COLORS="#aaffaa #448844 #88cc88"
BATT_DISCHARGE_COLORS="#ffffaa #99994c #eeee9e"
BATT_LOW_COLORS1="#ee0000 #cc8888 #ffaaaa"
BATT_LOW_COLORS2="#aa0000 #cc8888 #ffaaaa"
ACPI_BATT_STAT_DISCHARG=1
ACPI_BATT_STAT_CHARGING=2
ACPI_BATT_STAT_CRITICAL=4
NETIF_ACTIVE_COLORS='#aaffff #008888 #9eeeee'
NETIF_INACTIVE_COLORS=$WMII_NORMCOLORS
netif_status() {
local addr
if addr=$( (ifconfig $1 || exit 1) | awk 'NR == 3 { addr = $2; }
/status:/ { if ($2 == "'$2'")
print addr; else exit 1; }'); then
echo $NETIF_ACTIVE_COLORS $1 $addr
else
echo $NETIF_INACTIVE_COLORS $1 off
fi
}
battery_status() {
local state time life
state=$( sysctl -n hw.acpi.battery.state )
time=$( sysctl -n hw.acpi.battery.time )
life=$( sysctl -n hw.acpi.battery.life )
if [ $(( $state & $ACPI_BATT_STAT_CRITICAL )) -ne 0 ]; then
if [ "$BATT_LOW_COLORS" = "$BATT_LOW_COLORS1" ]; then
BATT_LOW_COLORS=$BATT_LOW_COLORS2
else
BATT_LOW_COLORS=$BATT_LOW_COLORS1
fi
echo -n $BATT_LOW_COLORS
elif [ $(( $state & $ACPI_BATT_STAT_DISCHARG )) -ne 0 ]; then
echo -n $BATT_DISCHARGE_COLORS
else
echo -n $BATT_AC_COLORS
fi
if [ $time -gt 0 ]; then
printf " %d:%02d" $(( $time / 60 )) $(( time % 60 ))
else
echo -n " AC"
fi
echo " ($life%)"
}
# Event processing
# Processed later by `wmiiloop' and evaled.
# Duplicate the eval line and replace 'eval' with 'echo' for details.
eventstuff() {
cat <<'!'
# Events
Event Start
case "$1" in
wmiirc)
exit;
esac
Event Key
fn=$(echo "$@" | sed 's/[^a-zA-Z_0-9]/_/g')
Key_$fn "$@"
Event CreateTag
echo "$WMII_NORMCOLORS" "$@" | wmiir create "/lbar/$@"
Event DestroyTag
wmiir remove "/lbar/$@"
Event FocusTag
wmiir xwrite "/lbar/$@" "$WMII_FOCUSCOLORS" "$@"
Event UnfocusTag
wmiir xwrite "/lbar/$@" "$WMII_NORMCOLORS" "$@"
Event UrgentTag
shift
wmiir xwrite "/lbar/$@" "*$@"
Event NotUrgentTag
shift
wmiir xwrite "/lbar/$@" "$@"
Event LeftBarClick
shift
wmiir xwrite /ctl view "$@"
Event CreateClient
xprop -id "$@" WM_CLASS | grep -qi \"xterm\" && \
transset-df -i "$@" .9
# Actions
Action quit
wmiir xwrite /ctl quit
Action exec
wmiir xwrite /ctl exec "$@"
Action rehash
proglist $PATH >$progsfile
Action status
set +xv
wmiir remove /rbar/_empty 2>/dev/null && sleep 2
wmiir remove /rbar/battery 2>/dev/null && sleep 2
wmiir remove /rbar/time 2>/dev/null && sleep 2
echo "$WMII_NORMCOLORS" | wmiir create /rbar/_empty
echo "$WMII_NORMCOLORS" | wmiir create /rbar/battery
echo "$WMII_NORMCOLORS" | wmiir create /rbar/time
while :; do
battery_status | wmiir write /rbar/battery
date +%a\ %H:%M | wmiir write /rbar/time
sleep 20
done
Event ClientMouseDown
client=$1; button=$2
case "$button" in
3)
do=$(eval $WMII_9MENU -initial "${menulast:-SomeRandomName}" Nop Delete Fullscreen)
case "$do" in
Delete)
wmiir xwrite /client/$client/ctl kill;;
Fullscreen)
wmiir xwrite /client/$client/ctl Fullscreen on;;
esac
menulast=${do:-"$menulast"}
;;
4)
eval $TRANS_INC
;;
5)
eval $TRANS_DEC
;;
esac
# Key Bindings
Key $MODKEY-Control-t
case $(wmiir read /keys | wc -l | tr -d ' \t\n') in
0|1)
echo -n $Keys | tr ' ' '\012' | wmiir write /keys
wmiir xwrite /ctl grabmod $MODKEY;;
*)
wmiir xwrite /keys $MODKEY-Control-t
wmiir xwrite /ctl grabmod Mod3;;
esac
Key $MODKEY-space
wmiir xwrite /tag/sel/ctl select toggle
Key $MODKEY-d
wmiir xwrite /tag/sel/ctl colmode sel default
Key $MODKEY-s
wmiir xwrite /tag/sel/ctl colmode sel stack
Key $MODKEY-m
wmiir xwrite /tag/sel/ctl colmode sel max
Key $MODKEY-a
Action $(actionlist | eval $WMII_MENU) &
Key $MODKEY-p
sh -c "$(eval $WMII_MENU <$progsfile)" &
Key $MODKEY-t
wmiir xwrite /ctl "view $(tagsmenu)" &
Key $MODKEY-Return
eval $WMII_TERM &
Key $MODKEY-Shift-space
wmiir xwrite /tag/sel/ctl send sel toggle
Key $MODKEY-f
wmiir xwrite /client/sel/ctl Fullscreen toggle
Key $MODKEY-Shift-c
wmiir xwrite /client/sel/ctl kill
Key $MODKEY-Shift-t
wmiir xwrite "/client/$(wmiir read /client/sel/ctl)/tags" "$(tagsmenu)" &
Key $MODKEY-$LEFT
wmiir xwrite /tag/sel/ctl select left
Key $MODKEY-$RIGHT
wmiir xwrite /tag/sel/ctl select right
Key $MODKEY-$DOWN
wmiir xwrite /tag/sel/ctl select down
Key $MODKEY-$UP
wmiir xwrite /tag/sel/ctl select up
Key $MODKEY-Tab
wmiir xwrite /tag/sel/ctl select up
Key $MODKEY-Shift-Tab
wmiir xwrite /tag/sel/ctl select down
Key $MODKEY-Shift-$LEFT
wmiir xwrite /tag/sel/ctl send sel left
Key $MODKEY-Shift-$RIGHT
wmiir xwrite /tag/sel/ctl send sel right
Key $MODKEY-Shift-$DOWN
wmiir xwrite /tag/sel/ctl send sel down
Key $MODKEY-Shift-$UP
wmiir xwrite /tag/sel/ctl send sel up
Key $MODKEY-Up
eval $TRANS_INC
Key $MODKEY-Down
eval $TRANS_DEC
Key XF86Mail
xset dpms force off
!
for i in 0 1 2 3 4 5 6 7 8 9; do
cat <<!
Key $MODKEY-$i
wmiir xwrite /ctl view "$i"
Key $MODKEY-Shift-$i
wmiir xwrite /client/sel/tags "$i"
!
done
}
# WM Configuration
wmiir write /ctl << EOF
font $WMII_FONT
focuscolors $WMII_FOCUSCOLORS
normcolors $WMII_NORMCOLORS
grabmod $MODKEY
border 1
EOF
export WMII_MENU WMII_9MENU WMII_FONT WMII_TERM
export WMII_FOCUSCOLORS WMII_SELCOLORS WMII_NORMCOLORS
# Feed events to `wmiiloop' for processing
eval "$(eventstuff | sed 's/^[ ]//' | { . wmiiloop; })"
echo "$Keys" | tr ' ' '\n' | wmiir write /keys
# Functions
Action() {
action=$1; shift
if [ -n "$action" ]; then
Action_$action "$@" \
|| conf_which $action "$@"
fi
}
proglist() {
paths=$(echo "$@" | sed 'y/:/ /')
ls -lL $paths 2>/dev/null \
| awk '$1 ~ /^[^d].*x/ && NF > 2 { print $NF }' \
| sort | uniq
}
# Misc
progsfile="$WMII_NS_DIR/.proglist"
Action status &
proglist $PATH >$progsfile &
pgrep xcompmgr || xcompmgr &
transset-df -a # to make status bar transparent
hsetroot -center ~/wp/1280x1024_0031.jpg
#pgrep xscreensaver || xscreensaver -no-splash &
pgrep xterm || xterm &
# Setup Tag Bar
seltag="$(wmiir read /tag/sel/ctl 2>/dev/null)"
wmiir ls /lbar |
while read bar; do
wmiir remove "/lbar/$bar"
done
wmiir ls /tag | sed -e 's|/||; /^sel$/d' |
while read tag; do
if [ "X$tag" = "X$seltag" ]; then
echo "$WMII_FOCUSCOLORS" "$tag" | wmiir create "/lbar/$tag"
else
echo "$WMII_NORMCOLORS" "$tag" | wmiir create "/lbar/$tag"
fi
done
# More functions
tagsmenu() {
wmiir ls /tag | sed 's|/||; /^sel$/d' | eval $WMII_MENU
}
actionlist() {
{ proglist $WMII_CONFPATH
echo -n $Actions | tr ' ' '\012'
} | sort | uniq
}
conf_which() {
which=$(which which)
prog=$(PATH="$WMII_CONFPATH" $which $1); shift
[ -n "$prog" ] && $prog "$@"
}
# Stop any running instances of wmiirc
echo Start wmiirc | wmiir write /event || exit 1
wmiir read /event |
while read event; do
set -- $event
event=$1; shift
Event_$event $@
done 2>/dev/null