2008-01-21 02:00:21 +03:00
|
|
|
|
2009-10-10 00:40:33 +04:00
|
|
|
[ -z "$scriptname" ] && scriptname="$wmiiscript"
|
2008-01-21 02:00:21 +03:00
|
|
|
echo Start $wmiiscript | wmiir write /event 2>/dev/null ||
|
|
|
|
exit 1
|
|
|
|
|
2009-10-10 00:40:33 +04:00
|
|
|
wi_newline='
|
2008-01-22 02:22:42 +03:00
|
|
|
'
|
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
_wi_script() {
|
2009-10-10 00:40:33 +04:00
|
|
|
# Awk script to mangle key/event/action definition spec
|
|
|
|
# into switch-case functions and lists of the cases. Also
|
|
|
|
# generates a simple key binding help text based on KeyGroup
|
|
|
|
# clauses and comments that appear on key lines.
|
|
|
|
#
|
|
|
|
# Each clause (Key, Event, Action) generates a function of the
|
|
|
|
# same name which executes the indented text after the matching
|
|
|
|
# clause. Clauses are selected based on the first argument passed
|
|
|
|
# to the mangled function. Additionally, a variable is created named
|
|
|
|
# for the plouralized version of the clause name (Keys, Events,
|
|
|
|
# Actions) which lists each case value. These are used for actions
|
|
|
|
# menus and to write wmii's /keys file.
|
2008-01-21 02:00:21 +03:00
|
|
|
cat <<'!'
|
|
|
|
BEGIN {
|
|
|
|
arg[1] = "Nop"
|
2008-01-22 02:22:42 +03:00
|
|
|
narg = 1;
|
2008-01-21 02:00:21 +03:00
|
|
|
body = "";
|
2009-10-03 07:02:01 +04:00
|
|
|
keyhelp = ""
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
2008-05-30 01:22:56 +04:00
|
|
|
function quote(s) {
|
2009-10-03 07:02:01 +04:00
|
|
|
gsub(/'/, "'\\''", s)
|
2008-05-30 01:22:56 +04:00
|
|
|
return "'" s "'"
|
|
|
|
}
|
2008-01-21 02:00:21 +03:00
|
|
|
function addevent() {
|
|
|
|
var = arg[1] "s"
|
2008-01-22 02:22:42 +03:00
|
|
|
for(i=2; i <= narg; i++) {
|
2008-05-20 03:26:43 +04:00
|
|
|
if(body == "")
|
|
|
|
delete a[arg[1],arg[i]]
|
|
|
|
else
|
|
|
|
a[arg[1],arg[i]] = body
|
|
|
|
if(i == 2) {
|
|
|
|
# There's a bug here. Can you spot it?
|
|
|
|
gsub("[^a-zA-Z_0-9]", "_", arg[2]);
|
2008-05-30 01:22:56 +04:00
|
|
|
body = sprintf("%s %s \"$@\"", arg[1], arg[2])
|
2008-01-22 02:22:42 +03:00
|
|
|
}
|
|
|
|
}
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
2009-10-03 07:02:01 +04:00
|
|
|
/^(Key)Group[ \t]/ {
|
|
|
|
sub(/^[^ \t]+[ \t]+/, "")
|
|
|
|
keyhelp = keyhelp "\n " $0 "\n"
|
|
|
|
}
|
2008-05-30 01:22:56 +04:00
|
|
|
/^(Event|Key|Action|Menu)[ \t]/ {
|
2008-01-21 02:00:21 +03:00
|
|
|
addevent()
|
2009-10-03 07:02:01 +04:00
|
|
|
split($0, tmp, /[ \t]+#[ \t]*/)
|
|
|
|
narg = split(tmp[1], arg)
|
|
|
|
if(arg[1] == "Key" && tmp[2])
|
|
|
|
for (i=2; i <= narg; i++)
|
|
|
|
keyhelp = keyhelp sprintf(" %-20s %s\n",
|
|
|
|
arg[i], tmp[2])
|
2008-01-21 02:00:21 +03:00
|
|
|
body = ""
|
|
|
|
}
|
|
|
|
/^[ \t]/ {
|
2009-10-03 07:02:01 +04:00
|
|
|
sub(/^( |\t)/, "")
|
2008-01-21 02:00:21 +03:00
|
|
|
body = body"\n"$0
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
addevent()
|
2008-05-20 03:26:43 +04:00
|
|
|
for(k in a) {
|
|
|
|
split(k, b, SUBSEP)
|
|
|
|
c[b[1]] = c[b[1]] b[2] "\n"
|
|
|
|
if(body != "")
|
2009-10-03 07:02:01 +04:00
|
|
|
d[b[1]] = d[b[1]] quote(b[2]) ")" a[k] "\n;;\n"
|
2008-05-20 03:26:43 +04:00
|
|
|
}
|
2008-05-30 01:22:56 +04:00
|
|
|
for(k in c)
|
|
|
|
printf "%ss=%s\n", k, quote(c[k])
|
|
|
|
for(k in d) {
|
|
|
|
printf "%s() {\n", k
|
|
|
|
printf " %s=$1; shift\n", tolower(k)
|
2009-03-19 01:16:13 +03:00
|
|
|
printf "case $%s in\n%s\n*) return 1\nesac\n", tolower(k), d[k]
|
2008-05-30 01:22:56 +04:00
|
|
|
printf "}\n"
|
2008-05-20 03:26:43 +04:00
|
|
|
}
|
2009-10-03 07:02:01 +04:00
|
|
|
print "KeysHelp=" quote(keyhelp)
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
|
|
|
!
|
|
|
|
}
|
|
|
|
|
|
|
|
_wi_text() {
|
2008-05-20 03:26:43 +04:00
|
|
|
cat <<'!'
|
|
|
|
Event Key
|
2008-05-30 01:22:56 +04:00
|
|
|
Key "$@"
|
2008-05-20 03:26:43 +04:00
|
|
|
!
|
2008-01-21 02:00:21 +03:00
|
|
|
eval "cat <<!
|
2009-10-10 00:40:33 +04:00
|
|
|
$( (test ! -t 0 && cat; for a; do eval "$a"; done) | sed '/^[ ]/s/\([$`\\]\)/\\\1/g')
|
2008-08-25 20:47:56 +04:00
|
|
|
!
|
2008-01-21 02:00:21 +03:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
wi_events() {
|
2009-10-10 00:40:33 +04:00
|
|
|
#cho "$(_wi_text "$@" | awk "$(_wi_script)")" | cat -n
|
|
|
|
eval "$(_wi_text "$@" | awk "$(_wi_script)")"
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wi_fatal() {
|
|
|
|
echo $scriptname: Fatal: $*
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
wi_notice() {
|
|
|
|
xmessage $scriptname: Notice: $*
|
|
|
|
}
|
|
|
|
|
|
|
|
wi_readctl() {
|
|
|
|
wmiir read /ctl | sed -n 's/^'$1' //p'
|
|
|
|
}
|
|
|
|
|
|
|
|
wmiifont="$(wi_readctl font)"
|
|
|
|
wmiinormcol="$(wi_readctl normcolors)"
|
|
|
|
wmiifocuscol="$(wi_readctl focuscolors)"
|
|
|
|
|
2008-05-30 01:22:56 +04:00
|
|
|
wi_fnmenu() {
|
|
|
|
group="$1-$2"; shift 2
|
|
|
|
_last="$(echo $group|tr - _)_last"
|
|
|
|
eval "last=\"\$$_last\""
|
|
|
|
res=$(set -- $(echo "$Menus" | awk -v "s=$group" 'BEGIN{n=length(s)}
|
|
|
|
substr($1,1,n) == s{print substr($1,n+2)}')
|
2008-10-17 03:05:17 +04:00
|
|
|
[ $# != 0 ] && wmii9menu -i "$last" "$@")
|
2008-05-30 01:22:56 +04:00
|
|
|
if [ -n "$res" ]; then
|
|
|
|
eval "$_last="'"$res"'
|
|
|
|
Menu $group-$res "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
wi_proglist() {
|
2010-05-30 23:18:15 +04:00
|
|
|
wmiir proglist -- $(echo $* | sed 'y/:/ /') | sort | uniq
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wi_actions() {
|
|
|
|
{ wi_proglist $WMII_CONFPATH
|
2008-05-20 03:26:43 +04:00
|
|
|
echo -n "$Actions"
|
2008-01-21 02:00:21 +03:00
|
|
|
} | sort | uniq
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:26:43 +04:00
|
|
|
wi_runconf() {
|
|
|
|
sflag=""; if [ "$1" = -s ]; then sflag=1; shift; fi
|
|
|
|
which="$(which which)"
|
|
|
|
prog=$(PATH="$WMII_CONFPATH" "$which" -- $1 2>/dev/null); shift
|
|
|
|
if [ -n "$prog" ]; then
|
|
|
|
if [ -z "$sflag" ]
|
|
|
|
then "$prog" "$@"
|
|
|
|
else . "$prog"
|
|
|
|
fi
|
|
|
|
else return 1
|
|
|
|
fi
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wi_script() {
|
|
|
|
_noprog=true
|
|
|
|
if [ "$1" = -f ]; then
|
|
|
|
shift
|
|
|
|
_noprog=/dev/null
|
|
|
|
fi
|
|
|
|
which=$(which which)
|
|
|
|
_prog=$(PATH="$WMII_CONFPATH" $which $1 || echo $_noprog); shift
|
|
|
|
shift; echo "$_prog $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
wi_runcmd() {
|
|
|
|
if [ "$1" = -t ]; then
|
|
|
|
shift
|
|
|
|
set -- wihack -tags $(wmiir read /tag/sel/ctl | sed 1q) "$*"
|
|
|
|
fi
|
2008-05-20 03:26:43 +04:00
|
|
|
eval exec "$*" &
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wi_tags() {
|
|
|
|
wmiir ls /tag | sed 's,/,,; /^sel$/d'
|
|
|
|
}
|
|
|
|
|
2008-05-30 01:22:56 +04:00
|
|
|
wi_seltag() {
|
|
|
|
wmiir read /tag/sel/ctl | sed 1q | tr -d '\012'
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:14:06 +04:00
|
|
|
wi_selclient() {
|
|
|
|
wmiir read /client/sel/ctl | sed 1q | tr -d '\012'
|
|
|
|
}
|
|
|
|
|
2010-06-26 01:21:12 +04:00
|
|
|
wi_nexttag() {
|
|
|
|
awk -v curtag=$(wi_seltag) '
|
|
|
|
NR==1 {first = $0}
|
|
|
|
$0==curtag { if(getline) print $0; else print first; exit }'
|
|
|
|
}
|
|
|
|
|
2008-01-21 02:00:21 +03:00
|
|
|
wi_eventloop() {
|
|
|
|
echo "$Keys" | wmiir write /keys
|
|
|
|
|
2010-05-27 20:25:38 +04:00
|
|
|
if [ "$1" = -i ]
|
|
|
|
then cat
|
|
|
|
else wmiir read /event
|
2010-06-10 11:23:35 +04:00
|
|
|
fi |
|
|
|
|
while read wi_event; do
|
2009-10-10 00:40:33 +04:00
|
|
|
IFS="$wi_newline"
|
2008-01-22 02:22:42 +03:00
|
|
|
wi_arg=$(echo "$wi_event" | sed 's/^[^ ]* //')
|
2008-05-30 01:22:56 +04:00
|
|
|
unset IFS
|
2008-01-21 02:00:21 +03:00
|
|
|
set -- $wi_event
|
|
|
|
event=$1; shift
|
2010-06-26 01:21:12 +04:00
|
|
|
[ "$event" = Start -a "$1" = "$wmiiscript" ] &&
|
|
|
|
exit
|
2010-06-10 11:23:35 +04:00
|
|
|
( Event $event "$@" )
|
2008-05-30 01:22:56 +04:00
|
|
|
done
|
2008-10-17 04:15:03 +04:00
|
|
|
true
|
2008-01-21 02:00:21 +03:00
|
|
|
}
|
|
|
|
|
2008-05-30 01:22:56 +04:00
|
|
|
action() {
|
2008-01-21 02:00:21 +03:00
|
|
|
action=$1; shift
|
|
|
|
if [ -n "$action" ]; then
|
2008-05-30 01:22:56 +04:00
|
|
|
set +x
|
|
|
|
Action $action "$@" \
|
2008-05-20 03:26:43 +04:00
|
|
|
|| wi_runconf $action "$@"
|
2008-01-21 02:00:21 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|