How to force Multiple Monitors correct resolutions for LightDM?

NOTE: I also posted this answer here

I found a very simple workaround that works perfectly for me running 13.04. on a laptop with a 24" external screen that is not permanently connected.

I'll just copy from here

  1. log in
  2. use xrandr or the Displays control utility to configure your monitors how you'd like them to be configured in the login screen
  3. sudo cp ~/.config/monitors.xml /var/lib/lightdm/.config/

Since I already had my monitors configured properly I just had to do step 3.


I managed this little basic script below that answers my question. Now, whether the external monitor is connected or not, Lightdm uses the right resolutions at the greeter stage. Nevertheless, this same script needs to be modified to be generic, in a way that the user wouldn't need to specify manually resolutions of its laptop and monitor screens.

 (Parse the output of `XRAND -q` command, 
identify the connected devices, 
grab their first/maximum resolutions 
and use `XRANDR --output` to display them). 

So if someone has a better solution or a more generic script, he's the man.

SCRIPT:

    #!/bin/bash
    # V-1.0 by Hanynowsky - April 2012. 
    # I am a very basic script that works around bug 874241 repprted in launchpad.

    XCOM0=`xrandr -q | grep 'HDMI1 connected'`
    XCOM1=`xrandr --output HDMI1 --primary --mode 1920x1080 --output LVDS1 --mode 1366x768 --below HDMI1`
    XCOM2=`xrandr --output LVDS1 --mode 1366x768`
    # if the external monitor is connected, then we tell XRANDR to set up an extended desktop
    if [ -n "$XCOM0" ] || [ ! "$XCOM0" = "" ]; then echo $XCOM1
    # if the external monitor is disconnected, then we tell XRANDR to output only to the laptop screen
    else echo $XCOM2
    fi
    exit 0;

Many thanks Hanynowsky! Finding your answer saved me a ton of work (recently upgraded 12.04). However in my case it didn't provide the complete solution so I would like to add what I learned. My setup was a Samsung S22A300B plugged into the VGA port of a Vaio VGN-CR120E with built-in 1280x800 display and a Mobile GM965/GL960 Integrated Graphics Controller.

Briefly what I found was:

  • The maximum resolution I could set on the external Samsung display using the Displays System Setting was 1024x768.
  • This was apparently caused because my VGA controller doesn't support EDID. For some reason both Windows Vista and Windows 7 (on a different laptop) can handle this situation and provide a full range of resolutions.

To workaround this limited maximum resolution I did the following:

  • Added lines to your script to invoke xrandr with --newmode and --addmode
  • Tried cvt to generate the --newmode modeline for 1920x1080, but unfortunately it didn't work for my setup.
  • Borrowed a laptop with a an HDMI port, booted it with the Samsung plugged in, and grabbed the modline for 1920x1080 56.2 kHz out of /var/log/Xorg.0.log
  • Plugged that modline along with modifying your script for my setup (e.g. HDMI1->VGA1, correct laptop resolution, etc.)

This ALMOST worked, but after logon the external monitor was reset from a nice 1920x1080 back to 1024x768. It turned out that this was a persistent user setting and was easily fixed by using the Displays... System Setting (from the gear menu) to the now available 1920x1080. Now when I boot with the external monitor connected everything works as expected.

One additional glitch: If this script gets run twice (for example from terminal) the xrandr --newmode line will get a "BadName (named color or font does not exist)" error, but https://stackoverflow.com/questions/851704/xrandr-errors-badname-named-color-or-font-does-not-exist explained this and it seems benign. Also shouldn't be a problem when the script is hooked up lightdm.conf per Hanynowsky's instructions vs. run manually.

I'm providing the changes adapted for the above (VGA with no EDID functionality) in the hopes it will help someone else. As mentioned in the preceding answers you will have to adapt this for your own setup. I don't have any good advice on obtaining the correct modline, but if someone else does please chip in.

#!/bin/bash
# Modified for Vaio with 1920x1080 external on VGA
XCOM0=`xrandr -q | grep 'VGA1 connected'`
XCOM1="xrandr --output VGA1 --primary --mode 1920x1080 --output LVDS1 --mode 1280x800 --left-of VGA1"
XCOM2="xrandr --output LVDS1 --mode 1280x800"
NEWMODE="xrandr --newmode "1920x1080" 148.50  1920 2448 2492 2640  1080 1084 1089 1125 +hsync +vsync"
ADDMODE="xrandr --addmode VGA1 1920x1080"

# Always add this mode in case we need it (better would be to test first)
eval $NEWMODE
eval $ADDMODE

if [ -n "$XCOM0" ] || [ ! "$XCOM0" = "" ];
then
        # if the external monitor is connected, then we tell XRANDR to set up an extended desktop
        eval $XCOM1
else
        # if the external monitor is disconnected, then we tell XRANDR to output only to the laptop screen
        eval $XCOM2
fi
exit 0;

NOTE: I'm not sure if the eval is necessary (vs. echo in the original). I put this in before I discovered that my Displays... settings were resetting the external display to a lower resolution.