我始终将无线鼠标的加密狗放在笔记本电脑中,并希望使用 udev 运行一个脚本,在鼠标实际打开时禁用我的触控板。我已经编写了规则和脚本,但似乎无法让它们发挥作用。
以下是 UDEV 的 OFF/ON 动作
离开
UDEV [404.700104] change /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004/power_supply
ACTION=change DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004/power_supply/hidpp_battery_0
POWER_SUPPLY_CAPACITY_LEVEL=Unknown
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_MODEL_NAME=Wireless Mouse MX Master
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_ONLINE=0
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_SERIAL_NUMBER=4060-fb-d9-a0-50
POWER_SUPPLY_STATUS=Unknown
SEQNUM=3540
SUBSYSTEM=power_supply
USEC_INITIALIZED=404691556
在
UDEV [406.390053] change /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004/power_supply
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004/power_supply/hidpp_battery_0 POWER_SUPPLY_CAPACITY_LEVEL=Normal
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_MODEL_NAME=Wireless Mouse MX Master
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_SERIAL_NUMBER=4060-fb-d9-a0-50
POWER_SUPPLY_STATUS=Discharging
SEQNUM=3541
SUBSYSTEM=power_supply
USEC_INITIALIZED=406373747
我的规则
ACTION=="change", ATTR{serial_number}=="4060-fb-d9-a0-50", RUN+="/home/sly/bin/mouse-plug.sh $attr{online}"
鼠标插头.sh
#!/bin/sh
TOUCHPADDEVICE=$(($(xinput list | grep -i touchpad | cut -d= -f2 | cut -d[ -f1)+0))
if [ $1 -eq 1 ]; then
xinput disable $TOUCHPADDEVICE
else
xinput enable $TOUCHPADDEVICE
fi
设备的udev信息
$ udevadm info -a -p /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004/power_supply/hidpp_battery_0
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004/power_supply/hidpp_battery_0':
KERNEL=="hidpp_battery_0"
SUBSYSTEM=="power_supply"
DRIVER==""
ATTR{capacity_level}=="Normal"
ATTR{manufacturer}=="Logitech"
ATTR{model_name}=="Wireless Mouse MX Master"
ATTR{online}=="1"
ATTR{scope}=="Device"
ATTR{serial_number}=="4060-fb-d9-a0-50"
ATTR{status}=="Discharging"
ATTR{type}=="Battery"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004':
KERNELS=="0003:046D:4060.0004"
SUBSYSTEMS=="hid"
DRIVERS=="logitech-hidpp-device"
ATTRS{country}=="00"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003':
KERNELS=="0003:046D:C52B.0003"
SUBSYSTEMS=="hid"
DRIVERS=="logitech-djreceiver"
ATTRS{country}=="00"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2':
KERNELS=="1-2:1.2"
SUBSYSTEMS=="usb"
DRIVERS=="usbhid"
ATTRS{authorized}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceClass}=="03"
ATTRS{bInterfaceNumber}=="02"
ATTRS{bInterfaceProtocol}=="00"
ATTRS{bInterfaceSubClass}=="00"
ATTRS{bNumEndpoints}=="01"
ATTRS{supports_autosuspend}=="1"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2':
KERNELS=="1-2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="8"
ATTRS{bMaxPower}=="98mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 3"
ATTRS{bcdDevice}=="1207"
ATTRS{bmAttributes}=="a0"
ATTRS{busnum}=="1"
ATTRS{configuration}=="RQR12.07_B0029"
ATTRS{devnum}=="2"
ATTRS{devpath}=="2"
ATTRS{devspec}==" (null)"
ATTRS{idProduct}=="c52b"
ATTRS{idVendor}=="046d"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Logitech"
ATTRS{maxchild}=="0"
ATTRS{product}=="USB Receiver"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="removable"
ATTRS{rx_lanes}=="1"
ATTRS{speed}=="12"
ATTRS{tx_lanes}=="1"
ATTRS{urbnum}=="69831"
ATTRS{version}==" 2.00"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{authorized_default}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bMaxPower}=="0mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0418"
ATTRS{bmAttributes}=="e0"
ATTRS{busnum}=="1"
ATTRS{configuration}==""
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{devspec}==" (null)"
ATTRS{idProduct}=="0002"
ATTRS{idVendor}=="1d6b"
ATTRS{interface_authorized_default}=="1"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Linux 4.18.5-arch1-1-ARCH xhci-hcd"
ATTRS{maxchild}=="16"
ATTRS{product}=="xHCI Host Controller"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{rx_lanes}=="1"
ATTRS{serial}=="0000:00:14.0"
ATTRS{speed}=="480"
ATTRS{tx_lanes}=="1"
ATTRS{urbnum}=="279"
ATTRS{version}==" 2.00"
looking at parent device '/devices/pci0000:00/0000:00:14.0':
KERNELS=="0000:00:14.0"
SUBSYSTEMS=="pci"
DRIVERS=="xhci_hcd"
ATTRS{ari_enabled}=="0"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x0c0330"
ATTRS{consistent_dma_mask_bits}=="64"
ATTRS{d3cold_allowed}=="1"
ATTRS{device}=="0xa12f"
ATTRS{devspec}==""
ATTRS{dma_mask_bits}=="64"
ATTRS{driver_override}=="(null)"
ATTRS{enable}=="1"
ATTRS{irq}=="128"
ATTRS{local_cpulist}=="0-7"
ATTRS{local_cpus}=="ff"
ATTRS{msi_bus}=="1"
ATTRS{numa_node}=="-1"
ATTRS{revision}=="0x31"
ATTRS{subsystem_device}=="0x07be"
ATTRS{subsystem_vendor}=="0x1028"
ATTRS{vendor}=="0x8086"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
mouse-plug.sh 确实按预期启用和禁用触摸板,但它不会在 UDEV 事件时触发。
答案1
鼠标插头需要修改为
#!/bin/sh
export DISPLAY=:0
export XAUTHORITY="/home/sly/.Xauthority"
TOUCHPADDEVICE=$(($(xinput list | grep -i touchpad | cut -d= -f2 | cut -d[ -f1)+0))
if [ $1 -eq 1 ]; then
xinput disable $TOUCHPADDEVICE
else
xinput enable $TOUCHPADDEVICE
fi
这可以通过传递用户名并通过 udev 动态显示来改善,但对于单用户笔记本电脑,它可以像这样工作得很好。