Any updates on disabling middle-click paste?

I'm using the middle mouse button on my ThinkPad with Ubuntu to scroll and I'm pasting a lot of text in my documents by accident which is very annoying and I often end up with messed up documents.

I searched on the internet how to disable this feature. The only quick solution I've found is to execute xmodmap -e "pointer = 1 25 3 4 5 6 7 8 9" in the konsole or for a persistent change to put pointer = 1 25 3 4 5 6 7 8 9 in the ~/.Xmodmap file. So the middle butten gets remapped to another button. This works fine for me, but now I cannot use use the middle mouse button for anything else---especially not for my beloved feature of opening new tabs in firefox by middle-clicking. Or just anything else...

Apart from directly patching the GTK I was not able to find anything else. Does someone know a more elegant way to disbale the middle-click-paste functionality in Ubuntu?


my system:
ThinkPad-R61
3.8.0-30-generic #44-Ubuntu SMP Thu Aug 22 20:54:42 UTC 2013 i686 i686 i686 GNU/Linux


Solution 1:

Here's the best 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

~button2
    echo -n | xsel -n -i
~control + c
    echo -n | xsel -n -i
~control + shift + c
    echo -n | xsel -n -i
~control + x
    echo -n | xsel -n -i

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

Solution 2:

There is some clean solution that works on Ubuntu 14.04. I obtained it by running gnome-tweak-tool -v -d. The solution is:

gsettings set org.gnome.settings-daemon.plugins.xsettings overrides  "{'Gtk/EnablePrimaryPaste': <0>}"

It can be done in dconf-editor as well: org->gnome->settings-daemon->plugins->xsettings --->>> overrides and put {'Gtk/EnablePrimaryPaste': <0>}.

To activate it you can put 1 instead of 0.

Solution 3:

What I ended up doing was creating two aliaseses in .bashrc:

alias mc-off='xmodmap -e "pointer = 1 25 3 4 5 6 7 8 9"'
alias mc-on='xmodmap -e "pointer = 1 2 3 4 5 6 7 8 9"'

Now every time I need to disable the trackpad's middle click I run mc-off from a terminal and mc-on to switch it back on when I plug a mouse.