X-Git-Url: https://git.draconx.ca/gitweb/fvwmconf.git/blobdiff_plain/61db326451517da54d7bf4ec3216effd5a774900..cb413f94ce2cd07780082b28613856651082a925:/scripts/resize.sh 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"