]> git.draconx.ca Git - fvwmconf.git/commitdiff
Fix resize.sh to work in dash.
authorNick Bowler <nbowler@draconx.ca>
Thu, 9 Apr 2015 03:00:10 +0000 (23:00 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 9 Apr 2015 03:00:10 +0000 (23:00 -0400)
"echo -n" is not portable to dash, so this script breaks horribly.
Avoid that, but also just rewrite the script because those shell
tests are awful and we can do better with grid coordinates.

scripts/resize.sh

index a375ddd5f589da97ef66b06ab1404fe73a89d036..65d646c072d2cc24c5a2b26c56230e15f5548809 100755 (executable)
@@ -1,36 +1,49 @@
 #!/bin/sh
-# resize.sh mouseX mouseY windowW windowH
+#
+# Copyright © 2008, 2015 Nick Bowler
+#
 # Emits an FVWM directed resize command based on the position of the mouse
 # cursor within a window (mouseX, mouseY) and the width and height of the
 # window (windowW, windowH).
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
 
 if [ $# -lt 4 ]; then
-       echo "usage: $0 mouseX mouseY windowW windowH"
+       printf 'usage: %s mouseX mouseY windowW windowH\n' "$0" 1>&2
        exit 1
 fi
 
-echo -n "Resize Direction "
+# The window's area is divided into a 4x4 grid of equally sized rectangles.
+# We return a resize direction depending on which rectangle was clicked,
+# according to the following diagram:
+#
+#            ┏━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━┓
+#            ┃ NorthWest │         North         │ NorthEast ┃
+#            ┠───────────┼───────────┬───────────┼───────────┨
+#            ┃           │ NorthWest │ NorthEast │           ┃
+#            ┃   West    ├───────────┼───────────┤    East   ┃
+#            ┃           │ SouthWest │ SouthEast │           ┃
+#            ┠───────────┼───────────┴───────────┼───────────┨
+#            ┃ SouthWest │         South         │ SouthEast ┃
+#            ┗━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┛
 
-# Straight directions
-if [ $1 -le $(($3/4)) -a $2 -ge $(($4/3)) -a $2 -le $(($4/3*2)) ]; then
-       echo "West"
-elif [ $1 -ge $(($3/4*3)) -a $2 -ge $(($4/3)) -a $2 -le $(($4/3*2)) ]; then
-       echo "East"
-elif [ $2 -le $(($4/4)) -a $1 -ge $(($3/3)) -a $1 -le $(($3/3*2)) ]; then
-       echo "North"
-elif [ $2 -ge $(($4/4*3)) -a $1 -ge $(($3/3)) -a $1 -le $(($3/3*2)) ]; then
-       echo "South"
-# Quadrants
-elif [ $1 -le $(($3/2)) ]; then
-       if [ $2 -le $(($4/2)) ]; then
-               echo "NorthWest"
-       else
-               echo "SouthWest"
-       fi
-else
-       if [ $2 -le $(($4/2)) ]; then
-               echo "NorthEast"
-       else
-               echo "SouthEast"
-       fi
-fi
+rect_w=$(($3/4))
+rect_h=$(($4/4))
+grid_x=$(($1/$rect_w))
+grid_y=$(($2/$rect_h))
+
+case $grid_x$grid_y in
+11|00) dir=NorthWest ;;
+21|30) dir=NorthEast ;;
+12|03) dir=SouthWest ;;
+22|33) dir=SouthEast ;;
+?0) dir=North ;;
+0?) dir=West ;;
+3?) dir=East ;;
+?3) dir=South ;;
+*) exit 1 ;;
+esac
+
+printf 'Resize Direction %s\n' "$dir"