bin/xzoomscr: New script and bindings to control XRANDR zoomy panny stuff.
[profile] / bin / xzoomscr
diff --git a/bin/xzoomscr b/bin/xzoomscr
new file mode 100755 (executable)
index 0000000..f852297
--- /dev/null
@@ -0,0 +1,51 @@
+#! /bin/sh -e
+
+case $# in 1) ;; *) echo >&2 "usage: $1 ZOOM"; exit 2 ;; esac
+zoom=$1
+
+ok=nil
+case ${DISPLAY-nil} in
+  *:*[!0-9.]*) ;;
+  *:*.*.*) ;;
+  *:*.*) ok=t dpybase=${DISPLAY%.*} ;;
+  *:*) ok=t dpybase=$DISPLAY ;;
+esac
+case ok in nil) echo >&2 "$0: bad DISPLAY"; exit 2 ;; esac
+
+set -- $(xqueryptr); scr=$1 x=$2 y=$3
+DISPLAY=$dpybase.$scr; export DISPLAY
+
+eval $(xscsize -b)
+
+case $(( $XWIDTH % $zoom || XHEIGHT % $zoom )) in
+  0) ;;
+  *) echo >&2 "$0: zoom multiplier doesn't divide screen size"; exit 2 ;;
+esac
+
+{ read _
+  found=nil
+  while read _ _ respos name; do
+    res=${respos%%+*} pos=${respos#*+}
+    ww=${res%x*} hh=${res#*x}
+    w=${ww%/*} h=${hh%/*}
+    x0=${pos%+*} y0=${pos#*+}
+    x1=$(( $x0 + $w )) y1=$(( $y0 + $h ))
+    case $(( $x0 <= $x && $x < $x1 && $y0 <= $y && $y < $y1 )) in
+      1) found=t; break ;;
+    esac
+  done
+} <<EOF
+$(xrandr --listmonitors)
+EOF
+
+case $found in nil) echo >&2 "$0: pointer not on any screen?"; exit 2 ;; esac
+
+case $zoom in
+  1) pan= ;;
+  *) pan="--panning ${XWIDTH}x${XHEIGHT}" ;;
+esac
+
+xrandr --fb ${XWIDTH}x${XHEIGHT} \
+       --output $name \
+       --mode $(( $XWIDTH/$zoom ))x$(( $XHEIGHT/$zoom )) \
+       $pan