6

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)]

0

3 Answers 3

1

Based on the output of xinput list you posted, I assume you also have a ThinkPad with a trackpoint and often find yourself accidentally triggering the "middle mouse button paste", e.g. while scrolling with the middle button + track point. If that is the main problem, then you may follow these instructions.

This solution disables the middle button of the trackpoint completely, except for when using it to scroll, which is exactly what I needed in my case. The "middle mouse button paste" behavior is preserved when using external mice or tapping the touchpad with three fingers.

The following script remaps the middle button (2) to 0, which disables it. The other buttons keep their original functionality. Store it locally at a location of your choice.

trackpoint_id=$(xinput --list | grep 'Elan TrackPoint' | grep -oP '(?<=id\=)[0-9]+')
button_map=$(xinput --get-button-map $trackpoint_id)
new_button_map=$(echo $button_map | sed '0,/2/{s/2/0/}')
xinput --set-button-map $trackpoint_id $new_button_map

Note that the ID assigned to the trackpoint may change after rebooting, therefore I extract its ID.

To make sure that this script runs on every startup, do the following:

  1. Open 'Startup Applications' (just hit Super and search for it)
  2. In the GUI, click 'Add' to add the script to the startup programs
  3. Type a name of your liking into the 'name' field. In the 'command' field, type bash and paste the absolute path to the script at the end
  4. Save

Now, everything should work as described, even after rebooting.

0
0

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!

0

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

2
  • Answers that are nothing but links are not very good. What about later when the link is gone?
    – David
    Feb 7, 2022 at 16:47
  • @David thank you. I will edit my answer in a few minutes <3
    – Myrkytyn
    Feb 7, 2022 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .