Wednesday, 4 October 2017

How to set a custom display resolution in Xubuntu

This is the way to mirror my pair of screens on my bedroom PC. One screen is 1360x768 (a little odd) and the other is 1680x1050. The default mirroring in XFCE will only run them both at a 4:3 resolution like 1280x1024, since this is the highest resolution they are both compatible with, even though the aspect ratio is wrong and so a part of the screen is not actually used.

x.org server ships with a command line tool called xrandr. This is capable of changing the display settings on the fly and in this case the command we want is either of the following:
xrandr --fb 1360x768 --output VGA-0 --mode 1360x768 --scale 1x1 --output HDMI-0 --same-as VGA-0 --mode 1680x1050 --scale-from 1360x768
Alternate form (which I also tested): 
xrandr --fb 1680x1050 --output HDMI-0 --mode 1680x1050 --scale 1x1 --output VGA-0 --same-as HDMI-0 --mode 1360x768 --scale-from 1680x1050
Which one you use will depend on which screen it is more important to run in native mode. At the moment I am using the first option, as it gives a native size picture on the 1360x768 screen which is the easiest to read bedside screen. The important difference over what xfce4-display-settings can achieve is that one of the screens can be scaled to match the other. It would also be possible to have some oddball configurations like three displays with two of them an extended desktop and one mirroring one of the others.

Running this command only lasts as long as the next boot. In order to make it come into effect at every startup it needs to be put into a file that the LightDM window manager executes when it initialises.

In this case, after looking at the Ubuntu documentation over here on the wiki, I made a file in the path /etc/lightdm/lightdm.conf.d and called it 50-myconfig.conf

The contents of this file are just two lines:
[Seat:*]
display-setup-script=xrandr --fb 1360x768 --output VGA-0 --mode 1360x768 --scale 1x1 --output HDMI-0 --same-as VGA-0 --mode 1680x1050 --scale-from 1360x768
Basically display-setup-script is a prefix that tells LightDM to run this command after it starts the X server, and then it is the xrandr command I mentioned above.

Just as an aside, right now I am looking at putting MainPC to Debian 9.1 with XFCE as the front end. The issues to be resolved will be how to get a more up to date version of XFCE than the default from the Debian repository, this will probably entail using the unstable repositories. This will all be tested out in a VM before migrating. No other computers are planned to be shifted, it is mostly about getting the best system on a PC that is used for the most work I do.

[UPDATE] When I reinstalled the bedroom PC with Debian recently I had to put this setting back in to the computer. The PC is also using XFCE as its GUI and the settings were the same, except I put the display-setup-script line into /etc/lightdm/lightdm.conf file. An interesting twist was I had to install some extra packages for Radeon drivers before Xrandr could detect the display settings and ports properly. Since there have been questions over video performance on this computer with late releases of Xubuntu it will make an interesting comparison. Although, this tiny PC is to get a makeover soon with a Asrock Q1900 board that will run Intel chipset and graphics which will help a lot because of better support in Linux.