145

I tried to use xrandr to set 1680x1050 as a new mode to VGA output, but it says:

sudo xrandr --addmode VGA-0 1680
X Error of failed request:  BadMatch (invalid parameter attributes)
Major opcode of failed request:  140 (RANDR)
Minor opcode of failed request:  18 (RRAddOutputMode)
Serial number of failed request:  35
Current serial number in output stream:  36

6 Answers 6

231

First generate a "modeline" by using cvt
Syntax is: cvt width height refreshrate

cvt 1680 1050 60

this gives you:

# 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
Modeline "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync

Now tell this to xrandr:

xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync

Then you can now add it to the table of possible resolutions of an output of your choice:

xrandr --addmode VGA-0 1680x1050_60.00

The changes are lost after reboot, to set up the resolution persistently, 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

You need to replace VGA-0 with your monitor connection. Use xrandr --listmonitors.

22
  • 34
    The connected device might not be VGA-0. If you get the message xrandr: cannot find output "VGA-0", try running the following command: xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/" (source: xrandr on ArchWiki). The output of that command should be the correct device identifier.
    – thirdender
    Jul 9, 2014 at 6:25
  • 14
    You do not need sudo with xrandr
    – Panther
    Oct 12, 2015 at 18:14
  • 5
    If you're on a VM, the display is usually Virtual1 instead of VGA-0.
    – CyberEd
    Mar 22, 2016 at 22:37
  • 5
    I get this error : X Error of failed request: BadMatch (invalid parameter attributes) Major opcode of failed request: 140 (RANDR) Minor opcode of failed request: 18 (RRAddOutputMode) Serial number of failed request: 37 Current serial number in output stream: 38 Jul 7, 2017 at 18:06
  • 10
    You need to replace VGA-0 with your monitor connection. Use xrandr --listmonitors. See How to fix error 'xrandr: cannot find output “VGA1”'?
    – Human
    Mar 7, 2018 at 5:27
23

How to set a custom resolution previously specified. After executing the other steps defined to create the resolution, run:

xrandr -s 1680x1050
2
  • This yield an error: Size [width]x[height] not found in available modes Jan 30, 2023 at 0:23
  • You have to do both "--newmode" to define a mode ("add mode to server") and "--addmode" to allow the newly added mode to be used for a given output ("add mode to output connetor"). Only then you can activate that mode for that output. Oct 17, 2023 at 13:14
14

How to set a custom resolution previously specified when running multiple monitors. After executing the other steps defined to create the resolution, run:

xrandr --output DVI-0 --mode 1680x1050

Replace DVI-0 with your device-id, e.g. VGA-0

2
  • Great, how do I get my device-id? Jan 30, 2023 at 0:22
  • @aggregate1166877 you can see it through "xrandr" without options. there is a list of devices and if they are connected. mines are DP-0 & DP-2 Mar 26, 2023 at 19:04
13

Thanks to thom and thirdender this is basically a single command configuration based on the most voted answer.

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

The above command will generate the desired ~/.xprofile file. Just make sure you use the resolution (i.e. the RES variable) of your liking. More info here.

You could replace

xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/"

with

xrandr | grep -e " connected [^(]" | cut -d\  -f1

in $DISP variable if that does not work for you.

2
  • Thanx for this one. It did the job for me. But to make it work, the user should run "cvt 1920 1200 60" command first. Because resolution isn't exist yet. May 13, 2021 at 10:22
  • The script contains MODELINE=$(cvt $(echo $RES) ... which will run the required cvt command to generate the correct modeline. Oct 17, 2023 at 13:02
3

Definitely you have to take a look at autorandr, there seems to be no easier way.

This is the man page (from Ubuntu): http://manpages.ubuntu.com/manpages/bionic/man1/autorandr.1.html

And this is the source code: https://github.com/phillipberndt/autorandr

Install it in Ubuntu with:

sudo apt install autorandr

Then just save your current config with:

autorandr -s myFaveConfig

and change config and save others with

autorandr -s myOtherConfig

Then just apply them whenever you want with:

autorandr [theConfigIwant]

for example:

autorandr myFaveConfig

will load the first config you saved in this example.

Nothing easier !!

0

Have you already installed the nvidia video driver? I had problems with low resolution and discovered that my system was without nvidia driver. I don't have the exact command now, but is something like this, I suggest doing a resarch for it:

sudo apt install nvidia-driver-[version]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .