How do I save my new resolution setting with xrandr?

I found somewhere in a forum the solution to a problem where the only resolutions available were 800x600 and 1024x768. I managed to get 1440x900, which works very well. Every time I reboot, this mode disappears. I am forced to retype the commands, so how can I save this? I'm assuming it is a simple command, but I am the largest of noobs when it comes to Ubuntu. The commands are:

  • xrandr --newmode "1440x900_60.00" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
  • xrandr --addmode VGA1 1440x900_60.00
  • xrandr --output VGA1 --mode 1440x900_60.00

Solution 1:

You have several choices but perhaps the easiest is to place your command exactly as you have given above in your $HOME/.xprofile file. From this location it will be executed every time you login.

By default this file does not exist in Ubuntu and so may need to be created manually and then be made executable. The following commands will do this:

touch $HOME/.xprofile
chmod +x $HOME/.xprofile

Note the 2 small shortcomings of this method:

  1. .xprofile is accessed occurs fairly late in the startup process so you may see some initial screen resolution resizing
  2. This is a 'per user' setting and may need to be repeated for other users on your system

If you wish to delve deeper there are a few other choices available in the reference link below, but the technique I have described here is still the safest and easiest.

References:

  • Setting xrandr changes persistently

Solution 2:

The accepted answer applies the same configuration regardless of the status of connected displays. This didn't work for me, as I'm connected to different displays at work and at home. autorandr allows automatic xrandr configurations for different display setup. To use autorandr,

  1. Install with sudo apt install autorandr (tested on Ubuntu 18.04, Lubuntu 20.04)
  2. Configure your monitor to your liking with xrandr
  3. Store your configuration with autorandr --save work (I'm storing my work config, choose a name that suits you)
  4. Resume the config with autorandr --change work to choose config, or just autorandr --change to have it infer your config from your connected monitors.

XDG autostart .desktop is also provided, and installed into /etc/xdg/autostart/autorandr.desktop by default. When you reconnect your work monitor, the work setup will be reloaded.