How to create a callback for “monitor plugged” on an intel graphics?

后端 未结 5 698
猫巷女王i
猫巷女王i 2020-12-12 21:40

I\'ve got an eeepc with an intel graphics. I\'d like to hook a script to the event of a monitor plugged via VGA. How to do that?

5条回答
  •  独厮守ぢ
    2020-12-12 22:12

    Thanks sebastianwagner!

    With this information, I've been able to successfully boot my Kodi media center with the TV turned off. Indeed, when the TV is off, the Intel driver doesn't want to set up a mode and I got a blank screen when I later powered on the TV.

    The Kodi log showed the following line:

    WARNING: CXRandR::Query - output HDMI1 has no current mode, assuming disconnected
    

    So I created the following line in /etc/udev/rules.d/99-monitor-hotplug.rules :

    ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/usr/sbin/hotplugtv.sh"
    

    Content of /usr/sbin/hotplugtv.sh (my X server is running as root) :

    #!/bin/bash
    
    export DISPLAY=:0
    export XAUTHORITY=/root/.Xauthority
    
    /bin/date 2>&1 >> /var/log/hotplugtv.log;
    if [[ $(cat /sys/class/drm/card0-HDMI-A-1/status | grep -Ec "^connected") -eq 1 ]]; then
            echo "TV connected!" >> /var/log/hotplugtv.log;
            /bin/sleep 2s;
            /usr/bin/xrandr --verbose --output HDMI1 --auto 2>&1 >> /var/log/hotplugtv.log;
    else
            echo "TV disconnected!" >> /var/log/hotplugtv.log;
    fi
    

    Don't forget to reload udev rules when you make any change to your script (this was driving me crazy!):

    udevadm control --reload-rules
    

    Be careful to disable any screen saver in Kodi because they stay activated forever when you finally power up the TV. On the other hand energy saving / DPMS seems to work fine.

提交回复
热议问题