如何为“监控器插入"创建回调.在英特尔图形上? [英] How to create a callback for "monitor plugged" on an intel graphics?

查看:144
本文介绍了如何为“监控器插入"创建回调.在英特尔图形上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有英特尔图形处理器的eeepc.我想将脚本连接到通过VGA插入显示器的事件.该怎么做?

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?

推荐答案

作为粗略的解决方案,您可以对sysfs进行轮询.在我的笔记本电脑上,我有:

As a crude solution, you may be able to poll on sysfs. On my laptop I have:

$ cat /sys/class/drm/card0-LVDS-1/status
connected

$ cat /sys/class/drm/card0-VGA-1/status
disconnected

我猜想这需要内核DRM以及可能的KMS.

I'm guessing this requires kernel DRM and possibly KMS.

要查看是否可以自动触发某些内容,可以运行udevadm monitor --property,然后观察(断开)连接显示器以查看是否报告了事件.

To see if you can trigger something automatically, you could run udevadm monitor --property, and watch while you are (dis-)connecting the monitor to see if events are reported.

使用radeon时,我第一次连接VGA显示器时会收到一个事件,但随后的断开连接和重新连接都没有事件.该事件应类似于(以您的为例):

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

KERNEL[1303765357.560848] change /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV_LOG=0
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
SUBSYSTEM=drm
HOTPLUG=1
DEVNAME=dri/card0
DEVTYPE=drm_minor
SEQNUM=2943
MAJOR=226
MINOR=0

不幸的是,没有太多可与之匹敌的东西,但是只要图片中只有一张视频卡不太重要即可.查找udev从何处(可能是/etc/udev/rules.d/)从系统上获取规则,并使用以下命令创建99-monitor-hotplug.rules文件:

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 /etc/udev/rules.d/), and create a 99-monitor-hotplug.rules file with:

ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/root/hotplug.sh"

连接显示器后,

udev将运行hotplug.sh.作为测试,我在/root/hotplug.sh中放置了以下内容(不要忘记使此脚本可执行):

udev will then run hotplug.sh when a display is connected. As a test, I put the following in /root/hotplug.sh (don't forget to make this script executable):

#!/bin/sh

for output in DVI-I-1 LVDS-1 VGA-1; do
        echo $output >> /root/hotplug.log
        cat /sys/class/drm/card0-$output/status >> /root/hotplug.log
done

因此,连接外接显示器后,在hotplug.log中有了一个条目.即使对ACTION=="change"进行过滤,引导时仍然会遇到一些事件,因此您可能希望在脚本中以某种方式考虑到这一点.

With that, I got an entry in hotplug.log after I connected an external display. Even filtering for ACTION=="change", I still got some events on boot, so you may want to take that into account somehow in your script.

这篇关于如何为“监控器插入"创建回调.在英特尔图形上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆