10

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
artfulrobot
  • 8,543

4 Answers4

10

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.

Pilot6
  • 90,100
  • 91
  • 213
  • 324
5

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
    
Jacob Vlijm
  • 83,767
  • 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
  • Hi @artfulrobot added bash version. – Jacob Vlijm Mar 29 '16 at 18:16
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 ...

monitor35
  • 537
  • 1
  • 4
  • 8
0

I used the OP's script, but in my notebook the device id changes at every boot, so I did a little modification.

It works like a charm now.

# Find device id and store it in a variable

LINE=$(xinput | grep -o "Touchpad.*id=[0-9][0-9]") TOUCH=$(echo $LINE | grep -o [0-9][0-9])

if xinput list-props $TOUCH | grep "Device Enabled (187):.*1" >/dev/null then xinput disable $TOUCH notify-send -u low -i mouse "Touchpad disabled" else xinput enable $TOUCH notify-send -u low -i mouse "Touchpad enabled" fi