#!/bin/sh

# window geometry
wx="$1"
wy="$2"
ww="$3"
wh="$4"

# pointer position
px="$5"
py="$6"

# 1/hfactor of the window size is the hot area
hfactor=3
# but at least this many pixels
hminpix=20

# calculate hot areas
hwid="$[ww / hfactor]"
if [ "$hwid" -lt "$hminpix" ]; then
	hwid="$hminpix"
fi
if [ "$hwid" -gt "$[ww / 2]" ]; then
	hwid="$[ww / 2]"
fi
hhgt="$[wh / hfactor]"
if [ "$hhgt" -lt "$hminpix" ]; then
	hhgt="$hminpix"
fi
if [ "$hhgt" -gt "$[wh / 2]" ]; then
	hhgt="$[wh / 2]"
fi
hlft="$[wx + hwid]"
hrgt="$[wx + ww - 1 - hwid]"
htop="$[wy + hhgt]"
hbot="$[wy + wh - 1 - hhgt]"

# determine the direction
DIR=""
if [ "$py" -le "$htop" ]; then
	DIR="${DIR}N"
elif [ "$py" -ge "$hbot" ]; then
	DIR="${DIR}S"
fi
if [ "$px" -le "$hlft" ]; then
	DIR="${DIR}W"
elif [ "$px" -ge "$hrgt" ]; then
	DIR="${DIR}E"
fi

# do it
if [ "$DIR" = "" ]; then
	echo beep
	exit 1
else
	echo "Resize direction $DIR"
fi
