#!/bin/sh

_CONF_FILE=$1
_FLAG_RESOLUTION=0
_FLAG_GAMMA=0
#_GET_CONNECTED_DISPLAY=`xrandr | grep -w connected | awk '{print $1}'`

source /etc/prime-display/$_CONF_FILE.conf

for arg in "$@"; do
	case "$arg" in
		-r|--resolution)
			_FLAG_RESOLUTION=1
			shift
			;;
		-g|--gamma)
			_FLAG_GAMMA=1
			shift
			;;
	esac
done

for d in "${DISPLAYS[@]}"
do
	if [[ ${_FLAG_RESOLUTION} -eq 1 ]]; then
		/usr/bin/xrandr --output $d \
			--mode $DISPLAY_RES \
			--rate $REFRESH_RATE \
	       		> /dev/null 2>&1
		sleep 5
	fi

	if [[ ${_FLAG_GAMMA} -eq 1 ]]; then

		if [[ ${GAMMA_DELAY} > 0 ]]; then
			sleep $GAMMA_DELAY
		fi

		/usr/bin/xrandr --output $d \
        		--gamma $R_GAMMA_VALUE:$G_GAMMA_VALUE:$B_GAMMA_VALUE \
        		--brightness $BRIGHTNESS \
         		> /dev/null 2>&1
	fi
done

exit 0
