Is there a way to disable the middle mouse button paste behavior that is here by default on gnome?
I have a sensitive mouse wheel and whenever I scroll texts, sometimes it pastes stuff randomly into the text. I lose quite a lot of credibility when I send a file to someone else that has random text snippets pasted all over it.
I have seen a solution that goes by mapping the mouse's middle button to a non-existant mouse button, but that implies getting rid of the middle mouse button altogether (i.e. no tab-closing, opening links into a new tab automatically, etc.). I'd like to keep my middle mouse button active, just disable the pasting behavior.
This also happens when I scroll text with my touchpad (accidentally hit two-fingers without moving, bam.)
So the problem will not be fixed just by changing for a new mouse (in fact I believe it happens more often with my touchpad than with my mouse).
I use gnome-tweak-tool for disabling middle button paste in Ubuntu 16.04.
Install it
Run it by searching "tweak tool" in installed apps or just type
gnome-tweak-tool
in a terminal.Turn off.
That's it.
Or using just CLI
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
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:
To persist this behavior, edit ~/.Xmodmap and add
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:
If you place this in a script and add it to your startup scripts this shouldn't be an issue.
Somehow, I ended up without any xmodmap files on my Ubuntu install, so I had to find a different approach to this problem.
Take a look at the xinput command.
which lists information about your mouse. It shows my mouse is "Dell Premium USB Optical Mouse" and also that I have "Macintosh mouse button emulation". Armed with that info, I can
which gives me a listing that looks like
Here is the useful, required knowledge. My mouse has, theoretically, 18 buttons. Each button's default action has the same name as it's button number. In other words, button 1 does action 1, button 4 does action 4, etc. Action 0 means "off".
The position in the listing shows the function assigned to that button. So if my button map read
this would mean button 1 (position 1) does action 1 (normal left button), button 2 (position 2) does action 3 (middle button) and button 3 (position 3) does action 2 (right button).
To make a left handed mouse all you would need would be a button map that starts
Or, in your case, it looks like you want the middle button to do the same thing as button 1 (left button) so your map needs to start
I'd reset my mouse button mappings thus:
In your case, you may have a different number of mapped buttons and have some special button map already defined. Likwely, your mouse has a different name, too. First, get your mouse's "name". Then, use the get-button-map operation to find your base button map. finally, use the set-button-map option, modifying button 2 to do action 1.
This is not a permanent change. I added the necessary code to my .bashrc so it executes every time I login or open a terminal.
Hope this helps.
For a solution to the problem, please view this guide I wrote:
Or, more directly, here's the patch to disable the 'middle mouse button paste' functionality in GTK:
The only answer that worked for me was given on https://unix.stackexchange.com/a/277488/288916 Radivarig (All credits go to him). Note that I had to make one change though to make it work:
Install xbindkeys:
Create a configuration file for xbindkeys
~/.xbindkeysrc
with the text:Load the configuration file using
Add this line to
~./bashrc
so thatxbindkeys
always loads on startup.This is what works for me but what Radivarig suggests is to instead use the line
This last one does not work for me but if one of the versions does not work I suggest to try the other.
After a long time looking this is the only solution I found to work for me that turns off the middle mouse paste button universally without having to disable the middle mouse button completely.
Note that for the existing up-voted answers either they don't answer the question, instead telling you how to disable the middle mouse button completely, or they give a solution that only works in a few programs (tweak-solution only in gedit and gnome terminal and few others) or they simply say it is impossible.
spawn's answer is of a similar spirit and might also work, I did not see it before I found this solution.
Edit: In my opinion the following answer is a better solution than mine: https://unix.stackexchange.com/a/501445/72554
Here's the simplest solution I've found to keep middle click functional without it pasting things.
First install sxhkd and xsel.
Then configure ~/.config/.sxhkd/sxhkdrc like so
And that's basically it.
Now start sxhkd (or configure it to launch on startup). Now, middle mouse will no longer paste anything but will otherwise function like normal. (As long as you use only ctrl+c and ctrl+x to copy things that is, if you copy things with the mouse it can paste once before it returns to normal.)
For Gnome applications you can use
gnome-tweaks
(new name ofgnome-tweak-tool
package) under the "Keyboard & Mouse" tab there's the "Middle Click Paste" option or editing directly the org.gnome.desktop.interface/gtk-enable-primary-paste Gnome option.For KDE applications seems that there's an equivalent solution.
For the whole X (including non Gnome applications) you can install XMousePasteBlock which then has to be running (by the user is enough, no root required) in order to work. This disables completely the middle click paste without disabling the other middle click functions.
I suggest using one of these, which work mostly well for me:
using xbindkeys: whenever middle-button is pressed, clear the primary clipboard. At least on my system it is cleared, before the pasting happens. Details: create xbindkeys-config:
Paste the following new hotkey:
Reload xbindkeys (e.g. killall xbindkeys;xbindkeys). Done.
using xdotool: Clear the clipboard on window focus change (should work with most windowmanagers). Details: Execute the following command:
Note that with this command you can still use the primary clipboard within the same window, or pressing middlemouse onto another window BEFORE focusing it (if you don't have "focus follows mouse", or somthing, activated).