#!/bin/sh

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

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

size="$(ddcsize)"
xresolution=

# FIXME: this is geared towards CRT, TFTs should just get native resolution!
[ -n "$size" ] &&  xresolution="$(ddcreslist|ddcresbest "${size% *}" "${size#* }")"

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

resolution_setup "$xresolution" "$1"
