Setting custom resolution in linux via xrandr
In case you want to add a custom resolution for your screen that is missing from the options, just follow the next simple steps:
Generate a new modeline
The following example is adding a 1080p resolution:
cvt 1920 1200 60
which will return something like this:
# 1920x1200 59.88 Hz (CVT 2.30MA) hsync: 74.56 kHz; pclk: 193.25 MHz Modeline "1920x1200_60.00" 193.25 1920 2056 2256 2592 1200 1203 1209 1245 -hsync +vsync
The important piece of information to keep for the next step is “1920x1200_60.00” 193.25 1920 2056 2256 2592 1200 1203 1209 1245 -hsync +vsync .
Add new modeline to xrandr
xrandr --newmode "1920x1200_60.00" 193.25 1920 2056 2256 2592 1200 1203 1209 1245 -hsync +vsync
Add a mode to the set of valid modes
DISP=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") xrandr --addmode $DISP 1920x1200_60.00
Make changes permanent
Create the file ~/.xprofile with the content:
#!/bin/sh xrandr --newmode "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync xrandr --addmode VGA-0 1680x1050_60.00
One command setup
OK, if you are too lazy to follow all the steps above one-by-one, just use this one-command-solution:
RES="1920 1200 60" && \ DISP=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") && \ MODELINE=$(cvt $(echo $RES) | grep -e "Modeline [^(]" | sed -r 's/.*Modeline (.*)/\1/') && \ MODERES=$(echo $MODELINE | grep -o -P '(?<=").*(?=")') && \ xrandr --newmode $MODELINE && \ xrandr --addmode $DISP $MODERES
And to generate the ~/.xprofile file:
RES="1920 1200 60" && \ DISP=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") && \ MODELINE=$(cvt $(echo $RES) | grep -e "Modeline [^(]" | sed -r 's/.*Modeline (.*)/\1/') && \ MODERES=$(echo $MODELINE | grep -o -P '(?<=").*(?=")') && \ cat > ~/.xprofile << _EOF #!/bin/sh xrandr --newmode $MODELINE xrandr --addmode $DISP $MODERES _EOF
Just make sure you select the right RES variable for your needs!