#!/bin/sh

## Includes.
. funcrcSet

## Save window dimensions.
## On entry: $1 = window title

funcWindowDimSave() {
	if [ -z "$BASH" ]; then local FUNCNAME=funcWindowDimSave; fi
	if [ $DEBUG_TRANSITS -ne 0 ]; then echo "$FUNCNAME(): IN"; fi

	## Local variables.
	local line width height
	local found=0

	## This is the recommended portable way to check for
	## the existence of an executable within the path.
	if [ `command -v xwininfo` ]; then

		## xwininfo returns stats by default but it'll print info if
		## the named window exists or not so this must be checked for.
		xwininfo -name "$1" > $TEMP_DIR/XWinInfo
		while read -r line; do
			case $line in
				xwininfo:*\"$1\")
					found=1 ;;
				Width:*)
					## Get text after first ':'
					width=${line#*:} ;;
				Height:*)
					## Get text after first ':'
					height=${line#*:} ;;
			esac
		done < $TEMP_DIR/XWinInfo

		if [ $found -eq 1 ]; then
			funcrcSet WindowWidth $width
			funcrcSet WindowHeight $height
		fi
	else
		echo "$FUNCNAME(): xwininfo is required to save the window dimensions."
	fi

	if [ $DEBUG_TRANSITS -ne 0 ]; then echo "$FUNCNAME(): OUT"; fi
}
