diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2009-09-03 19:04:17 +0200 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2009-09-03 19:04:17 +0200 |
commit | b04492700c40837bbae771c53ba2aafaadcd3a65 (patch) | |
tree | 8d130c84dad53ad4bce06c817a386072a57f6d1a /examples | |
parent | 6b063255c15068665e2e635e41a85b498707b648 (diff) |
refactored dispatcher that supports getting fifo path from event
Diffstat (limited to 'examples')
-rwxr-xr-x[-rw-r--r--] | examples/data/uzbl/scripts/dispatcher.sh | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/examples/data/uzbl/scripts/dispatcher.sh b/examples/data/uzbl/scripts/dispatcher.sh index 6f33406..e3e2706 100644..100755 --- a/examples/data/uzbl/scripts/dispatcher.sh +++ b/examples/data/uzbl/scripts/dispatcher.sh @@ -1,27 +1,44 @@ #!/bin/sh # -# Sample uzbl key handler +# Sample uzbl eventhandler # # demonstrating one possible way to access and process # uzbl's event messages # -# Usage: uzbl | keyhandler +# Usage: uzbl | eventhandler # +VERBOSE=1 + + ALTPRESSED=0 +log () { + [ -n "$VERBOSE" ] && echo "$1" +} + +fifo () { + log "$1 > ${FIFO_PATH:-unset}" + [ -n "$FIFO_PATH" ] && echo "$1" > "$FIFO_PATH" +} + +log "Init eventhandler" + clear_modifiers() { ALT_PRESSED=0 CONTROL_PRESSED=0 #etc. - echo 'set status_message = ' > "$FIFO_PATH" + fifo 'set status_message = ' } while read EVENT; do # get eventname ENAME=`echo "$EVENT" | sed -ne 's/\([A-Z]*\) .*/\1/p'` - if [ x"$ENAME" = x'KEYPRESS' ]; then + if [ x"$ENAME" = 'xFIFO_SET' ]; then + FIFO_PATH=`echo $EVENT | cut -d ' ' -f 3` + + elif [ x"$ENAME" = x'KEYPRESS' ]; then KEY=$(echo "$EVENT" | sed -ne 's/KEYPRESS \[.*\] \(.*$\)/\1/p') FIFO_PATH='/tmp/uzbl_fifo_'$(echo "$EVENT" | sed -ne 's/KEYPRESS \[\(.*\)\] .*$/\1/p') @@ -38,7 +55,7 @@ while read EVENT; do # place an indicator showing the active modifier # on uzbl's statusbar # - echo 'set status_message = @status_message <span foreground="red" weight="bold">Alt</span>' > "$FIFO_PATH" + fifo 'set status_message = @status_message <span foreground="red" weight="bold">Alt</span>' fi if [ "$ALT_PRESSED" = 1 ]; then @@ -47,8 +64,8 @@ while read EVENT; do # if [ x"$KEY" = x'a' ]; then ALT_PRESSED=0 - echo 'set inject_html = <html><body> <h1>You pressed Alt+a </h1> </body></html>' > "$FIFO_PATH" - echo 'set status_message = ' > "$FIFO_PATH" + fifo 'set inject_html = <html><body> <h1>You pressed Alt+a </h1> </body></html>' + fifo 'set status_message = ' # delete keycmd # here not needed. loading a new page @@ -58,8 +75,8 @@ while read EVENT; do fi if [ x"$KEY" = x'b' ]; then ALT_PRESSED=0 - echo 'set inject_html = <html><body> <h1>You pressed Alt+b </h1> </body></html>' > "$FIFO_PATH" - echo 'set status_message = ' > "$FIFO_PATH" + fifo 'set inject_html = <html><body> <h1>You pressed Alt+b </h1> </body></html>' + fifo 'set status_message = ' fi fi @@ -69,7 +86,7 @@ while read EVENT; do if [ x"$KEY" = x'Control_L' -o x"$KEY" = x'Control_R' ];then clear_modifiers CONTROL_PRESSED=1 - echo 'set status_message = @status_message <span foreground="red" weight="bold">Control</span>' > "$FIFO_PATH" + fifo 'set status_message = @status_message <span foreground="red" weight="bold">Control</span>' #etc. fi fi |