LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Mobile (http://www.linuxquestions.org/questions/linux-mobile-81/)
-   -   How to detect external monitor connection on laptop (http://www.linuxquestions.org/questions/linux-mobile-81/how-to-detect-external-monitor-connection-on-laptop-744888/)

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!

Dave

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:
Code:

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

Monitor disconnected:
Code:

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

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:

/proc/acpi/video/VID/CRT0

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:47 AM.