1

I've read the answers to this question but I don't have ACPI, the /sys/class/drm/card0-socket/status method does not work and the xrandr method chokes my CPU. udevadm monitor shows nothing when (un)plugging the monitor.

I've got a circa 2013 Lenovo ThinkPad w530 with nVidia quadro something. I'm running Lubuntu 18.04 with the nouveau driver. The monitor is a 27" Philips 271S. I'm using a VGA cable.

How do I do detect monitor (un)plugging?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 1
    Are you running `nvidia` or `nouveau`? Depending on that, you may also get "files" with EDID entries under `/sys` or `/proc`. Also, it's interesting that `xrandr` "chokes your CPU', while `read-edid`, which calls the BIOS and has to do some extremely complicated things to do that, does not. `xrandr` really should just call the X server, which should already have this information. Unless nvidia/nouveau decides that's a good time to test for connected monitors again, with all the time-outs that usually involves. – dirkt Nov 15 '18 at 08:06
  • I'm running `nouveau`. I have the EDID in `/sys/class/drm/card0-VGA-1/edid` but `cat /path/edid` gives the same result both with the monitor plugged and unplugged. Maybe the chocking could be avoided with some `nice` trick, I didn't try that route. About "just calling the X server", maybe that's what [srandr](https://github.com/jceb/srandrd) does, but I'm not at ease with compiling C. – White_Rabbit Nov 15 '18 at 08:49
  • Which call did you use? Just `xrandr -q`? If this results in monitor probing with long timeouts each time it's called (check `/var/log/Xorg.0.log` for hints if it really does that), I'd consider a bugreport with the nouveau developers. Possibly there's also a way to set shorter timeouts or to just probe card0-VGA-1, so I'd ask them. It seems to work via `get-edid`, after all. – dirkt Nov 15 '18 at 09:07
  • I use `xrandr --display :0 --query`. I can't interpret the log. #Last line before call [ 15674.053] (II) event7 - ThinkPad Extra Buttons: device is a keyboard # I call xrandr [ 17548.848] (II) NOUVEAU(0): EDID vendor "PHL", prod id 2314 # [ many lines ] # [ last line of `/var/log/Xorg.0.log`] [ 17548.849] (II) NOUVEAU(0): Modeline "1280x720"x60.0 74.48 1280 1336 1472 1664 720 721 724 746 -hsync +vsync (44.8 kHz e) – White_Rabbit Nov 15 '18 at 09:15

1 Answers1

2

I resorted to polling for the external screen EDID. I installed the read-edid package, added a line in visudo

%sudo  ALL=(ALL:ALL) NOPASSWD:/usr/bin/get-edid

to allow passwordless get-edid and used the following loop:

#!/bin/bash
# edid_based_automatic_display_loop.sh
export NEW_CONNECTION=1
export NEW_DISCONNECTION=1

while :
do
    sleep 1
    sudo get-edid 2>/dev/null|parse-edid 2>/dev/null|grep "PHL 271S7Q">/dev/null
    _DISCONNECTED=`echo $?`
    # echo "DISCONNECTED $_DISCONNECTED"
    if [ $_DISCONNECTED = "0" -a $NEW_CONNECTION = "1" ] ; then
        export NEW_DISCONNECTION=1;
        export NEW_CONNECTION=0;
        bash /home/bruno/.screenlayout/only_external.sh
    elif [ $_DISCONNECTED = "1" -a $NEW_DISCONNECTION = "1" ] ; then
        export NEW_DISCONNECTION=0;
        export NEW_CONNECTION=1;
        bash /home/bruno/.screenlayout/only_laptop.sh
    fi
done