Skip to content

Instantly share code, notes, and snippets.

@bumbummen99
Last active September 16, 2023 04:13
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumbummen99/fcab50dad5638399375693a70a8c17f4 to your computer and use it in GitHub Desktop.
Save bumbummen99/fcab50dad5638399375693a70a8c17f4 to your computer and use it in GitHub Desktop.
Ubuntu disable MCP (middle click paste) on Lenovo TrackPoint middle button

You may have tried to disable the middle click paste (MCP) feature on ubuntu, likely because you work on a notebook/thinkpad or thinkpad keyboard, just to find out that literally every solution to this "issue" does not apply to ubuntu in specific and does just not work. Also since Linux distros have multiple layers of clipboards there are many ways to solve this and to break other functionality at the same time. The obvious solution is to keep the feature enabled but block it on a keymap level for the specific device that should behave "natural". In order to achieve this behaviour we are going to utilize xinput to modify the device mapping. No other device other than the builtin TrackPoint mouse buttons will be affected.

1) Find out the device id

Type in xinput list | grep 'id=' and guess which device is your builtin TrackPoint. Mine is called 'TPPS/2 Elan TrackPoint'

2) Find out which button corrosponds to the middle mouse button

Xinput utilizes a mapping list for all the devices buttons. In order to modify/set this list we first want
to retrieve the current mapping by typing the following command: ´xinput get-button-map ´ which will give an output like: 1 2 3 4 5 6 7

Now that you got the mapping the funny part begins. Each of the entries position corrosponds
to one button and you have to find out which one is the middle button. In order to do this you can simply swap the existing buttons around and observe the behaviour. Dont worry, this change is NOT permanent across relog/reboots. We will make it permanent once it is working. In order to set a mapping simply use the following command: xinput set-button-map <id> <mapping> i.e. xinput set-button-map 17 1 2 3 4 5 6 7

Change the mapping

My middle button was the second entry in the mapping part. If you want to disable the MCP feature but still want to be able to keep the click functionality (Like click/press to scroll in chrome) you simply have to set that button to 0. The following command worked on my T495:
xinput set-button-map 17 1 0 3 4 5 6 7

Make it permanent

As mentioned above the changes made to the keymapping will not persist after a reboot until you add it to a startup script. In order to do so you can simply use Ubuntu's 'Startup Applications' application.

Enjoy lazy scrolling without accidential inserts

@victoriyus
Copy link

This is a nice solution but it's a bit unclear and it removes middle click functionality entirely except for scrolling.
This repository seems to fix this issue without removing functionality

This solution does also work in an entirely different way - which is not bad but should be noted.

The solution i have explained in this gist is dependent on the button mapping, so no interaction with events or clearing any clipboards. That said, the indexes for the buttons can vary from device to device. On a ThinkPad T495 this did work flawlessly, that is why I asked for the specific device so the information can be added.

Doesn't this method literally just block input from middle click entirely? I'm sorry if I'm misunderstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment