From cb413f94ce2cd07780082b28613856651082a925 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 8 Apr 2015 23:00:10 -0400 Subject: [PATCH] Fix resize.sh to work in dash. "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 | 65 ++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/scripts/resize.sh b/scripts/resize.sh index a375ddd..65d646c 100755 --- a/scripts/resize.sh +++ b/scripts/resize.sh @@ -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" -- 2.43.2