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=()
|
|
|
|
|
2009-10-10 00:40:33 +04:00
|
|
|
wi_newline='
|
2008-01-21 02:00:21 +03:00
|
|
|
'
|
|
|
|
|
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}
|
|
|
|
|
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) {
|
2008-10-17 03:05:17 +04:00
|
|
|
res = `{wmii9menu -i $"($last) $fns} \
|
2008-01-28 00:08:25 +03:00
|
|
|
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 {
|
2010-05-30 23:18:15 +04:00
|
|
|
ifs=: { wmiir proglist -- `{echo -n $*} | sort | uniq }
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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 \
|
2008-05-30 01:28:27 +04:00
|
|
|
| grep -v '^fn |=' || echo $noprog}
|
2008-01-21 02:00:21 +03:00
|
|
|
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} $*) }
|
2008-05-24 03:51:56 +04:00
|
|
|
fn `{env | 9 sed -n 's/^fn#([^=]+).*/\1/p'}
|
|
|
|
mykeys=()
|
2008-10-16 07:59:17 +04:00
|
|
|
if(! ~ $* '')
|
|
|
|
eval exec $* & }
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn wi_getfuns {
|
2008-05-18 21:31:58 +04:00
|
|
|
env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p' | sort | uniq
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|
2008-05-18 21:31:58 +04:00
|
|
|
for(i in Key Event Action '*Menu')
|
2008-01-21 02:00:21 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:14:06 +04:00
|
|
|
fn wi_selclient {
|
|
|
|
wmiir read /client/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 |
|
2009-10-10 00:40:33 +04:00
|
|
|
while(ifs=$wi_ewlinel{wi_event=`{read}}) {
|
|
|
|
ifs=$wi_newline{
|
2008-01-21 02:00:21 +03:00
|
|
|
wi_arg=`{echo $wi_event | sed 's/^[^ ]+ //'}}
|
|
|
|
* = `{echo $wi_event}
|
|
|
|
event = $1; shift
|
2008-05-25 05:12:53 +04:00
|
|
|
Event-$"event $*
|
2008-01-21 02:00:21 +03:00
|
|
|
} >[2]/dev/null </dev/null
|
2008-10-17 04:15:03 +04:00
|
|
|
true
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn Event-Key {
|
|
|
|
Key-$1 $1
|
|
|
|
}
|
|
|
|
|
2009-05-17 22:15:08 +04:00
|
|
|
fn Event-Quit {
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
fn Event-Start {
|
|
|
|
if(~ $1 $wmiiscript)
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
fn Action {
|
2008-10-17 18:39:13 +04:00
|
|
|
cmd=$1 action=Action-$"cmd { shift
|
|
|
|
if(! ~ $cmd '') {
|
|
|
|
if(wi_fn-p $action)
|
|
|
|
$action $*
|
|
|
|
if not
|
|
|
|
wi_runcmd `{wi_script $cmd} $*
|
|
|
|
}
|
|
|
|
}
|
2008-01-18 01:50:35 +03:00
|
|
|
}
|
|
|
|
|