udev - 무선 마우스 연결 시 트랙패드를 자동으로 비활성화합니다.

udev - 무선 마우스 연결 시 트랙패드를 자동으로 비활성화합니다.

저는 무선 마우스용 동글을 항상 노트북에 보관하고 있으며 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}"

mouseplug.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를 통해 동적으로 표시함으로써 개선될 수 있지만 단일 사용자 랩톱의 경우 이와 같이 잘 작동합니다.

관련 정보