5

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

Stan
  • 1,060
  • 2
  • 11
  • 15

4 Answers4

6

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

Cestarian
  • 251
  • This worked for me on Ubuntu 18.04 on a Thinkpad Carbon X1. – Joel Feb 14 '19 at 01:11
  • 2
    When I tried this, I needed to do the same thing for button1, which is probably left click. That would make sense, since you left click to highlight text, and highlighting text is what puts text into the middle click buffer. – Dave Yarwood Mar 23 '19 at 23:42
  • BTW, this worked for me on Ubuntu 16.04 on a Thinkpad Carbon X1 :) – Dave Yarwood Mar 23 '19 at 23:43
3

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.

muru
  • 197,895
  • 55
  • 485
  • 740
  • Just tried this and failed. Am I correct that this does not work anymore on Ubuntu 18. (If it ever did, more likely it was equivalent to switching of the middle mouse button in Gnome Tweak Tool which does not actually work accept in a select few programs.) – Kvothe Aug 30 '18 at 14:40
  • This worked for ubuntu 18- lenovo on touchpad. Thanks – saurabheights Apr 03 '19 at 17:09
1

I too tried to look for a clean solution to this problem, but ended up going for a surprisingly effective work-around. If you have xsel installed, you can clear the contents of the primary paste buffer (the one used by the middle mouse) with xsel -p -c. You can then create a keyboard shortcut that executes this command, and map it to any unused keys (in my case, the rectangular ThinkPad button which is farthest to the right in the left-hand corner of the space above the keyboard proper on my ThinkPad X230; you should have a similar button (might be blue on your model), but if not, you can use any other vestigial button that you wish). I used the system preferences pane for Keyboard Shortcuts to do this, so Xmodmap is not required for this workaround. Now, whenever I want to use my middle mouse, I press this button to clear any content that might be in the paste-buffer, and it works perfectly, without the need to cripple the functionality of the middle mouse.

I hope you find this response useful, or otherwise find the answer you are looking for.

1

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.

h3nr1x
  • 111