#!/bin/sh

PATH="/usr/lib/alterator-x11:$PATH"

. shell-quote

out_from_db()
{
	#hsync
	echo "$1"|cut -f4 -d';'|
		sed -r 's,[[:space:]]*(.*),hsync:\1,'
	#vsync
	echo "$1"|cut -f5 -d';'|
		sed -r 's,[[:space:]]*(.*),vsync:\1,'
}

name="$(quote_sed_regexp "$1")"
dbout="$([ -n "$name" ] && mondrv|grep -m1 -i ";[[:space:]]*$name[[:space:]]*;")"

#monitor sync: prefer database
if [ -n "$dbout" ]; then
    out_from_db "$dbout"
else
    printf "hsync:%s\n" "$(monitor_ddc hsync)"
    printf "vsync:%s\n" "$(monitor_ddc vsync)"
fi

ddcscreen="$(monitor_ddc size)"

#monitor size: from ddc
if [ -n "$ddcscreen" ] ;then
	echo "$ddcscreen" |
	sed -r 's/[[:space:]]*([0-9]+)[[:space:]]([0-9]+).*/width:\10\nheight:\20/'
fi
