quarta-feira, 11 de maio de 2016

How to make xrandr custom resolution permanent on Ubuntu 16.04 LTS!!

Back to the xrandr issue again. I realized that making the custom resolution permanent is not so simple as I would think. You may find many solutions talking about xorg.conf, but it seems this is deprecated for a long time. You may also find solutions to load the script on the user login (other users won't have access to the custom resolution), or using some weird way out from X11 or Gnome or KDE. The thing is: none of this solution seems to fit on Ubuntu 16.04, which uses Unity and LigthDM.
I didn't go deep on this, but it looks like the best way to add custom resolutions is using the LigthDM setup.

From here (https://wiki.ubuntu.com/LightDM), ligthDM is:

LightDM is the display manager running in Ubuntu. It starts the X servers, user sessions and greeter (login screen). The default greeter in Ubuntu is Unity Greeter. 

And we'll use this option:

display-setup-script is run after the X server starts but before the user session / greeter is run. Set this if you need to configure anything special in the X server. It is run as root. If this command returns an error code the X server is stopped. 

So, suppose you already has the xrandr parameters and know what is the customs resolution you want (if not look here: http://mylowtechstuff.blogspot.com.br/2016/02/overscanunderscan-on-hdmi-using-ubuntu.html ) .

Lets makes a script file (in my case /home/jairo/tvPanasonic.sh):

#!/bin/bash
xrandr --newmode  "1208x679" 74.25 1208 1353 1393 1650 679 707 712 750 +hsync +vsync
xrandr --addmode HDMI1 "1208x679"


It is very important to note that we are just adding a new resolution here, and not enabling it (#xrandr --output  HDMI1 --mode "1208x679").  This is important because if there is some problem, or if you change the monitor or port you may have problem like Ubuntu windows not loading. So, don't enable the custom resolution, just make it available so later you can go to the System Settings/Display and pick the custom resolution there. If something is wrong the system must be smart enough to find a new working resolution. So, DON'T force the custom resolution from the script file.

Don't forget to make the script executable:

chmod +x /home/jairo/txPanasonic.sh

Edit the lightdm.conf file:

sudo nano /etc/lightdm/lightdm.conf 

and add the display-setup-script just like the example bellow:

[Seat:*]
autologin-guest=false
autologin-user=jairo
autologin-user-timeout=0

display-setup-script=/home/jairo/tvPanasonic.sh


Restart the Ubuntu, and now you can find the custom resolution on the Systems settings/Display:

 

This should make the custom resolution available every time you turn the system on and will load it. If you change or disconnect the monitor it should keep working because we did not force the system to use an static video configuration (at least I hope this...didn't test).