Skip to content

Instantly share code, notes, and snippets.

@palesz
Created October 15, 2020 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palesz/8cb1d22c8d3252878f5a4f201f064060 to your computer and use it in GitHub Desktop.
Save palesz/8cb1d22c8d3252878f5a4f201f064060 to your computer and use it in GitHub Desktop.
Set a custom resolution using xrandr (even if the resolution currently does not exist)
#!/bin/sh
set -eux
width=${1:-2560}
height=${2:-1080}
newresandrate="$width $height 60"
modeline=`cvt $newresandrate | grep Modeline | sed 's/Modeline //g'`
modetitle=`echo $modeline | grep -o "\"[^\"]*\""`
connected_device=`xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/"`
echo $modeline
echo $modetitle
echo $connected_device
if [[ `xrandr | grep $modetitle | wc -l` -lt 1 ]]; then
echo "Adding the new mode to xrandr"
sudo xrandr --newmode $modeline
sudo xrandr --addmode $connected_device $modetitle
fi
xrandr -s ${width}x${height}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment