dots

Personal dotfiles
git clone git://git.gormless.xyz/dots.git
Log | Files | Refs

focus (1267B)


      1 #!/bin/sh
      2 
      3 BW=${BW:-8}                    # border width
      4 ACTIVE=${ACTIVE:-0x444444}     # active border color
      5 INACTIVE=${INACTIVE:-0x888888} # inactive border color
      6 
      7 # get current window id
      8 CUR=$(pfw)
      9 
     10 usage() {
     11     echo "usage: $(basename $0) <next|prev|wid>"
     12     exit 1
     13 }
     14 
     15 setborder() {
     16     ROOT=$(lswin -r)
     17 
     18     # check if window exists
     19     wattr $2 || return
     20 
     21     # do not modify border of fullscreen windows
     22     test "$(wattr xywh $2)" = "$(wattr xywh $ROOT)" && return
     23 
     24     case $1 in
     25         active)   chwb -s $BW -c $ACTIVE $2 ;;
     26         inactive) chwb -s $BW -c $INACTIVE $2 ;;
     27     esac
     28 }
     29 
     30 case $1 in
     31     next) wid=$(lswin|grep -v $CUR|sed '1 p;d') ;;
     32     prev) wid=$(lswin|grep -v $CUR|sed '$ p;d') ;;
     33     0x*) wattr $1 && wid=$1 ;;
     34     *) usage ;;
     35 esac
     36 
     37 # exit if we can't find another window to focus
     38 test -z "$wid" && echo "$(basename $0): can't find a window to focus" >&2 && exit 1
     39 
     40 #setborder inactive $CUR # set inactive border on current window
     41 #setborder active $wid   # activate the new window
     42 chwso -r $wid           # put it on top of the stack
     43 wintf $wid                # set focus on it
     44 
     45 # you might want to remove this for sloppy focus
     46 #wmp -a $(wattr xy $wid) # move the mouse cursor to
     47 #wmp -r $(wattr wh $wid) # .. its bottom right corner