tmaximize - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
tmaximize (1163B)
---
1 #!/bin/sh
2
3 usage() {
4 echo "usage: $(basename $0) [-hv] wid" >&2
5 exit 1
6 }
7
8 while getopts hv OPT; do
9 case $OPT in
10 h) MAX=horz ;;
11 v) MAX=vert ;;
12 *) usage ;;
13 esac
14 done
15 shift $((OPTIND -1))
16
17 test -n "$1" && WID=$1 || usage
18
19 MAX=${MAX:-full}
20 EXPANDIR=/tmp/.expan.d
21 BW=$(wattr b $WID)
22 SW=$(( $(wattr w `lsw -r`) - 2*$BW))
23 SH=$(( $(wattr h `lsw -r`) - 2*$BW))
24
25 test -d $EXPANDIR || mkdir -p $EXPANDIR
26
27 is_maxed() {
28 case $MAX in
29 vert) test $(wattr h $WID) -eq $SH && return 0 ;;
30 horz) test $(wattr w $WID) -eq $SW && return 0 ;;
31 full) test "$(wattr wh $WID)" = "$SW $SH" && return 0 ;;
32 esac
33
34 return 1
35 }
36
37 expand_win() {
38 wattr xywhi $WID > $EXPANDIR/$WID
39 case $MAX in
40 vert) GEOMETRY=$(printf '%d 0 %d %d' $(wattr xw $WID) "$SH") ;;
41 horz) GEOMETRY=$(printf '0 %d %d %d' $(wattr y $WID) "$SW" $(wattr h $WID)) ;;
42 full) GEOMETRY=$(printf '0 0 %d %d' "$SW" "$SH") ;;
43 esac
44 wtp ${GEOMETRY} ${WID}
45 }
46
47 collapse_win() {
48 test -f $EXPANDIR/$WID || return
49 wtp $(grep $WID $EXPANDIR/$WID)
50 rm $EXPANDIR/$WID
51 }
52
53 is_maxed && collapse_win || expand_win ;