bin/xzoomscr, dot/e16-bindings: Allow fractional zooming.
[profile] / bin / xzoomscr
CommitLineData
56e4c6c0
MW
1#! /bin/sh -e
2
3case $# in 1) ;; *) echo >&2 "usage: $1 ZOOM"; exit 2 ;; esac
4zoom=$1
5
6ok=nil
7e571efe
MW
7case $zoom in
8 */*/*) ;;
9 *[!0-9/]*) ;;
10 */*) ok=t mul=${zoom%/*} div=${zoom#*/} ;;
11 *) ok=t mul=1 div=$zoom ;;
12esac
13case $ok in nil) echo >&2 "$0: bad zoom $zoom"; exit 2 ;; esac
14case $(( $mul > $div )) in 1) echo >&2 "$0: zoom too high"; exit 2 ;; esac
15
16ok=nil
56e4c6c0
MW
17case ${DISPLAY-nil} in
18 *:*[!0-9.]*) ;;
19 *:*.*.*) ;;
20 *:*.*) ok=t dpybase=${DISPLAY%.*} ;;
21 *:*) ok=t dpybase=$DISPLAY ;;
22esac
7e571efe 23case $ok in nil) echo >&2 "$0: bad DISPLAY"; exit 2 ;; esac
56e4c6c0
MW
24
25set -- $(xqueryptr); scr=$1 x=$2 y=$3
26DISPLAY=$dpybase.$scr; export DISPLAY
27
28eval $(xscsize -b)
29
7e571efe 30case $(( $XWIDTH%$div || $XHEIGHT%$div )) in
56e4c6c0 31 0) ;;
7e571efe 32 *) echo >&2 "$0: zoom divisor doesn't divide screen size"; exit 2 ;;
56e4c6c0
MW
33esac
34
35{ read _
36 found=nil
37 while read _ _ respos name; do
38 res=${respos%%+*} pos=${respos#*+}
39 ww=${res%x*} hh=${res#*x}
40 w=${ww%/*} h=${hh%/*}
41 x0=${pos%+*} y0=${pos#*+}
42 x1=$(( $x0 + $w )) y1=$(( $y0 + $h ))
43 case $(( $x0 <= $x && $x < $x1 && $y0 <= $y && $y < $y1 )) in
44 1) found=t; break ;;
45 esac
46 done
47} <<EOF
48$(xrandr --listmonitors)
49EOF
50
51case $found in nil) echo >&2 "$0: pointer not on any screen?"; exit 2 ;; esac
52
7e571efe 53case $(( $mul == $div )) in
56e4c6c0
MW
54 1) pan= ;;
55 *) pan="--panning ${XWIDTH}x${XHEIGHT}" ;;
56esac
57
58xrandr --fb ${XWIDTH}x${XHEIGHT} \
59 --output $name \
7e571efe 60 --mode $(( $mul*$XWIDTH/$div ))x$(( $mul*$XHEIGHT/$div )) \
56e4c6c0 61 $pan