linux-mint – How to get external monitor resolution set by xrandr to persist

linux-mintmulti-monitorresolutionxrandr

tl;dr

My laptop keeps forgetting the correct resolution of the external monitor attached to it. How can I make the configuration "stick"?

Details

I have a laptop running Linux Mint attached to an external ViewSonic monitor. I set it up to use the external monitor as a second screen (i.e. not mirrored). This worked fine for some weeks.

Suddenly, the laptop no longer recognized it as a ViewSonic, at which point it did not know its optimal resolution (1600 x 1200), only allowing a max of 1028 x 768.1 This did not work well at all with my laptop, which has 1920 x 1200 resolution.

After much frustration, I found this answer. It helped me to fix the problem, as follows (the output of the cvt command being the modeline which was used in the next command):

cvt 1600 1200
xrandr --newmode "1600x1200_60.00"  161.00  1600 1712 1880 2160  1200 1203 1207 1245 -hsync +vsync
xrandr --addmode VGA-1 1600x1200_60.00

This is exactly what I had been wishing I could do, but could not do through the GUI. (There are reasons why I still love the command-line…)

This once again worked well for a time. However, when I booted the computer today and signed in, I got a notification area popup with a string of errors about different attempted modes which weren't working, and the external monitor was switched off. I repeated the commands above, and it is working again.

I have an nVidia card. I tried installing the proprietary driver when things began to go awry, but at that point the external monitor was no longer recognized at all, so I am back to the open source driver. I do not have an Xorg.conf or an Xorg.conf.d, only an xorg.conf.failsafe.

I don't want to repeat these commands every time I boot the machine. Is there some way I can get this saved to my Xorg.conf or something? It's been a number of years since I've done much with X. Can anybody help me here?


1I have been unable to determine why this happened. My best guess is a problematic driver update.

Best Answer

I'm sure there's a better way, I think this is all handled by udev now but if you know that those commands will solve it, you could always just make them into a script:

#!/usr/bin/env bash
cvt 1600 1200
xrandr --newmode "1600x1200_60.00"  161.00  1600 1712 1880 2160  1200 1203 1207 1245 -hsync +vsync
xrandr --addmode VGA-1 1600x1200_60.00

Make it executable and then add it to your Desktop Environment's startup applications. This is probably the best choice if your DE provides you with the option.


If you can't do the above, as a dirty hack you could add them to your ~/.profile:

if [ ! -t 0 ] 
then
    cvt 1600 1200
    xrandr --newmode "1600x1200_60.00"  161.00  1600 1712 1880 2160  1200 1203 1207 1245 -hsync +vsync
    xrandr --addmode VGA-1 1600x1200_60.00
fi

The if [ ! -t 0 ] should ensure this is only run in the GUI and .profile is sourced by mint's login manager as I recall.

Now, you should also be able to use ~/.xsession but I've had issues with that being ignored. A lot of the older approaches are being replaced and I'm not sure what the state of the art way is.

Related Question