Software & AppsOperating SystemLinux

Saving xrandr Resolution Settings on Ubuntu

Ubuntu 21

In this article, we will explore how to save xrandr resolution settings on Ubuntu. xrandr is a command-line tool used for setting the size, orientation, and reflection of the outputs for a screen. It’s a powerful tool, but changes made with it are not saved across sessions. This means that if you change your resolution settings, they will be reset the next time you log in. However, there are ways to make these changes persistent.

Method 1: Using xorg.conf

The first method involves using the xorg.conf file. This file is used by the X Window System (the graphical subsystem of most Unix-like operating systems, including Ubuntu) to configure the graphics settings.

Step 1: Open xorg.conf

Open a terminal and run the following command:

sudo nano /etc/X11/xorg.conf

This command uses the sudo command to run the nano text editor with root privileges, and opens the xorg.conf file located in the /etc/X11/ directory.

Step 2: Edit xorg.conf

Add the following lines to the file:

Section "Monitor"
 Identifier "VGA1"
 Modeline "1440x900_60.00" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
EndSection

In this code, Section "Monitor" begins a new section for monitor settings. Identifier "VGA1" sets the identifier for the monitor to VGA1. The Modeline line defines a new mode for the monitor, with the resolution set to 1440×900 and the refresh rate set to 60.00 Hz. The numbers following the resolution and refresh rate are the horizontal and vertical sync values, which control the timing of the monitor.

Step 3: Save and Exit

Save the file and exit the text editor. In nano, you can do this by pressing Ctrl+X, then Y to confirm that you want to save the changes, and then Enter to confirm the file name.

Step 4: Reboot

Reboot your system for the changes to take effect.

Method 2: Using a Startup Script

The second method involves creating a startup script that runs every time you log in.

Step 1: Create .xprofile

Open a terminal and run the following command:

nano ~/.xprofile

This command opens the .xprofile file in your home directory (indicated by the ~ character) in the nano text editor. If the file doesn’t exist, this command will create it.

Step 2: Edit .xprofile

Add the following lines to the file:

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

These commands create a new mode with the xrandr --newmode command, add it to the available modes for the monitor with the xrandr --addmode command, and then set the monitor to use this mode with the xrandr --output command.

Step 3: Make .xprofile Executable

Make the .xprofile file executable by running the following command:

chmod +x ~/.xprofile

This command changes the permissions of the .xprofile file to make it executable. The chmod command changes the permissions, and the +x option adds the executable permission.

Step 4: Reboot

Reboot your system for the changes to take effect.

Method 3: Using autorandr

The third method involves using autorandr, a tool that automatically applies xrandr settings when monitors are connected.

Step 1: Install autorandr

Install autorandr by running the following command:

sudo apt install autorandr

This command uses the sudo command to run the apt install command with root privileges, which installs the autorandr package.

Step 2: Configure and Save

Configure your monitor to your desired resolution using the xrandr command, and then save your configuration with the following command:

autorandr --save <config_name>

Replace <config_name> with a name of your choice. This command saves the current monitor configuration under the given name.

Step 3: Create autorandr.desktop

To automatically apply the saved configuration on startup, create a new file ~/.config/autostart/autorandr.desktop with the following contents:

[Desktop Entry]
Type=Application
Name=Autorandr
Exec=autorandr --change <config_name>

Replace <config_name> with the name you used in the previous step. This file is a desktop entry that is automatically run when you log in, and it runs the autorandr --change command to apply the saved configuration.

Step 4: Reboot

Reboot your system for the changes to take effect.

By following these methods, you can make your xrandr resolution settings persistent across sessions on Ubuntu.

What is xrandr?

xrandr is a command-line tool used for setting the size, orientation, and reflection of the outputs for a screen on Ubuntu.

Why are changes made with xrandr not saved across sessions?

Changes made with xrandr are not saved across sessions because they are not automatically written to a configuration file.

Leave a Comment

Your email address will not be published. Required fields are marked *