2

I keep the dongle in my laptop at all times for my wireless mouse, and want to use udev to run a script that disables my trackpad when the mouse is actually turned on. I've written rules and a script, but cannot seem to get them to work.

The following are the UDEV actions for 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 

My rules

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

Udev info of device

$ 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 does enable and disable the touchpad as intended, but it is not triggered upon the UDEV event.

5
  • I would check the following: First, see if the file /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:4060.0004/power_supply/serial_number exists (and matches the content 4060-fb-d9-a0-50). I'm sure it does, that is what you are attempting to reference via ATTRS{4060-fb-d9-a0-50}. Next up, check for errors in udevadm test -a 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. It should specify the list of rules (and the order they were processed in). This is generally useful for debugging. Sep 26, 2018 at 2:29
  • @BrianRedbeard I'm not getting any errors if I run udevadm test -a 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/hidpp_battery_0 in fact, it even says run: /home/sly/bin/mouse-plug.sh 1 when the mouse is on and run: /home/sly/bin/mouse-plug.sh 0 when the mouse is off. The serial number is consistent with what I have in the file. It just doesn't ever run when the real event happens.
    – Cyn
    Sep 26, 2018 at 4:32
  • I've added ENV variables for XAUTHORITY and DISPLAY, but it still never runs
    – Cyn
    Sep 26, 2018 at 5:02
  • Here's a working example of a similar mechanism I use: ACTION=="add", SUBSYSTEM=="usb", ATTRS{bcdDevice}=="0bb3", ATTRS{idProduct}=="2514", ATTRS{idVendor}=="0424", ATTRS{bDeviceClass}=="09", ATTRS{bmAttributes}=="e0", RUN+="/home/bharrington/.local/bin/ext_mirror.sh". This is the script itself: gist.github.com/brianredbeard/426b9f24e67af37838ccbdcfdc736e22 Sep 26, 2018 at 5:19
  • Wouldn't work with the udev passed environment variables for some reason, ended up manually exporting DISPLAY and XAUTHORITY inside the script.. It now works like I planned.
    – Cyn
    Sep 26, 2018 at 5:30

1 Answer 1

1

mouse-plug needed to be modified to

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

This could be bettered by passing the username and display dynamically through udev, but for a single user laptop, it works fine like this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .