#!/bin/bash # # Wrapper around xrandr to set screen resolution. # # Parameters BASENAME="`basename $0`" RESOLUTION="$1" INTERFACE="$2" #XRES="$1" #YRES="$2" #INTERFACE="$3" # Check #if [ -z "$Y" ]; then if [ -z "$RESOLUTION" ]; then #echo "usage: $BASENAME " echo "usage: $BASENAME x " echo "example:" echo "" echo " $BASENAME HDMI-2 1680x1050" echo "" echo "for simpler usage, try xrandr directly, like:" echo "" echo " xrandr --output HDMI-2 --mode 1680x1050" echo "" echo "Available screens and resolutions" echo "---------------------------------" echo "" xrandr exit 1 elif ! which cvt &> /dev/null; then echo "please install cvt from xserver-xorg-core" exit 1 elif ! which xrandr &> /dev/null; then echo "please install xrandr from x11-xserver-utils" exit 1 fi # Parse resolution XRES="`echo $RESOLUTION | cut -d 'x' -f 1`" YRES="`echo $RESOLUTION | cut -d 'x' -f 2`" # Check resolution if [ -z "$XRES" ]; then echo "$BASENAME: invalid value for x-res" exit 1 elif [ -z "$YRES" ]; then echo "$BASENAME: invalid value for y-res" exit 1 fi # Get modeline and interface MODELINE="`cvt $XRES $YRES | grep -v '^#' | sed -e 's/^Modeline //'`" NAME="`echo $MODELINE | cut -d ' ' -f 1 | sed -e 's/"//g'`" # Fallback to the first connected interface found if [ -z "$INTERFACE" ]; then INTERFACE="`xrandr | grep " connected" | cut -d ' ' -f 1 | head -1`" fi # Apply xrandr --newmode $MODELINE &> /dev/null xrandr --addmode $INTERFACE $NAME xrandr --output $INTERFACE --mode $NAME