How to disable touchpad when mouse is connected and how to rebind mouse buttons?

Hello,

I would like my laptop’s touchpad to get disabled when I connect a mouse. I have seen an option like this on Mint with Cinnamon, but I can’t find anything like it in Endeavour with Plasma.

Also, my mouse has two side buttons for navigating forwards and backwards in browsers and such, but I would like to swap the buttons. I have found the “Re-bind additional mouse buttons” option in mouse settings, but it doesn’t look like it can be used to achieve what I need.

I have searched around, but most solutions were for Xorg and non-Arch distros. Does anyone have any advice, please?

Hello @bytehowl ,
Not all of your questions I’m going to answer.

yay -S ydotool
sudo systemctl daemon-reload
sudo systemctl enable ydotool.service
sudo systemctl start ydotool.service
ydotool key 530:1 530:0

This last command toggles touchpad enable.

yay -S wayland-mouse-mapper-git
From now on your creativity is needed. I haven’t tested this (edit it)
/usr/bin/mousemapper
To understand more or to get lost

The mousemapper script is almost the same here.
Edit 1:
Here is a more promising clue:

yay input-remapper
sudo systemctl enable --now input-remapper
sudo systemctl start --now input-remapper
sudo input-remapper-control --list-devices | grep Mouse > /tmp/mouse
if [[ -s /tmp/mouse ]]; then
   ydotool key 530:1 530:0
fi

to check if mouse is present
and
input-remapper-gtk
helps you to do the remapping

Hm, so I take your advice to mean there’s no built-in way to achieve what I need?

Ydotools isn’t working for me, when I get to the step to enable the service I get:

Failed to enable unit: Unit file ydotool.service does not exist.

This happens even after restart.

I have taken a look at the mousemapper script and read the Baeldung page. At a glance it looks like it should work, but I’m not good enough at bash to fully understand the script. I’ll need to take some time to sit down and take a proper look at it.

I have also taken a look at the input-remapper and I was able to remap the buttons on the mouse. I think a utility like this is preferable for me compared to scripting. I wasn’t able to make it turn off the touchpad yet, because of the ydotools issue…

No idea about this specific solution, but have you tried sudo systemctl enable ydotool ? as a quick attempt to make this work?

I have tried that version and it didn’t work either.

systemctl enable ydotool.service --user --now  

@bytehowl
Sorry, RE ydotool I forgot something.

su
kate /usr/lib/systemd/system/ydotool.service
[Unit]
Description=Starts ydotoold service

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/ydotoold --socket-path="/run/user/1000/.ydotool_socket" --socket-own="1000:1000"
ExecReload=/usr/bin/kill -HUP $MAINPID
KillMode=process
TimeoutSec=180

[Install]
WantedBy=default.target

exit and then

systemctl daemon-reload
systemctl --user enable ydotool.service
systemctl --user start ydotool.service
ydotool key 530:1 530:0

Works without the .service. Try it out :wink:

Failed to connect to bus: No medium found

I got all the way to the end, and then:

failed to connect socket `/run/user/1000/.ydotool_socket': No such file or directory
Please check if ydotoold is running.

It’s not exclusively my fault this ambiguity around ydotool configuration. Here is a summary

yay ydotool
sudo chmod +s $(which ydotool) # all users can use it
# ~/.bashrc
#
export YDOTOOL_SOCKET="/tmp/.ydotool_socket"

mkdir -p .config/systemd/user/
kate ~/.config/systemd/user/ydotoold.service

[Unit]
Description=Starts ydotoold service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=3
ExecStart=/usr/bin/ydotoold --socket-path="/tmp/.ydotool_socket"
ExecReload=/usr/bin/kill -HUP $MAINPID
KillMode=process
TimeoutSec=180

[Install]
WantedBy=default.target

sudo cp /home/a/.config/systemd/user/ydotoold.service /usr/lib/systemd/system/ydotoold.service
#a is my user name

sudo systemctl daemon-reload
sudo systemctl enable ydotoold
sudo systemctl start ydotoold

logout, login ps -ef | grep ydotool should show bg proc
ydotool key 530:1 530:0 # toggles touchpad in wayland

Okay, that finally did it, but there’s another problem…

My touchpad is listed as “ELAN0501:00 04F3:3060 Mouse”, so that script would create the mouse tmp file even if I just have my touchpad.

Also, where am I supposed to put that script so it gets run when devices are (dis)connected?

@bytehowl
Here is a ‘recalculated’ version (skip to Edit2):

#!/bin/sh
journalctl -f -p 6 | awk '/idVendor=046d|disconnect/ { system ("ydotool key 530:1 530:0") }'

find a unique string in journal when your mouse is plugged in /switched on and disconnected by this command:
journalctl -f -p 6
The customized script may be autostarted.
Static query is below at Edit2
It seems a bit over-engineered.

Edit2
For me the RTFM is pretty valid.
/usr/include/linux/input-event-codes.h
So having configured ydotool we also have touchpad on (531) and off (532) keycodes. Let’s wipe down the ‘white-board’ and simplify the case.
I inserted 2 scripts into Autostart a login and a logout one
cat momp.sh

#!/bin/sh
# Check whether mouse is plugged-in and disable/enable touchpad
while :
do
    lsusb | grep -q Mouse
    MOUSE="$?"
    if [ "$MOUSE" != "$PREM" ]; then
     case $MOUSE in
      0)
       ydotool key 532:1 532:0
       ;;
      1)
       ydotool key 531:1 531:0
       ;;
     esac
     PREM="$MOUSE"
   fi
    sleep 5
done

and before logout:

cat mompend.sh

#!/bin/sh
pkill momp.sh

OK, so the final script does work. It is just unfortunate that it relies on a unique string relevant to each device - I don’t always use the same mouse, even now I have a different one than when I started this thread. I suppose I could just check the lsusb output against an array of identifiers… Ideally, it would be built-in, but I guess that’s a complaint for the Plasma devs.

That being said I think can make do with this solution for now. Thank you for your help and patience :slight_smile:

@bytehowl Extended grep covers all of your mice

lsusb | grep -q -E -w ‘Mouse|trackball|anything’

BTW did you @bytehowl know that touchpad can be enabled/disabled by by assigning shortcuts out of the box. Never mind otherwise I would not have learned some new scripting stuff.

Just did this very easily and successfully on my wife’s laptop. In plasma, go to system settings > mouse & touchpad > touchpad. There are checkboxes for disabling the device entirely (if you always use the external mouse, which she does) and disable while typing. Check/ uncheck as you choose. You will need to reboot (not just logout) for the changes to take effect

I do, in fact I didn’t even need to assign anything, the Fn+F7 on my laptop works. However, I’m used to having this automated, and as I have mentioned earlier, Cinnamon has this and also Gnome (with a bit of digging).

Reboots shouldn’t actually be necessary, but again, not automated.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.