-   Linux - Mobile (
-   -   How to detect external monitor connection on laptop (

xflow7 08-03-2009 07:31 PM

How to detect external monitor connection on laptop
Hi all,

I have a Lenovo T61p w/ NVIDIA FX570M GPU running Slack 12.2.

I sometimes have an external monitor connected, and like having it set up as a separate Screen in X (i.e. laptop DFP as :0.0 and external as :0.1).

I can do this no problem when the monitor is connected. Only trouble is that if the external monitor is not connected, X won't start unless I either change the default ServerLayout or pass a command-line option.

I'd like to have it automagically figure out whether or not to try and use the second screen.

As far as I can tell, X will not sequentially try ServerLayouts in the xorg.conf file until one works (which would be a really nice feature, IMHO).

So, is there a command that I can have startx (or similar) run to determine if anything is connected and then call X with the appropriate ServerLayout?

I've waded through the /sys and /proc directories, checked every logfile I can think of, and can't find anything that reports the connection status.

Thanks for any help!


michaelk 08-03-2009 07:59 PM

My first idea would be to parse the output of the xrandr command to see if the monitor is connected.

xflow7 08-03-2009 08:08 PM

Thanks for the reply.

I don't think that's going to work as I need a way to detect the monitor connection *before* X is started. If X isn't running xrandr returns "Can't open display"

michaelk 08-03-2009 08:18 PM

Your are correct. Will have to work on a second idea.

xflow7 08-04-2009 09:46 PM

Well, through mostly dumb luck and trial and error I've found *a* way to check I think, although it is not remotely intuitive.

Monitor connected:

$ cat /sys/devices/virtual/video_output/acpi_video1/state

Monitor disconnected:

$ cat /sys/devices/virtual/video_output/acpi_video1/state

Surely there must be a less arcane check, though!

xflow7 08-04-2009 09:50 PM

Aha! That last result got me thinking and it turns out similar info can be obtained by examining:


which is at least *somewhat* more intuitive.

Molly83 08-12-2009 04:06 AM

Connect the monitor, flat panel, or projector to the laptop's 15-pin video connection on the back of the computer as shown to the right. Once connected, your laptop may automatically switch to the new external display or you may be required to press a sequence of keys in order to switch from the laptop to the external display.i hope this helps

All times are GMT -5. The time now is 02:56 AM.