URI:
       tvroum - scripts - various script and utils
  HTML git clone git://z3bra.org/scripts
   DIR Log
   DIR Files
   DIR Refs
       ---
       tvroum (1513B)
       ---
            1 #!/bin/sh
            2 #
            3 # z3bra - 2014 (c) wtfpl
            4 # window focus wrapper that sets borders and can focus next/previous window
            5 
            6 BW=${BW:-2}                    # border width
            7 ACTIVE=${ACTIVE:-0xffffff}     # active border color
            8 INACTIVE=${INACTIVE:-0x323232} # inactive border color
            9 
           10 # get current window id
           11 CUR=$(pfw || echo NONE)
           12 
           13 usage() {
           14     echo "usage: $(basename $0) <next|prev|wid>" >&2
           15     exit 1
           16 }
           17 
           18 setborder() {
           19     ROOT=$(lsw -r)
           20 
           21     # check that window exists and shouldn't be ignored
           22     wattr $2 || return
           23     wattr o $2 && return
           24 
           25     # do not modify border of fullscreen windows
           26     test "$(wattr xywh $2)" = "$(wattr xywh $ROOT)" && return
           27 
           28     case $1 in
           29         active)
           30             chwb -s $BW -c $ACTIVE $2
           31             #chwb2 -O $ACTIVE -I 000000 -i 4 -o 4 $2
           32             ;;
           33         inactive)
           34             chwb -s $BW -c $INACTIVE $2
           35             #chwb2 -O $INACTIVE -I 000000 -i 4 -o 4 $2
           36             ;;
           37     esac
           38 }
           39 
           40 case $1 in
           41     next)
           42         wid=$(lsw|grep -v $CUR|sed '1 p;d')
           43         ;;
           44     prev)
           45         wid=$(lsw|grep -v $CUR|sed '$ p;d')
           46         ;;
           47     0x*)
           48         wattr $1 && wid=$1
           49         #test "$wid" = "$CUR" && exit;;
           50         ;;
           51     *) usage ;;
           52 esac
           53 
           54 # exit if we can't find another window to focus
           55 test -z "$wid" && { echo "$(basename $0): no window to focus" >&2; exit 1; }
           56 
           57 wtf $wid                # set focus on it
           58 chwso -r $wid           # raise windows
           59 setborder inactive $CUR # set inactive border on current window
           60 setborder active $wid   # activate the new window
           61 chwb -s $BW $wid
           62 
           63 exit 0