3

I have found similar questions:

How can I set a keyboard shortcut to toggle on/off e.g. the trackpad?

and

How to set a toggle on linux (True or False) bash command?

But these are gnome-based, their solutions use gsettings commands, which don't work in Xfce (like org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled).

The commands I use in Xfce are synclient touchpadoff=1 and synclient touchpadoff=0.

How to adjust those in a command that would opertate like an on/off toggle?

cipricus
  • 1,529

2 Answers2

3

Source: https://www.commandlinefu.com/commands/view/19659/toggle-the-touchpad-on-or-off

Put the command in a script:

#!/bin/bash

tp=$(synclient -l | grep TouchpadOff | awk '{ print $3 }') && tp=$((tp==0)) && synclient TouchpadOff=$tp

Another command that can be used is

synclient TouchpadOff=$(synclient -l | grep -q 'TouchpadOff.*1'; echo $?)

Make that script executable. Create a shortcut to run the script.


UPDATE: As the synclient method may not work on newer systems:

#!/bin/sh
# This shell script is PUBLIC DOMAIN. You may do whatever you want with it.

TOGGLE=$HOME/.toggle_touchpad

if [ ! -e $TOGGLE ]; then touch $TOGGLE xinput disable 14 notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/status/touchpad-disabled.png "Trackpad disabled" else rm $TOGGLE xinput enable 14 notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/devices/input-touchpad.png "Trackpad enabled" fi

In the above commands 14 is a variable to be identified with xinput list

~$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Sony Vaio Jogdial                         id=8    [slave  pointer  (2)]
⎜   ↳ BM30X mouse                               id=12   [slave  pointer  (2)]
⎜   ↳ AlpsPS/2 ALPS GlidePoint                  id=14   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Video Bus                                 id=6    [slave  keyboard (3)]
    ↳ Sony Vaio Keys                            id=7    [slave  keyboard (3)]
    ↳ Video Bus                                 id=9    [slave  keyboard (3)]
    ↳ Power Button                              id=10   [slave  keyboard (3)]
    ↳ USB 2.0 Camera: USB Camera                id=11   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=13   [slave  keyboard (3)]

To identify the name of the device in that list look in the Mouse & Touchpad settings

enter image description here

This script also shows a notification with icon, as well as message.

Sources here, here, also here.

cipricus
  • 1,529
2

I'm running Xubuntu 21.10 (xfce). The xinput method didn't work because synclient/synaptics wasn't in sync & is still running.

Rather than try the synclient solution, which may not work in the future, I used belt and suspenders:

#!/bin/sh
# This shell script is PUBLIC DOMAIN. You may do whatever you want with it.

TOGGLE=$HOME/.toggle_touchpad

if [ ! -e $TOGGLE ]; then touch $TOGGLE synclient touchpadoff=1 xinput disable 13 notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/status/touchpad-disabled.png "Trackpad disabled" else rm $TOGGLE xinput enable 13 synclient touchpadoff=0 notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/devices/input-touchpad.png "Trackpad enabled" fi

brad80242
  • 21
  • 2