2008-01-18 01:50:35 +03:00
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
# For the time being, this file follows the lisp bracing
|
|
|
|
# convention. i.e.:
|
|
|
|
# if(frob this) {
|
|
|
|
# frob that
|
|
|
|
# if(frob theother) {
|
|
|
|
# unfrob this
|
|
|
|
# unfrob that}}
|
|
|
|
|
2008-01-18 01:50:35 +03:00
|
|
|
wmiiscript=$1
|
|
|
|
wmiikeys=()
|
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
wi_nl='
|
|
|
|
'
|
|
|
|
|
2008-01-18 01:50:35 +03:00
|
|
|
echo Start $wmiiscript | wmiir write /event >[2]/dev/null \
|
|
|
|
|| exit write
|
|
|
|
|
|
|
|
if(~ $scriptname '')
|
|
|
|
scriptname=$wmiiscript
|
|
|
|
|
|
|
|
# Blech.
|
|
|
|
if(! test -x $PLAN9/bin/read)
|
|
|
|
fn read { sh -c 'read -r x || exit 1; echo $x' }
|
|
|
|
|
|
|
|
fn wi_atexit {}
|
|
|
|
fn sigexit {
|
|
|
|
wi_atexit
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_fatal {
|
|
|
|
echo $scriptname: Fatal: $*
|
|
|
|
exit fatal
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_notice {
|
|
|
|
xmessage $scriptname: Notice: $*
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_readctl { wmiir read /ctl | sed -n 's/^'$1' (.*)/\1/p' }
|
|
|
|
|
|
|
|
wmiifont=`{wi_readctl font}
|
|
|
|
wmiinormcol=`{wi_readctl normcolors}
|
|
|
|
wmiifocuscol=`{wi_readctl focuscolors}
|
|
|
|
|
|
|
|
fn wi_menu {
|
|
|
|
dmenu -b -fn $wmiifont \
|
|
|
|
-nf $wmiinormcol(1) -nb $wmiinormcol(2) \
|
|
|
|
-sf $wmiifocuscol(1) -sb $wmiifocuscol(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_9menu {
|
|
|
|
wmii9menu -font `{echo $wmiifont | sed 's/,.*//'} \
|
|
|
|
-^(nf nb br)^$wmiinormcol \
|
|
|
|
-^(sf sb br)^$wmiifocuscol $*
|
|
|
|
}
|
|
|
|
|
2008-01-28 00:08:25 +03:00
|
|
|
fn wi_fnmenu {
|
|
|
|
group=$1^Menu-$2 last=$group^_last fns=`{wi_getfuns $group} {
|
|
|
|
shift 2
|
|
|
|
if(! ~ $#fns 0) {
|
|
|
|
res = `{wi_9menu -initial $"($last) $fns} \
|
|
|
|
if(! ~ $res '') {
|
|
|
|
($last) = $res
|
|
|
|
$group-$res $*}}}
|
|
|
|
}
|
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
fn wi_fn-p {
|
|
|
|
rc -c 'whatis '$1 >[2]/dev/null | grep -s '^fn '
|
|
|
|
}
|
|
|
|
|
2008-01-18 01:50:35 +03:00
|
|
|
fn wi_proglist {
|
|
|
|
/bin/ls -lL `{echo $* | sed 'y/:/ /'} >[2]/dev/null \
|
|
|
|
| awk '$1 ~ /^[^d].*x/ { print $NF }' \
|
|
|
|
| sort | uniq
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_actions {
|
|
|
|
{ wi_proglist $WMII_CONFPATH
|
|
|
|
wi_getfuns Action
|
|
|
|
} | sort | uniq
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_script {
|
2008-01-21 02:00:21 +03:00
|
|
|
noprog=true prog=() {
|
|
|
|
if(~ $1 -f) {
|
|
|
|
shift
|
|
|
|
noprog=/dev/null
|
|
|
|
}
|
|
|
|
prog = `{rc -c 'path=$confpath whatis '$1 >[2]/dev/null \
|
|
|
|
| grep -v '^fn|= ' || echo $noprog}
|
|
|
|
shift; echo $prog $*}
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn wi_initkeys {
|
|
|
|
ifs=() {
|
|
|
|
wmiikeys = `{wmiir read /keys} {
|
|
|
|
mykeys = `{comm -23 \
|
|
|
|
<{wi_getfuns Key | sort | uniq} \
|
|
|
|
<{echo $wmiikeys | sort | uniq}}
|
|
|
|
{echo $wmiikeys; wi_getfuns Key} \
|
|
|
|
| sort | uniq \
|
2008-01-21 02:00:21 +03:00
|
|
|
| wmiir write /keys }}
|
2008-01-18 01:50:35 +03:00
|
|
|
fn wi_atexit {
|
|
|
|
wi_cleankeys
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_cleankeys {
|
|
|
|
ifs=() {
|
|
|
|
wmiikeys = `{wmiir read /keys} {
|
|
|
|
comm -23 <{echo $wmiikeys | sort | uniq} \
|
|
|
|
<{echo $mykeys} \
|
2008-01-21 02:00:21 +03:00
|
|
|
| wmiir write /keys }}
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_runcmd { @{
|
|
|
|
rfork ns
|
|
|
|
path=$oldpath
|
|
|
|
if(~ $1 -t) {
|
|
|
|
shift
|
2008-01-21 02:00:21 +03:00
|
|
|
* = (wihack -tags `{wmiir read /tag/sel/ctl | sed 1q} $*) }
|
|
|
|
eval exec $* & }
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_getfuns {
|
|
|
|
env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p'
|
|
|
|
}
|
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
for(i in Key Event Action)
|
|
|
|
fns=`{wi_getfuns $i} {
|
|
|
|
if(! ~ $fns '')
|
|
|
|
fn $i-^$fns}
|
|
|
|
|
2008-01-18 01:50:35 +03:00
|
|
|
fn wi_tags {
|
|
|
|
wmiir ls /tag | sed 's,/,,; /^sel$/d'
|
|
|
|
}
|
|
|
|
|
2008-01-28 00:08:25 +03:00
|
|
|
fn wi_seltag {
|
|
|
|
wmiir read /tag/sel/ctl | sed 1q
|
|
|
|
}
|
|
|
|
|
2008-02-04 01:14:41 +03:00
|
|
|
fn wi_readevent {
|
|
|
|
wmiir read /event
|
|
|
|
}
|
|
|
|
|
2008-01-18 01:50:35 +03:00
|
|
|
fn wi_eventloop {
|
|
|
|
wi_initkeys
|
|
|
|
|
2008-02-04 01:14:41 +03:00
|
|
|
wi_readevent |
|
2008-01-21 02:00:21 +03:00
|
|
|
while(ifs=$wi_nl{wi_event=`{read}}) {
|
|
|
|
ifs=$wi_nl{
|
|
|
|
wi_arg=`{echo $wi_event | sed 's/^[^ ]+ //'}}
|
|
|
|
* = `{echo $wi_event}
|
|
|
|
event = $1; shift
|
|
|
|
Event-$event $*
|
|
|
|
} >[2]/dev/null </dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Event-Key {
|
|
|
|
Key-$1 $1
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Event-Start {
|
|
|
|
if(~ $1 $wmiiscript)
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Action {
|
|
|
|
cmd=$1 action=Action-$cmd { shift
|
|
|
|
if(wi_fn-p $action)
|
|
|
|
$action $*
|
|
|
|
if not
|
|
|
|
wi_runcmd `{wi_script $cmd} $*
|
|
|
|
} &
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|