Score:4

How to disable middle button paste in Ubuntu 20.04.2 LTS?

in flag

I have installed Tweaks and turned Middle Click Paste off. That doesn't help.

I have also followed all of the recommendations in these posts:

How do I disable middle mouse button click paste?

However, I can't get it disabled. It's a very annoying behaviour, in my opinion, and I can't see why it's so hard to get rid of it. Seems like a huge bug.

$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Elan Touchpad                             id=12   [slave  pointer  (2)]
⎜   ↳ Elan TrackPoint                           id=13   [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)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Integrated Camera: Integrated C           id=10   [slave  keyboard (3)]
    ↳ Integrated Camera: Integrated I           id=11   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=14   [slave  keyboard (3)]
    ↳ ThinkPad Extra Buttons                    id=15   [slave  keyboard (3)]

Score:0
gh flag

I made it in lubuntu 20.04 with a xorg.conf

this way the setting survives suspend to ram.

First identify your mouse name with

xinput list

then create a file

/etc/X11/xorg.conf.d/somefile.conf

cat /etc/X11/xorg.conf.d/50-mouse-map.conf 
Section "InputClass"
    Identifier  "PIXART USB OPTICAL MOUSE" #here your mouse name
    Option  "ButtonMapping" "1 0 3 4 5 6 7" #here your mapping
EndSection

wiki xinput

you can control if it is working with

grep ButtonMapping /var/log/Xorg.0.log 

Note: only tested with focal (20.04) X11 session!

Score:0
ru flag

This solution worked for me:

Disable middle click to paste in Firefox

On the URL bar, type “about:config“, press Enter

Click the “I’ll be careful, I promise” button.

Select for “middlemouse.paste“.

Double click on it to change the value from “true” to “false”.

Disable middle click to paste in Firefox


Patching the gtk source file

Also instruction for patching GTK3 (Ubuntu 20.04) also works for me.

Open a terminal and type the following:

sudo apt-get update
sudo apt-get upgrade

Next, grab the necessary files for compiling the code:

sudo apt-get build-dep gtk+3.0
sudo apt-get install build-essential

Create the patch file

mkdir /tmp/gtk
cd /tmp/gtk
nano gtk_disable_middle_mouse_button_paste.patch

And paste the following:

diff -ur gtk+2.0-2.20.1/gtk/gtkselection.c gtk+2.0-2.20.1-patched/gtk/gtkselection.c
--- gtk+2.0-2.20.1/gtk/gtkselection.c   2010-05-01 22:14:29.000000000 -0500
+++ gtk+2.0-2.20.1-patched/gtk/gtkselection.c   2011-09-17 10:45:37.000000000 -0500
@@ -1065,6 +1065,24 @@
   display = gtk_widget_get_display (widget);
   owner_window = gdk_selection_owner_get_for_display (display, selection);
   
+  if (selection == gdk_atom_intern("PRIMARY", TRUE)) {
+      GtkSelectionData selection_data;
+
+      selection_data.selection = selection;
+      selection_data.target = target;
+      selection_data.type = gdk_atom_intern("STRING", TRUE);
+      selection_data.format = 8;
+      selection_data.data = (unsigned char *)"";
+      selection_data.length = 0;
+      selection_data.display = display;
+
+      gtk_selection_retrieval_report(info, selection_data.type,
+              selection_data.format, selection_data.data,
+              selection_data.length, time_);
+
+      return TRUE;
+  }
+ 
   if (owner_window != NULL)
     {
       GtkWidget *owner_widget;

Now, we are going to grab the gtk 3.0 source code

apt-get source libgtk-3-0
cd gtk+3.0-{your-version}

Apply the patch:

patch -p1 < /tmp/gtk/gtk_disable_middle_mouse_button_paste.patch

Recompile the source code:

sudo apt-get install cdbs 
sudo dpkg-buildpackage -uc -us

Install the patched file:

sudo dpkg -i ../libgtk-3-{your-version}.deb

Log out and login again. The mouse middle-click to paste feature should be disabled now.

Instruction for GTK2

David avatar
cn flag
Answers that are nothing but links are not very good. What about later when the link is gone?
Myrkytyn avatar
ru flag
@David thank you. I will edit my answer in a few minutes <3
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.