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?
Join Stack Overflow to learn, share knowledge, and build your career.
|
|
As a crude solution, you may be able to poll on sysfs. On my laptop I have:
I'm guessing this requires kernel DRM and possibly KMS. To see if you can trigger something automatically, you could run With my radeon, I get an event the first time I connect a VGA monitor, but no events on subsequent disconnects and reconnects. The event should look something like (using yours as an example):
Unfortunately there's not a lot to match against, but as long as there's only one video card in the picture that's not too important. Find where udev gets rules from on your system (probably
With that, I got an entry in |
|||||||||||||||||||||
|
|
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.
So I created the following line in /etc/udev/rules.d/99-monitor-hotplug.rules :
Content of /usr/sbin/hotplugtv.sh (my X server is running as root) :
Don't forget to reload udev rules when you make any change to your script (this was driving me crazy!):
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. |
|||
|
|
|
Assuming you're running X, a script can parse the output of xrandr to see what monitors are connected. This should work with any graphics card. This is the same tool you'll probably use to make use of the change in your script. It doesn't solve the issue with notifications to automatically run a script. While I don't have a great generic solution, a common case is detecting when an external monitor is present because a laptop is connected to a docking station. In this case, you can have your script trigger off of something else that triggers when connecting to the docking station such as the addition or removal of a USB keyboard or ethernet. |
|||
|
|
|
You have three options:
In any of the ways mentioned, you're still going to have to poll in one way or another, so I'd just go with the first option. |
|||||||||||||||||||||
|