wctrl (3479B)
1 #!/bin/sh 2 3 case "$1" in 4 "-f") # fullscreen, expected input: wid 5 FSFILE=${FSFILE:-/tmp/fsfile} 6 wid=$2 7 test -f $FSFILE && wtp $(cat $FSFILE) 8 if test -f $FSFILE && grep -q $wid $FSFILE; then 9 rm -f $FSFILE 10 else 11 wattr xywhi $wid > $FSFILE 12 chwb -s 0 $wid 13 wtp $(wattr xywh `lsw -r`) $wid 14 fi 15 $(basename $0) -fo $2 16 17 ;; 18 19 "-fo") #focus, expected input: wid 20 shift 21 BW=${BW:-2} # border width 22 ACTIVE=${ACTIVE:-0xffffff} # active border color 23 INACTIVE=${INACTIVE:-0x333333} # inactive border color 24 25 CUR=$(pfw) 26 27 usage() { 28 echo "usage: $(basename $0) <next|prev|wid>" 29 exit 1 30 } 31 32 setborder() { 33 ROOT=$(lsw -r) 34 wattr $2 || return 35 test "$(wattr xywh $2)" = "$(wattr xywh $ROOT)" && return 36 case $1 in 37 active) chwb -s $BW -c $ACTIVE $2 ;; 38 inactive) chwb -s $BW -c $INACTIVE $2 ;; 39 esac 40 } 41 42 case $1 in 43 next) wid=$(lsw|grep -v $CUR|sed '1 p;d') ;; 44 prev) wid=$(lsw|grep -v $CUR|sed '$ p;d') ;; 45 0x*) wattr $1 && wid=$1 ;; 46 *) usage ;; 47 esac 48 49 test -z "$wid" && echo "$(basename $0): can't find a window to focus" >&2 && exit 1 50 51 setborder inactive $CUR # set inactive border on current window 52 setborder active $wid # activate the new window 53 chwso -r $wid # put it on top of the stack 54 wtf $wid # set focus on it 55 wmp -a $(wattr xy $wid) # move the mouse cursor to 56 wmp -r $(wattr wh $wid) # .. its bottom right corner 57 ;; 58 59 60 "-q") # kill window 61 killw -p $2 62 ;; 63 "-c") # centralize 64 WID=$(pfw) 65 WW=$(wattr w $WID) 66 WH=$(wattr h $WID) 67 ROOT=$(lsw -r) 68 SW=$(wattr w $ROOT) 69 SH=$(wattr h $ROOT) 70 wtp $(((SW - WW)/2)) $(((SH - WH)/2)) $WW $WH $WID 71 ;; 72 73 "-cy") # cycle between windows, expected input: prev, next or wid 74 shift 75 BW=${BW:-0} # border width 76 ACTIVE=${ACTIVE:-0xffffff} # active border color 77 INACTIVE=${INACTIVE:-0x323232} # inactive border color 78 79 # get current window id 80 CUR=$(pfw || echo NONE) 81 82 usage() { 83 echo "usage: $(basename $0) <next|prev|wid>" >&2 84 exit 1 85 } 86 87 setborder() { 88 ROOT=$(lsw -r) 89 90 # check that window exists and shouldn't be ignored 91 wattr $2 || return 92 wattr o $2 && return 93 94 # do not modify border of fullscreen windows 95 test "$(wattr xywh $2)" = "$(wattr xywh $ROOT)" && return 96 97 case $1 in 98 active) 99 chwb -s $BW -c $ACTIVE $2 100 #chwb2 -O $ACTIVE -I 000000 -i 4 -o 4 $2 101 ;; 102 inactive) 103 chwb -s $BW -c $INACTIVE $2 104 #chwb2 -O $INACTIVE -I 000000 -i 4 -o 4 $2 105 ;; 106 esac 107 } 108 109 case $1 in 110 next) 111 wid=$(lsw|grep -v $CUR|sed '1 p;d') 112 ;; 113 prev) 114 wid=$(lsw|grep -v $CUR|sed '$ p;d') 115 ;; 116 0x*) 117 wattr $1 && wid=$1 118 #test "$wid" = "$CUR" && exit;; 119 ;; 120 *) usage ;; 121 esac 122 123 # exit if we can't find another window to focus 124 test -z "$wid" && { echo "$(basename $0): no window to focus" >&2; exit 1; } 125 126 wtf $wid # set focus on it 127 chwso -r $wid # raise windows 128 setborder inactive $CUR # set inactive border on current window 129 setborder active $wid # activate the new window 130 chwb -s $BW $wid 131 132 exit 0 133 esac