7

I am trying to tweak the touchpad on Ubuntu 16.04 but none of the usual methods seem to work. e.g.

synclient touchpadOff=1

It still works!

$ xinput set-prop $DEVICE_ID "Device Enabled" 0
$ xinput list-props 15 |head -n2
  Device 'SynPS/2 Synaptics TouchPad':
    Device Enabled (168):   0

...it still works!

I can disable it from the Settings app. but I want to be able to map this to a keyboard shortcut, so I'm looking for a command line solution.

Bonus points if you answer works in Gnome-Shell as well as Unity :-)

EDIT: output of xinput as requested in comment.

$ xinput
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ELAN Touchscreen                          id=12   [slave  pointer  (2)]
⎜   ↳ DLL06E4:01 06CB:7A13 Touchpad             id=13   [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=15   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Video Bus                                 id=8    [slave  keyboard (3)]
    ↳ Power Button                              id=9    [slave  keyboard (3)]
    ↳ Sleep Button                              id=10   [slave  keyboard (3)]
    ↳ Integrated_Webcam_HD                      id=11   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=14   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                          id=16   [slave  keyboard (3)]

Nb. I have used 15 for $DEVICE_ID

EDIT - thanks to the answer below here's my toggle script

You can do it in a one liner, but this way you get a nice notification, too. I've attached this to a shortcut key and it works a charm. Thanks all.

#!/bin/bash
if xinput list-props 13 | grep "Device Enabled (168):.*1" >/dev/null
then
  xinput disable 13
  notify-send -u low -i mouse "Trackpad disabled"
else
  xinput enable 13
  notify-send -u low -i mouse "Trackpad enabled"
fi
  • Please edit your question and add output of xinput terminal command. – Pilot6 Mar 29 '16 at 9:54
  • @Pilot6 Have done that. Thanks for your time :-) – artfulrobot Mar 29 '16 at 10:08
  • Hi artful, could you, for clarity reasons, mention if the toggle script works? It uses gsettings, and there is a little discussion :) – Jacob Vlijm Mar 29 '16 at 12:18
  • For me both, the device ID and the number inside the parenthesis were different. – lpanebr Nov 10 '17 at 18:26
9

You can switch the touchpad off with this command:

xinput disable 13

Enable it back by

xinput enable 13

The device is not controlled by psmouse. It is controlled by synaptics_i2c. And it is device 13.

You can also toggle it by name as you tried before, not to depend on the ID. But if you do not connect new input devices, the ID should stay.

See this answer for some details.

To remove a wrongly detected device you need to add i8042.nopnp kernel boot parameter.

  • Ah, so just got the wrong device. Wonder what the synaptics one does, then?! Thanks. – artfulrobot Mar 29 '16 at 10:12
  • It does nothing. It is wrongly detected by the kernel. You can fix it. – Pilot6 Mar 29 '16 at 10:13
3

Using gsettings

If you can change settings by gsettings, generally it is the preferred option. Since you can enable/disable touchpad from System Settings, and I am pretty sure System Settings does use gsettings, it looks like the method below should do the job, on your Dell as well.

Script to toggle the touchpad

14.04

#!/usr/bin/env python3
import subprocess

key = "org.gnome.settings-daemon.peripherals.touchpad" ;val = "touchpad-enabled"
curr = subprocess.check_output(["gsettings", "get", key, val]).decode("utf-8").strip()
newval = "false" if curr == "true" else "true"
subprocess.Popen(["gsettings", "set", key, val, newval])

15.04+

#!/usr/bin/env python3
import subprocess

key = "org.gnome.desktop.peripherals.touchpad" ;val = "send-events"
curr = subprocess.check_output(["gsettings", "get", key, val]).decode("utf-8").strip()
newval = "disabled" if curr == "'enabled'" else "enabled"
subprocess.Popen(["gsettings", "set", key, val, newval])

To use it

  1. Copy the script above, for your correct Ubuntu version, into an empty file, save it as toggle_touchpad.py
  2. Add the following command to a shortcut:

    python3 /path/to/toggle_touchpad.py
    

    Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/toggle_touchpad.py
    

Explanation

The command to disable touchpad:

for 14.04:

gsettings set org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled false

for 15.04 +:

gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled

Read the current state

If we use a script to read the current settings by the command:

gsettings get org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled

(14.04), or

gsettings get org.gnome.desktop.peripherals.touchpad send-events

(15.04+)

We can make the script set the opposite value, and thus toggle the touchpad.



EDIT; bash version of the toggle script

Just to be complete, and because OP indicated the python script(s) worked, but not wanted to use python, the bash version(s) of the two toggle scripts:

14.04

#!/bin/bash

key="org.gnome.settings-daemon.peripherals.touchpad"
val="touchpad-enabled" ;curr="$key $val"

if [ "$(gsettings get $curr)" == "false" ]
then
 gsettings set $key $val true
else
 gsettings set $key $val false
fi

15.04+

#!/bin/bash

key="org.gnome.desktop.peripherals.touchpad"
val="send-events" ;curr="$key $val"

if [ "$(gsettings get $curr)" == "'enabled'" ]
then
 gsettings set $key $val disabled
else
 gsettings set $key $val enabled
fi

To put under a shortcut key

  • Save the script as toggle_touchpad.sh
  • put the following command under a custom shortcut:

    /bin/bash /path/to/toggle_touchpad.sh
    
  • All this won't work for OP, because the touchpad is wrongly detected. – Pilot6 Mar 29 '16 at 12:07
  • Thanks @Pilot, I am in a doubt: he can set it from System settings : I can disable it from the Settings app which, I am pretty sure, uses gsettings. If OP mentions it doesn't work, I'll remove the answer though. – Jacob Vlijm Mar 29 '16 at 12:10
  • The problem is that the user space and gsettings will address SynPS/2 Synaptics TouchPad. But that is wrong. If OP boots with i8042.nopnp, this probably will work. But there is no reason to do it in such a complicated way. – Pilot6 Mar 29 '16 at 12:13
  • @Pilot I don't think this is complicated, and it gives OP an option to use only 1 shortcut to toggle. Let's see what he responds (if any). – Jacob Vlijm Mar 29 '16 at 12:16
  • Hello, OP here. Pilot6 was right in pointing out why my efforts - at least the 2nd one - wasn't working - I had the wrong ID (doh!). Jacob - not sure I'd jump to Python for executing a shell command, but critically yes, the gsettings method 15.10+ worked. – artfulrobot Mar 29 '16 at 15:12
1

I'm on 16.04 too. I usually using a little script that I put on a keyboard shortcut. When I execute it turns my touchpad off... But few seconds after it turns on ...

The script:

    #!/bin/sh

STATUS=`synclient | grep TouchpadOff | awk '{ print $3}'`

        if [ $STATUS != 1 ];
        then
                synclient touchpadOff=1;
        else
                synclient touchpadOff=2;
        fi
exit 0

I don't try to use it before I see your question ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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