How do I disable middle mouse button click paste?

I use gnome-tweak-tool for disabling middle button paste in Ubuntu 16.04.

  1. Install it

    sudo apt install gnome-tweak-tool
    
  2. Run it by searching "tweak tool" in installed apps or just type gnome-tweak-tool in a terminal.

  3. Go to "Keyboard and mouse" -> "Middle-click paste"
  4. Turn off.

    screenshot

That's it.

Or using just CLI

gsettings set org.gnome.desktop.interface gtk-enable-primary-paste false

Tested on 16.04.


I realise that this is not exactly the answer you want, but you can turn this off in Firefox (e.g. if you don't mind the feature elsewhere, but still want middle click in Firefox to open links in new tabs)

In about:config, set

middlemouse.contentLoadURL false
middlemouse.paste false

Not what you asked, but as this question is linked to from a few places I hope someone finds this answer useful.


Jared Robinson gave a simple solution that works on my machine:

Run the following command:

xmodmap -e "pointer = 1 25 3 4 5 6 7 8 9"

To persist this behavior, edit ~/.Xmodmap and add

pointer = 1 25 3 4 5 6 7 8 9

This currently isn't possible - though, as you have mentioned, there are ways to disable the MOUSE 3 button - or remap it- none of those get at the source of the issue. The X11 Primary Selection.

While this isn't a solution, hopefully this explanation will make it clear WHY. In Ubuntu there are two clipboards at work. One, which everyone is familiar with, the freedesktop.org clipboard (captures Ctrl+C command) The second is a clipboard manager that has been at play since before Ubuntu even existed - X11. The X Server (X11) manages three other clipboards: Primary Selection, Secondary Selection, and Clipboard. When you select text with your pointer it gets copied to a buffer in the XServer, the Primary Selection, and awaits pasting by means of the Mouse 3 button. The other two were designed to be used by other applications in a means to share a common clipboard between applications. In this case the freedesktop.org clipboard manager in Ubuntu already does this for us.

Through the extent of my research I can not find a way to disable the X11 selection manager. There are no compilation flags, applications, or configuration values that can disable this. There are various ways around this on a per application basis (majority of these applications being command line ones) - but nothing on a global scale.

I realize this isn't an ideal solution - but seems to be the truth to the issue. The only relevant solution I could muster is actually a hack, create a script that executes an infinite while loop that just replaces the Primary Selection with a null value.

First install xsel (Tool for manipulation of the X selection) sudo apt-get install xsel

The code is as follows:

while(true)
do
    echo -n | xsel -n -i
    sleep 0.5
done

If you place this in a script and add it to your startup scripts this shouldn't be an issue.