2

I'm trying to add custom shortcuts to enable/disable a touchpad on my laptop. I have GNOME 3 on Wayland. Using a suggestion from https://unix.stackexchange.com/a/571537/138312, I managed to do it using a terminal. However, if I put exactly the same commands into shortcuts (using a GUI, the only way I know), they don't work. Does anyone know the solution for this, or any other way around to have shortcuts for a touchpad?

Some details, if needed: Lenovo Thinkpad T450s, Debian 9, Gnome 3.22.2

2 Answers 2

7

I know it's been 9 months, but here's a solution that I just set up and that works for me:

  1. Create a shell script in location of your choice. For instance touch /home/$USER/toggle_touchpad.sh

  2. Make it executable chmod +x /home/$USER/toggle_touchpad.sh

  3. Paste following inside of it:

#!/usr/bin/env bash

if [ $(gsettings get org.gnome.desktop.peripherals.touchpad send-events) == "'enabled'" ]; then
    echo "Switching off"
    gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
else
    echo "Switching on"
    gsettings set org.gnome.desktop.peripherals.touchpad send-events enabled
fi

This will check if send-events is set to on or off at the moment and apply the opposite.

  1. Now go to "Keyboard Shortcuts" and create a custom shortcut
  • Name: Toggle touchpad (but up to you)

  • Command: /home/$USER/toggle_touchpad.sh (or your script location from step 1)

  • Shortcut: Ctrl+Super+T (or whatever works for you)

Now pressing Ctrl+Super+T will toggle Touch pad on and off.

1
  • Well, your comment is pretty useful even after 2 years. This worked for me well in Fedora 38. Commented Sep 6, 2023 at 16:04
0

Thanks, @Kasami for your super helpful answer here. I made a small change to include a desktop notification:

#!/usr/bin/env bash

IDFILE=~/tmp/touchpad_notification_id
[[ -f $IDFILE ]] && ID="-r $(<$IDFILE)" || ID=""

if [ $(gsettings get org.gnome.desktop.peripherals.touchpad send-events) == "'en
    echo "Switching off"
    gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
    notify-send -pe $ID -a Touchpad "Touchpad disabled" > $IDFILE
else
    echo "Switching on"
    gsettings set org.gnome.desktop.peripherals.touchpad send-events enabled
    notify-send -pe $ID -a Touchpad "Touchpad enabled" > $IDFILE
fi

The arguments (for those unfamiliar with notify-send):

  • -p - print the numeric id of the new notification
  • -e - transient notification - don't persist in unread notifications
  • -r - replace the previous notification if it exists (used in $ID)
  • -a - app name

The rest of the shell stuff just stores the notification ID in a temp file so the notification can be replaced the next time. This is useful if you press the shortcut key a few times and want to actually see it "toggle", vs the notifications being displayed one after the other only after they time out or you dismiss them.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.