How to quickly enable/disable touchpad in Xubuntu 14.04 without installing other applications?

36,378

Solution 1

That can be easily done with these two commands (inspired by a different answer):

Disable:

synclient TouchpadOff=1

Enable:

synclient TouchpadOff=0

My initial answer was to use

xinput set-prop 15 "Device Enabled" 0

and

xinput set-prop 15 "Device Enabled" 1

where the id number may be other than 15: it can be be found by running

xinput list

I found about these commands in this answer under a question on how to disable the touchpad.


The commands can be added into launchers.

I prefer creating .desktop files (in usr/share/applications or in .local/share/applications) for the two commands to be run easily with a launcher like Whisker Menu, Synapse, etc


Also:

  • by adding them into a single launcher,

  • setting advanced properties like in the image below

enter image description here

(namely 'show last used item' and 'inside button'),

  • and adding two specific icons,

the launcher will always display the current status of the touchpad.

enter image description here


Also it is never a bad idea to assign shortcuts (Settings Manager - Keyboard - Application Shortcuts) to the two commands.

Solution 2

You also can use synclient, like in this answer.

To turn off touchpad:

synclient TouchpadOff=1

To turn on:

synclient TouchpadOff=0

I think this is more convenient way. You don't need to know device id.

So my solution is to create bash script ~/toggle-touchpad.sh:

#!/bin/bash
if synclient | grep --quiet 'TouchpadOff             = 0'; then
  synclient TouchpadOff=1
  notify-send Touchpad Disabled
else
  synclient TouchpadOff=0
  notify-send Touchpad Enabled
fi

Modify file permission:

sudo chmod +x ./toggle-touchpad.sh

Next goto Settings-Keyboard-Application Shortcuts and add new shortcut. Enter path to the script (/home/your_username/toggle-touchpad.sh - for example). Specify shortcut (Fn+F9 in my case).

Done. Now you can toggle touchpad and you will get notification.

Solution 3

The non-launcher version:

#!/bin/bash

# toggle state of synaptics touchpad

tpid=`xinput list | grep SynPS | sed 's/.*id\=\([0-9]\+\).*/\1/g'`

declare -i status
status=`xinput list-props ${tpid} | grep Device\ Enabled | sed -e 's/.*\:[ \t]\+//g'`

if [ 0 -eq ${status} ] ; then
    xinput enable ${tpid}
else
    xinput disable ${tpid}
fi

Solution 4

I have used @cipricus and @Demeter answers, but without using synclient, i thought that would be good to share:

#!/bin/sh

TOGGLE=$HOME/.toggle
TOUCHPAD_ID=$(xinput list | grep "Touchpad" | grep -Eow '[0-9]{2}')

if [ ! -e $TOGGLE ]; then
   touch $TOGGLE
   xinput set-prop $TOUCHPAD_ID "Device Enabled" 0
else
   rm $TOGGLE
   xinput set-prop $TOUCHPAD_ID "Device Enabled" 1
fi
Share:
36,378

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    In Xubuntu 14.04. accessing the settings to disable and enable the touchpad are a bit hidden - in Settings-Mouse and Touchpad, and once there, there are a few other clicks needed.

    enter image description here

    I have tried by installing the panel application touchpad-indicator - but that seemed buggy in Xfce maybe due to conflicts with the Xfce settings...

    Is there a quick and safe method to enable/disable touchpad?

  • TronicZomB
    TronicZomB over 7 years
    Note to others, the spaces in the if statement are all necessary for this script to run correctly. Also, I think it should be sudo chmod +x ~/toggle-touchpad.sh
  • TronicZomB
    TronicZomB over 7 years
    Also, if you like clean files/file structure you could always name the script ".toggle-touchpad.sh" (with a dot "." out front) so that it is a hidden file but will still run just fine.
  • Admin
    Admin over 6 years
    This answer is better as synclient TouchpadOff etc doesn't need the xinput list variable (which varies from system to system); but I find the launchers more Xfce-friendly; so I'll integrate this into my answer
  • rbaleksandar
    rbaleksandar over 4 years
    Funny, the commands (at least with synclient) don't work on my Dell XPS 15 9570. :D
  • Hastur
    Hastur over 4 years
    Unfortunately under kubuntu 18.04LTS it doesn't work. It changes the status number from 2 (the default) to 0 and 1... but do not disable the touchpad. Using xinput --disable 12 where 12 is the number of the device it works. Nice use of notify send (+1).
  • cipricus
    cipricus over 3 years
    @Hastur - the synclient method stopped working in recent systems, xinput method works.
  • cipricus
    cipricus over 3 years
    xinput disable ID and xinput enable ID also work. Notifications with icons can be added too: askubuntu.com/a/1318615/925128
  • Hastur
    Hastur over 3 years
    @cipricus Yep, I was trying to say so... ("but does not disable the touchpad"). I use xinput myself (in my script)... and you seem to confirm that it works for you too... :-)