Saturday, April 2, 2016

How to set custom screen resolution in X-Windows

This post will explain step-by-step how to configure custom screen resolutions in X-Windows. This may be useful in situaction when, for example the system is unable to automatically detect all modes supported by monitor, or when we are working on a virtual machine (VMWare, Parallels, etc.) and want to adjust the screen size to the host. To list all available modes we have to open the Terminal (Ctrl+Alt+T) and type the following command:
xrandr
The output will look similar to this:

We can then select desired mode using command:
xrandr -s [selected mode]
If the mode that we are interested in is not listed, it will be necessary to add it manually. The first step is to create a proper modeline using CVT:
cvt 960 1080 60
CVT is a built-in tool which calculates and prints out valid VESA Coordinated Video Timing modeline for given screen resolution and refresh rate.

Once that step is done, it's time to add the mode to the set of valid modes for our output:
xrandr --newmode "960x1080_60.00"   86.00  960 1024 1120 1280  1080 1083 1093 1120 -hsync +vsync
xrandr --addmode Virtual1 "960x1080_60.00"
Note that the params used for the --newmode command are copied exactly from the output of the cvt command. Also, the --addmode operation requires the name of the device the mode will be associated with. In my case it was "Virtual1".



To confirm that the mode has been successfully added, run xrandr again:



That's it. Now we can select the mode using:
xrandr -s "960x1080_60.00"
To delete it from the list use the following commands:
xrandr --delmode Virtual1 "960x1080_60.00
xrandr --rmmode "960x1080_60.00


The above steps explain how to dynamically create and set custom screen resolution. However this will only last until the system is rebooted. To make the changes persistent we will have to use X-Windows configuration files. Here's how to do it:
cd /usr/share/X11/xorg.conf.d
sudo touch 10-monitor.conf
sudo notepadqq 10-monitor.conf
I'm using notepadqq to edit text files, but any other will do as well. Here's the content of the file:
Section "Monitor"
 Identifier "Virtual Monitor"
 Modeline "960x1080_60.00" 86.00 960 1024 1120 1280 1080 1083 1093 1120 -hsync +vsync
EndSection

Section "Screen"
 Identifier "Default Screen"
 Device "Virtual1"
 Monitor "Virtual Monitor"
 DefaultDepth 24
 SubSection "Display"
  Modes "960x1080_60.00"
 EndSubSection
EndSection
/usr/share/X11/xorg.conf.d stores configuration files for the X Server. All files in the directory have specific format and contain various parameters used to configure the system.