Created
October 15, 2020 17:42
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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