How to disable notebook's touchpad on USB mouse connect (and slower the last)? [duplicate]
Solution - automatic
Thanks to Esamo and his work.
To add AUTO triggers for connecting mouse on startup:
Create the file: /etc/udev/rules.d/10-local.rules
Fill up with this content: (replace $USER with your user name)
ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/$USER/scripts/touchpad_switcher.sh false"
ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/$USER/scripts/touchpad_switcher.sh true"
Example:
ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/dawid/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/dawid/scripts/touchpad_switcher.sh false"
ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/dawid/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/dawid/scripts/touchpad_switcher.sh true"
Next place your script wherever you want. I placed it in ~/scripts
touchpad_switcher.sh
#!/bin/sh
enabled=$1
touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);
if $enabled
then
xinput set-prop $touchpad_id "Device Enabled" 1 | notify-send "The touchpad is now enabled." ""
else
xinput set-prop $touchpad_id "Device Enabled" 0 | notify-send "Disabling the touchpad..." ""
fi
Remember to add execute permissions:
chmod +x touchpad_switcher.sh
Now simply reboot! ( merely restarting udev doesn't seem to work...)
Some other useful stuff:
Some info about udev rules
Example from ArchLinux
Simlar question
SOLUTION - not automatic
The script below, when executed, will disable the touchpad if any mouse is connected and show a notification.
touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);
if xinput | grep -i "mouse" | grep -i "pointer"
then xinput set-prop $touchpad_id "Device Enabled" 0 |
notify-send "Disabling the touchpad..." ""
else xinput set-prop $touchpad_id "Device Enabled" 1 |
notify-send "The touchpad is now enabled." ""
fi
Added there also a reverse situation, although in my case the touchpad gets enabled on mouse disconnection anyway.
I have saved the script in a file and am running it from Unity Launcher
Terminal
section after every mouse plug in.
ADVANCED
-
More mouses?
Clarify which
mouse
should deactivate the touchpad by expanding the value in"mouse"
fragment, name based onxinput
devices list. -
Scared mouse runs from edge to edge?
I had to run additional command for mouse - decreasing
cursor acceleration
since it is madly set to 10 on every connection. Actually after a while I made auto-detection script (it gets mouse id and its' prop for velocity; dunno about performance ofcut
)...touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2); mouse_id=$(xinput | grep -i "mouse" | grep -i 'pointer' | cut -f2 | cut -d '=' -f2); mouse_prop=$(xinput list-props $mouse_id | grep -i "velocity" | cut -f2 | cut -d '(' -f2 | cut -d ')' -f1 ); if xinput | grep -i "mouse" | grep -i "pointer" then xinput set-prop $touchpad_id "Device Enabled" 0 | xinput set-prop $mouse_id $mouse_prop 3 | notify-send "Disabling the touchpad..." "" else xinput set-prop $touchpad_id "Device Enabled" 1 | notify-send "The touchpad is now enabled." "" fi
Learned a lot today to make above :D .
SOMEONE PRO?
Would be useful to know how to make it automatic.
Also curious why mouse config is not saved (2.).
What @David Drozd posted didn't work for me on Ubuntu 16.04.
Seems like the trick with xinput
don't work in udev
.
Only synclient TouchpadOff=[0|1]
worked.
Also ACTION="remove"
didn't work solely.
I finally got it when added ENV{REMOVE_CMD}="/bin/sh -c '/usr/bin/synclient TouchpadOff=0'"
The full solution: create the file /etc/udev/rules.d/10-local.rules
with the following line (replace $USER with your user name)
ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{REMOVE_CMD}="/bin/sh -c '/usr/bin/synclient TouchpadOff=0'", RUN+="/bin/sh -c '/usr/bin/synclient TouchpadOff=1' "