Well, I've written a one-liner that fixes that problem. If the external display is attached, it will automatically switch over to it and display the internal display. Otherwise it boots normally (leaving the internal display enabled).
I put the script into the Xsession.d directory so it gets started for every user on boot: /etc/X11/Xsession.d/98vgaonly and made it executable.
The actual script line is this:
xrandr -q | grep 'VGA connected' && xrandr --output LVDS --off --output VGA --auto
It checks if the line 'VGA connected' was found in xrandr's query and then asks your X server to turn off the internal output and use the external one with automatic resolution detection.
So to automatically switch to a connected VGA during boot just execute:
echo 'xrandr -q | grep \'VGA connected\' && xrandr --output LVDS --off --output VGA --auto' | sudo tee /etc/X11/Xsession.d/98vgaonly && sudo chmod a+x /etc/X11/Xsession.d/98vgaonly
You may have to change the name of the outputs for your setup. xrandr -q will let you know what's available. It would probably be possible to somehow call this script automatically when plugging in a monitor, but I've not figured out how. xrandr only works when called from inside the running X session in my experience.
If you want to know more about XRandR, check this recent article.
Any comments are welcome!
Thanks! You just saved me a few grey hairs! I've been trying to tinker around with a netbook, and this script is perfect for what I'm doing. Many thanks to you!
ReplyDelete-- JLangbridge
You're quite welcome! That's exactly what I had written this for.
ReplyDeleteit is good that it is possible. but how about on hdmi output? I have a g60-120us. i hope you coould post a script for it. i am a noob.
ReplyDeleteJust replace "VGA" above in the script with what it says in the output of 'xrandr -q' e.g. "HDMI".
ReplyDeleteNice! I just installed a 1920x1080 external VGA to use with my little 13" and this really helps sort out some issues.
ReplyDeleteIs there another place to save this script in order to run it before the GUI login system appears? It would be nice if the login screen ran at normal, non-weirdly-stretched resolution.
@Hunter:
ReplyDeleteTry to call the script from /etc/X11/xinit/xserverrc
That should do the trick. But no warraty! ;)
Hmm.. I think that might not work. Try putting it into your display managers init files, e.g.
ReplyDelete/etc/kde4/kdm/Xsetup
Thank you, I added this script to my startup and now I don't have to do anything to fix my monitors.
ReplyDeleteYou're welcome. Always great to hear I could help. ;)
ReplyDeleteI don't need to detect the external monitor at boot. Instead in my work I have to move around a lot and my laptop has a small 12.1" monitor. So I modified a little the script and added a custom keyboard shortcut in GNOME to change monitors with a single key (F12 in my case).
ReplyDeleteThis is the script code:
xrandr -q | grep 'VGA1 connected' && xrandr --output LVDS1 --off --output VGA1 --auto
xrandr -q | grep 'VGA1 disconnected' && xrandr --output VGA1 --off --output LVDS1 --auto
(note: my laptop detected the laptop display as LVSD1 and the external monitor as VGA1)
It detects if the external monitor is connected, if so it turns off the laptop screen.
The problem was that is I disconnected the external monitor, the laptop monitor stayed off and I couldn't see a thing. For that reason the second command detects if the external monitor is disconnected and turns on the laptop display.
I'm using Ubuntu 10.04 and it works great.
Mau, this works like a charm. I am using a Samsung Syncmaster 2443W and a rather old Samsung X20 laptop, running Ubuntu 10.04. Thanks a lot. Cheers, Martin
ReplyDeleteDoes this work for s-video ports? I have one of those as well that I use on tv's that don't have a VGA port.
ReplyDeleteIt works with any output supported by xrandr.
ReplyDelete