#!/bin/bash

# SetCustomResolution.bash
# 2013-04-07
# Chieh Cheng
# http://www.CynosureX.com/

# GNU General Public License (GPL) Version 2, June 1991

  scriptDir=`dirname "$0"`
  scriptName=`basename "$0"`

function usage ()
{
  echo "  Usage:   ${scriptName} width heigth frequency"
}

  if [ $# -eq 3 ]
  then
    width="$1"
    height="$2"
    hz="$3"

    device=`xrandr | grep 'connected' | sed 's/ .*//'`
    mode=`cvt ${width} ${height} ${hz} | grep 'Modeline' | sed 's/Modeline //'`
    name=`echo "${mode}" | sed 's/ .*//'`

    xrandr --newmode ${mode}
    xrandr --addmode ${device} ${name}
    xrandr --output ${device} --mode ${name}
  else
    usage
  fi
