8

I have had difficulties trying to get the touchpad to automatically turn off when a USB mouse is connected and enable when it is disconnected.

I haven't had success with touchpad-indicator.

I have found a method that seems to work so far. I am posting it here as an answer in case anyone else finds it useful. I would also appreciate suggestions for alternatives or corrections.

Jay

1 Answer 1

5

Edit - This works in Freya NOT Loki

Here is my solution for disabling the touchpad in elementary OS when attaching a USB mouse.

I created these instructions based on the following websites: https://bbs.archlinux.org/viewtopic.php?id=188918

https://bbs.archlinux.org/viewtopic.php?id=170396

As well as the arch wiki on Synaptics touchpad, but I'm only allowed to paste 2 links.

Open a terminal by pressing the key combination: Super + T or by opening it from the Applications menu

Enter the following at the prompt to open Scratch as root:

sudo scratch-text-editor

Enter your password when asked.

Create a new file.

Paste the following into the new file:

SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/$USERNAME$/.Xauthority", RUN+="/bin/sh -c '/usr/bin/synclient TouchpadOff=1; sleep 5; /usr/bin/killall -q syndaemon'"
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/$USERNAME$/.Xauthority", RUN+="/bin/sh -c '/usr/bin/synclient TouchpadOff=0'"

* Replace $USERNAME$ in these 2 lines with your actual username. *

Click the save button Click “Computer” in the left hand column of the dialogue box. Navigate to the /etc/udev/rules.d folder Type the name “01-touchpad.rules” as the name of the file and click Save Close the file

This alone should enable and disable the touchpad when attaching or detaching a USB mouse. This will not disable the touchpad at system startup if a USB mouse is attached. To do this you can do the following:

Open a terminal Enter the following at the prompt to open Scratch as root:

sudo scratch-text-editor

Enter your password when asked.

Create a new file and paste the following into it:

#!/bin/bash
lista=`xinput list | grep -i 'mouse'`
listb=`xinput list | grep -i 'transceiver' | grep -i 'pointer'`
listc=`xinput list | grep -i 'receiver' | grep -i 'pointer'`

if [ ${#lista} -eq 0 ] && [ ${#listb} -eq 0 ] && [ ${#listc} -eq 0 ]; then
    exec `synclient TouchpadOff=0`
    notify-send "No USB Mouse Detected" "Your Touchpad is Active"
else
    exec  `synclient TouchpadOff=1`
    notify-send "USB Mouse Detected" "Your Touchpad is Disabled"
    sleep 5
    killall -q syndaemon
fi

Click the Save button Click "Computer" in the left column then navigate to /usr/local/bin Type the name "mouse_detect.sh" for the filename and click Save

Open the "Files" application as an Administrator If it is on your Plank, right click to find this option. If it is not, then open "Files" from the application menu and right-click the icon on Plank when it opens to find the option. Enter your password when asked.

Click "File System" in the left column and navigate to /usr/local/bin. Your file "mouse_detect.sh" should be present. Right click on this file and select "Properties" Click on the "More" button and then click on each of the "Execute" buttons to ensure they are all highlighted. Close Files

Now we need to create an autostart entry Open "System Settings" and click "Applications" Click "Startup" and click the "+" button in the lower left hand corner. When the box opens up type "/usr/local/bin/mouse_detect.sh" in the lower box where it asks you to type a custom command.

Open "Files" and press CTRL-H to display hidden files and press Home in the left hand column Navigate to the ~/.config/autostart

You should see a file like "custom-command0.desktop", open this in "Scratch" by right clicking and selecting Open With. (select Other Application if necessary) You should see a line that says Exec=/usr/local/bin/mouse_detect.sh if you are in the right file Add the following line line to the file:

X-GNOME-Autostart-Delay=8

You can also enter a custom name for the desktop file in the "Name" field and a custom comment in the "Comment" field.
Note: I had to remove the [en_CA] from my Name[en_CA] field for the name change to be visible in "Files". You might have to do the same if you live outside the US.

If you go back to your startup applications, your custom Name and Comment should be visible and you can enable or disable the autorun of this script on startup by clicking on the toggle to the right of it.

That should do it. If the startup script detects other wireless devices as a mouse and disables your touchpad when it shouldn't you can try changing the contents of the mouse_detect.sh file to:

#!/bin/bash
lista=`xinput list | grep -i 'mouse'`

if [ ${#lista} -eq 0 ]; then
    exec `synclient TouchpadOff=0`
    notify-send "No USB Mouse Detected" "Your Touchpad is Active"
else
    exec  `synclient TouchpadOff=1`
    notify-send "USB Mouse Detected" "Your Touchpad is Disabled"
    sleep 5
    killall -q syndaemon
fi

This has less chance of detecting wireless mice though, so only use it if the first one does not work for you.

Jay

4
  • This is really useful!
    – elmato
    Commented Sep 30, 2015 at 23:45
  • Thanks. I'm glad someone is finding it useful. I just edited my post to add full paths to killall and synclient in the udev rules in "01-touchpad.rules". This is the way they appeared in the reference links I posted. Also my machine started hanging on suspend when I installed kernel 3.19. Changing this seemed to help. Can't explain why. It's probably better to be explicit with the paths anyway. Feel free to update your udev rules in "01-touchpad.rules" to the updated ones. Commented Oct 2, 2015 at 1:27
  • @JasonGambrel, Nice post, Would you accept you own question. see elementaryos.stackexchange.com/help/self-answer
    – user.dz
    Commented Dec 5, 2015 at 21:14
  • Thanks Sneetsher. I didn't know I could accept my own answer or post an answer right with the question. That is helpful to know! Commented Jan 10, 2016 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.