Skip to content

Instantly share code, notes, and snippets.

@sujunmin
Created August 1, 2019 04:32
Show Gist options
  • Save sujunmin/728135d177f547926f49c877470ea8d9 to your computer and use it in GitHub Desktop.
Save sujunmin/728135d177f547926f49c877470ea8d9 to your computer and use it in GitHub Desktop.
Disable touchpad when the external mouse plugin

https://askubuntu.com/questions/824593/udev-rule-for-external-mouse-detection-to-turn-touchpad-on-and-off

  1. xinput list find the name of touchpad
  2. create the toggle script NAMEOFSCRIPT.SH
#!/bin/sh 
# 
# Enables the touchpad if and only if there aren't any external mice connected. 
# 
# Originally from: 
#     https://wiki.archlinux.org/index.php/Touchpad_Synaptics#System_with_multiple_X_sessions

# This supports also ALPS touchpads.

#Here puts how is named (Run 'xinput list' for the name to put below)
TOUCHPAD="HAILUCK CO.,LTD USB KEYBOARD Mouse" 
FOUND=0 

for MOUSE in `find /sys/class/input -name mouse\*` 
do 
    if [ "`cat $MOUSE/device/name`" != "$TOUCHPAD" ] 
    then 
        FOUND=1 
  #Find a Mouse device other than the TouchPad and record the variable.
        break 
    fi 
done 

DISPLAY=:0 
export DISPLAY 
for USER in `w -h | cut -d\  -f1 | sort | uniq` 
do 
    XAUTHORITY=`sudo -Hiu $USER env | grep ^HOME= | cut -d= -f2`/.Xauthority 
    export XAUTHORITY 
    TOUCHPADDEVICE=$(($(xinput list | grep -i "$TOUCHPAD" | cut -d= -f2 | cut -d[ -f1)+0)) 
#Find the Touchpad Id
    if [ $FOUND -eq 1 ]; then
#If another device is founded, disable touchpad
        xinput disable $TOUCHPADDEVICE
    else
#else enable touchpad
        xinput enable $TOUCHPADDEVICE
    fi
done
  1. create UDEV rule file /etc/udev/rules.d/01-touchpad_toggle.rules
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**" 
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**" 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment