140

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
Dagelf
  • 1,105
  • 11
  • 17
user216356
  • 1,401
  • 2
  • 10
  • 3

5 Answers5

224

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.

Elder Geek
  • 35,476
  • 25
  • 95
  • 181
thom
  • 7,372
  • 3
  • 24
  • 26
  • 33
    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](https://wiki.archlinux.org/index.php/xrandr)). The output of that command should be the correct device identifier. – thirdender Jul 09 '14 at 06:25
  • 13
    You do not need sudo with xrandr – Panther Oct 12 '15 at 18:14
  • 3
    I would like to add that I have the same error - and the above does not solve the problem at all – TellMeWhy Oct 13 '15 at 09:35
  • 5
    If you're on a VM, the display is usually `Virtual1` instead of VGA-0. – CyberEd Mar 22 '16 at 22:37
  • Ubuntu freezes when I try that solution. Using `Ctrl+Alt+F1` I can restart Unity, but then the custom resolution disappears – Nitay Jun 08 '16 at 15:26
  • 1
    @thirdender after your command, with `xrandr --addmode "DVI-I-1" "1280x800_60.00"` gave me the same error "BadMatch", any idea? – Aquarius Power Jan 01 '17 at 21:00
  • 4
    @AquariusPower, try adding `--verbose` to your command and see if there is any useful output. Also see [Why do xrandr errors “BadMatch”, “BadName”, “Gamma Failed” happen?](http://askubuntu.com/a/727897/181902) – thirdender Jan 02 '17 at 03:01
  • use `arandr` to find the VGA number instead of default VGA-0 as in the answer – kittu May 07 '17 at 07:31
  • 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 – ChameleonScales Jul 07 '17 at 18:06
  • 1
    After `xrandr --newmode` command - you can reconnect your display and it will automagically pick the newly added resolution ;) – jabu.hlong Feb 15 '18 at 21:24
  • 10
    You need to replace VGA-0 with your monitor connection. Use `xrandr --listmonitors`. See [How to fix error 'xrandr: cannot find output “VGA1”'?](https://unix.stackexchange.com/a/413304) – Human Mar 07 '18 at 05:27
  • Also, for Ubuntu 17.10 I had to [Disable Wayland](https://askubuntu.com/questions/975094/how-to-disable-wayland-in-17-10-in-gdm3-login-screen) for this to work. – Human Mar 07 '18 at 05:32
  • This worked perfectly for me. I have an MST dock, with a monitor that outputs 1080p over DVI. A DVI -> DisplayPort adapter. The monitor only reported 1024x768 to xrandr, but I knew it would support 1080p. – MattBoothDev May 22 '19 at 08:25
  • To only see active monitors, use `xrandr --listactivemonitors` – Simon Baars Aug 22 '19 at 06:33
  • Thank you! Magic happens with this answer. – Ahmed Ibrahim Jun 04 '20 at 18:09
  • 1
    I get this error after newmode: "Failed to get size of gamma for output default" – roadev Aug 23 '21 at 19:32
  • It was not working in ubuntu 21.04, finally I have update the file /etc/gdm3/custom.conf by uncommenting the line WaylandEnable=false to make it work. Thank you – Shyju M Aug 30 '21 at 13:05
  • This works, except that the login screen still runs at a low resolution. How do I make this resolution work at the login screen? – Aaron Franke Dec 16 '21 at 03:05
  • The modeline generated by cvt didn't work for me, maybe my monitor uses different standard. Using `grep -n Modeline /var/log/Xorg.0.log` I noticed that the newly added modeline was much different from the pre-existing ones. For example, my pre-existing modelines had `+hsync -vsync` whereas output of `cvt` had `-hsync +vsync`. So I had to change cvt output to match pre-existing modelines to make it work. – Nafiur Rahman Khadem Feb 21 '22 at 13:53
  • 1
    I had to use `cvt -r` to create a *reduced blanking* modeline for my 4K setup (3840x2160@60Hz). Without `-r` it didn't work. – sebastian May 12 '22 at 12:35
  • @sebastian Thanks for sharing! This also works on my LG 2500x1080... Thanks for sharing! Works on Fedora 36 with XFCE Spin with xorg :) – Benyamin Limanto Nov 29 '22 at 13:12
  • if you get "Xrandr not recognizing '-HSync' as an option" - https://superuser.com/questions/1279750/xrandr-not-recognizing-hsync-as-an-option basically don't copy the "Modeline", just the part after that :-) – jave.web Feb 23 '23 at 09:48
23

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

xrandr -s 1680x1050
Eric Leschinski
  • 2,181
  • 1
  • 20
  • 23
GuiRitter
  • 331
  • 2
  • 5
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

zwessels
  • 267
  • 2
  • 9
12

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.

Gryu
  • 7,279
  • 9
  • 31
  • 52
Tanasis
  • 466
  • 5
  • 8
  • 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. – deeptionary May 13 '21 at 10:22
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 !!

Dan Ortega
  • 168
  • 7