Wednesday, March 26, 2008

Laptop, External Monitor, and xrandr to the Rescue

I have just upgraded to Ubuntu Gutsy (I know I'm very very late) on my laptop. The installation went fine but when I connected an external monitor with a higher resolution than my laptop has, gdm and GNOME were not able to detect this, and instead displayed the picture in the upper left corner of the screen.

This was especially funny with GNOME, because the desktop actually used the full resolution, and I could move windows over the whole screen. Only the panels were stuck in the middle of the screen.

Apparently I'm not the only one with this problem, so let me tell you what I found out and how to fix this.

Everything was fine with Ubuntu Feisty. When I connected an external monitor, the laptop screen switched off and the higher resolution was used. But now when I connect an external monitor, the laptop screen doesn't switch off automatically.

Because the laptop screen is still on, the system now has two screens and GNOME will automatically adapt to the screen with the lower resolution.

The moment I manually switched off the laptop screen with the tool xrandr

$ xrandr --output LVDS --off

the GNOME panels jumped to their correct position. So let's investigate this xrandr a bit more.

xrandr is a powerful tool for managing multiple video outputs, rotating the screen, and setting up multihead displays.

You can get a list of what the graphics driver thinks it has connected by invoking

$ xrandr -q

This will give you something like this:

Screen 0: minimum 320 x 200, current 1680 x 1050, maximum 1680 x 1200
VGA-0 connected 1680x1050+0+0 (normal left inverted right) 433mm x 271mm
1680x1050 60.0*+ 60.0
1280x1024 75.0 59.9
1440x900 75.0 59.9
1280x960 59.9
1152x864 74.8
1280x720 59.9
1024x768 75.1 60.0
800x600 75.0 60.3
640x480 75.0 60.0
720x400 70.1
LVDS connected (normal left inverted right)
1024x768 60.0 + 60.0
800x600 60.3
640x480 59.9
S-video disconnected (normal left inverted right)

The interesting entries are LVDS (the laptop screen) and VGA-0 (the external monitor). Both are connected. VGA-0 might be called VGA or similar on your system, as this name is driver-dependent.

If I wanted to check if an external monitor was connected, I'd just run

$ xrandr -q | grep "^VGA.* connected"

VGA-0 connected 1280x1024+0+0 (normal left inverted right) 338mm x 270mm

I want the system to switch off the laptop screen whenever an external monitor is connected, so that GNOME will use the higher resolution. This easily can be done by adding the following lines to /etc/gdm/Init/Default just before the

exit 0

line:

xrandr -q | grep "^VGA.* connected" >/dev/null
RC=$?
if [ $RC = 0 ]; then
xrandr --output LVDS --off
fi

It will also make gdm use the full resolution.

3 comments:

Unknown said...

This entry really helped me out! Thank you!

Unknown said...

Actually I commented too quick. :-) I had to add:
xrandr --output VGA --preferred

After the first xrandr command to get it working. It was still a great help, but I wonder why it didn't work to begin with for me. Any ideas? I'm using Xubuntu 9.04 (which uses Gdm).

gmmmocom said...

https://www.blogger.com/comment.g?blogID=8649245443206318981&postID=2813209403682330647