udev - Desativando o trackpad automaticamente após a conexão do mouse sem fio

2

Eu mantenho o dongle no meu laptop o tempo todo para o mouse sem fio e quero usar o udev para executar um script que desativa meu trackpad quando o mouse está realmente ligado. Eu escrevi regras e um script, mas não consigo fazê-los funcionar.

A seguir, as ações UDEV para OFF / ON

OFF

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                                                                                                        

ON

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 

Minhas regras

ACTION=="change", ATTR{serial_number}=="4060-fb-d9-a0-50", RUN+="/home/sly/bin/mouse-plug.sh $attr{online}"

mouse-plug.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

Informações do dispositivo 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==""
O

mouse-plug.sh ativa e desativa o touchpad como pretendido, mas não é acionado no evento UDEV.

    
por Sly Cedix 26.09.2018 / 02:14

1 resposta

1

a tomada do mouse precisou ser modificada para

#!/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

Isso poderia ser melhorado passando o nome de usuário e exibindo dinamicamente pelo udev, mas para um único laptop de usuário, ele funciona bem assim.

    
por 26.09.2018 / 07:28

Tags