#!/bin/sh

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

tail_res()
{
    sed -n "/$1/,\$ p" /usr/share/alterator-x11/resolutions|
	tac|
	tr '\n' ','|
	sed 's/,$//'
}

size="$(ddcsize)"
xresolution=

[ -n "$size" ] &&  xresolution="$(ddcreslist|ddcresbest "${size% *}" "${size#* }")"

if [ -n "$xresolution" ];then
    xresolution="$(tail_res "$xresolution")"
else
    xresolution="auto"
fi

xconf -R "$xresolution" "$1" "$1"
