x-expand - scripts - various script and utils
HTML git clone git://z3bra.org/scripts
DIR Log
DIR Files
DIR Refs
---
x-expand (976B)
---
1 #!/bin/sh
2 #
3 # Expand window in the direction specified until it reach the monitor side
4
5 usage() {
6 echo "usage: $(basename $0) wid [direction]" >&2
7 }
8
9 expand() {
10 # current window size
11 b="$(wattr b $1)"
12 w="$(wattr w $1)"
13 h="$(wattr h $1)"
14 x="$(wattr x $1)"
15 y="$(wattr y $1)"
16
17 # monitor size / position
18 mx="$(randr $1 | cut -f 4 | head -n 1)"
19 my="$(randr $1 | cut -f 5 | head -n 1)"
20 mw="$(randr $1 | cut -f 2 | head -n 1)"
21 mh="$(randr $1 | cut -f 3 | head -n 1)"
22
23 case $2 in
24 n) h=$((y + h)); y=$my ;;
25 s) h=$((mh - y - 2*b)) ;;
26 w) w=$((x - mx + w)); x=$mx ;;
27 e) w=$((mw + mx - x - 2*b)) ;;
28 esac
29
30 wtp $x $y $w $h $1
31 wtf $wid
32 }
33
34
35 while getopts 'nswe' OPT; do
36 case $OPT in
37 n|s|w|e) direction=$OPT ;;
38 h) usage; exit 0 ;;
39 *) usage; exit 1 ;;
40 esac
41 done
42 shift $((OPTIND - 1))
43
44 cur=$(pdw)
45 wid=${1:-$cur}
46
47 [ -z "$wid" ] && { usage; exit 1; }
48
49 if [ -n "$direction" ]; then
50 expand $wid $direction
51 else
52 expand $wid n
53 expand $wid s
54 expand $wid w
55 expand $wid e
56 fi