#! /bin/zsh -feu

# invoke extern with the internal-panel device.
# Could get it from an /etc/ file.
# device="eDP1"

# when it's off it does not list!
# device=$(xrandr --listmonitors| grep '^ 0:'|cut -d ' '  -f 6)

device=$(xrandr | grep 'connected primary' | cut -f 1 -d ' ')

usage()
{
cat <<EOF
    usage: `basename $0` [+-shd] [--] ARGS...
-s ... set the size
EOF
}

ARGS=(-a)
OFF=n

while getopts :shd:o OPT; do
    case $OPT in
        s|+s)
            xrandr --size 0
            # by index! 1920x1080
            # xrandr --dpi 142x142

            # this is invoked by /etc/acpi/power.sh
            xrandr --dpi 106
            exit 0
            ;;
        h|+h)
            usage
            exit 0
            ;;
        o)
            OFF=y
            ARGS+=(-o)
            ;;
        d|+d)
            device=$OPTARG
            ;;
        *)
            usage>&2
            exit 2
    esac
done

shift `expr $OPTIND - 1`
OPTIND=1

$(dirname $0)/monitor-setup -d $device $ARGS

if [[ $OFF = 'n' &&  $(xrandr |grep ' connected'|wc -l) = 1 ]]
then
   echo "we are the only -> resize!"
   xrandr --size 0
fi
