Removing Middle Click or Middle Tap from Touchpad on Linux
This Dell XPS has a touchpad with a line at the bottom to mark the border between the two buttons - left and right. Which makes it even more annoying when a mystical middle button is recognised. There’s no good thing about a middle button - they have the absolute worst behaviour mapped to them; pasting in the middle of what you’re writing; closing a browser tab; etc.
It should be possible to disable middle click using some sort of utility in the desktop environment. When I was using Gnome, settings was no help and neither was the Gnome Tweaks package. Now I’m using KDE Plasma, there doesn’t seem to be a setting for it either. So we have to delve into the command line to make this happen.
First we need to find the touchpad amongst the input devices attached to the laptop. We can run xinput list
for this…
$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ DLL0945:00 06CB:76B1 Mouse id=10 [slave pointer (2)]
⎜ ↳ DLL0945:00 06CB:76B1 Touchpad id=11 [slave pointer (2)]
⎜ ↳ PS/2 Generic Mouse id=15 [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)]
↳ Power Button id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ Integrated_Webcam_HD: Integrate id=9 [slave keyboard (3)]
↳ Intel HID events id=12 [slave keyboard (3)]
↳ Dell WMI hotkeys id=13 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=14 [slave keyboard (3)]
We can see that touchpad is usefully labellled as “Touchpad” and we can see that it has an ID of 11. I can now disable the middle click on the touchpad by running…
$ xinput set-button-map 11 1 1 3
This is not particularly obvious (apart from the “set-button-map” part). But what I’m doing here is taking device number 11 (my touchpad) and remapping the three buttons so that the first two are mapped to 1 (left-click) and the third is mapped to 3 (right-click). The middle of the trackpad is now the same as the left. So I have a bigger area for the left-click and a smaller area for the right-click (like the classic PS/2 Microsoft mouse).
Sadly, we’re not quite done. When I restart the machine, the middle-click comes back. So need I need to wrap this into a shell script and drop it into /etc/init.d
so it will run whenever the machine boots.
#!/bin/sh
xinput set-button-map 11 1 1 3
But even now, we’re still not done. If I boot my machine whilst connected to my dock, there’s other input devices like an actual two-button mouse present, and my touchpad is no longer ID=11. Sometimes it’s 13, sometimes it’s 9. It seems it could basically be anything. If I disconnect from the dock without rebooting, the touchpad still has the middle-click.
So I need to break out some awk
to parse the output from xinput --list
. Here’s my awk
command where I do a match (between “/” characters) on the name of the device to filter out the others. Then I print the sixth ($6
) field in that line (id=11
) but starting from position 4
in that string, which gets rid of the id=
at the beginning.
$ xinput --list | awk '/DLL0945:00 06CB:76B1 Touchpad/ { printf substr($6, 4) }'
Within my shell script, I can capture the output of this into a variable, and then use it in my second call to xinput
to remap the buttons. And finally, I have rid myself of the touchpad middle-click…
#!/bin/sh
device=$(xinput --list | awk '/DLL0945:00 06CB:76B1 Touchpad/ { printf substr($6, 4) }')
xinput set-button-map $device 1 1 3