![当且仅当我插入外部显示器时 Udev 通知](https://linux22.com/image/114429/%E5%BD%93%E4%B8%94%E4%BB%85%E5%BD%93%E6%88%91%E6%8F%92%E5%85%A5%E5%A4%96%E9%83%A8%E6%98%BE%E7%A4%BA%E5%99%A8%E6%97%B6%20Udev%20%E9%80%9A%E7%9F%A5.png)
当且仅当用户插入外部显示器(即连接器已连接)时,我想向我的应用程序发送通知。
我的命令输出udevadm info -a -p /sys/class/drm/card1-VGA-2
:
looking at device '/devices/pci0000:00/0000:00:02.0/drm/card1/card1-VGA-2':
KERNEL=="card1-VGA-2"
SUBSYSTEM=="drm"
DRIVER==""
ATTR{edid}==""
ATTR{dpms}=="On"
ATTR{enabled}=="enabled"
ATTR{status}=="connected"
looking at parent device '/devices/pci0000:00/0000:00:02.0/drm/card1':
KERNELS=="card1"
SUBSYSTEMS=="drm"
DRIVERS==""
ATTRS{gt_RP1_freq_mhz}=="650"
ATTRS{gt_min_freq_mhz}=="650"
ATTRS{gt_RPn_freq_mhz}=="650"
ATTRS{gt_RP0_freq_mhz}=="1300"
ATTRS{gt_cur_freq_mhz}=="650"
ATTRS{gt_max_freq_mhz}=="1300"
looking at parent device '/devices/pci0000:00/0000:00:02.0':
KERNELS=="0000:00:02.0"
SUBSYSTEMS=="pci"
DRIVERS=="i915"
ATTRS{irq}=="48"
ATTRS{subsystem_vendor}=="0x17aa"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x030000"
ATTRS{driver_override}=="(null)"
ATTRS{consistent_dma_mask_bits}=="40"
ATTRS{dma_mask_bits}=="40"
ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000000f"
ATTRS{device}=="0x0126"
ATTRS{enable}=="1"
ATTRS{msi_bus}==""
ATTRS{local_cpulist}=="0-3"
ATTRS{vendor}=="0x8086"
ATTRS{subsystem_device}=="0x21d3"
ATTRS{boot_vga}=="1"
ATTRS{numa_node}=="-1"
ATTRS{d3cold_allowed}=="1"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
如果我的 udev 规则是下一个:
KERNEL=="card1", SUBSYSTEM=="drm", ATTR{status}=="connected", ACTION=="change", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/smidla/.Xauthority", RUN+="/home/smidla/test.sh"
什么也没有发生,但如果我删除该ATTR{status}=="connected"
部件,
test.sh
当我插入和拔出外部显示器时,我的执行。
但是,当且仅当我连接显示器时我才需要通知。我无法使用xrandr
或阅读/sys/class/drm/card1-VGA-2/status
,因为在我的硬件上这些操作会使系统速度减慢几秒钟。我怎么解决这个问题?