16

I am running Kubuntu 20.04.

I just noticed that clicking the middle mouse button pastes my clipboard; I don't like that.

I cannot find a way to disable this behaviour. I would like to keep middle mouse button click working, but disable the paste action.

Zanna
  • 70,465
Scorb
  • 770
  • 3
    There are two "clipboards," which in X11 terminology are called the primary selection and the clipboard selection. The primary selection holds text that you've selected. The clipboard selection holds text that you've copied using control-C. Middle-clicking should be pasting the primary selection by default, not the clipboard selection. However, if you select text and then do a control-C, both selections will have that text in them, until you select something else. –  Nov 11 '21 at 13:36
  • 1
    possible duplicate of: https://askubuntu.com/questions/4507/how-do-i-disable-middle-mouse-button-click-paste?noredirect=1&lq=1 https://askubuntu.com/questions/597064/disabling-middle-mouse-button?noredirect=1&lq=1 https://askubuntu.com/questions/349503/any-updates-on-disabling-middle-click-paste?noredirect=1&lq=1 –  Nov 11 '21 at 13:40
  • 3
    Two possible solutions : 1) Don't use it 2) Learn to love it, and understand the difference between "Ctrl+C"+"Ctrl+V" and "Selecting"+"Middle click". It's simple, efficient and very versatile. – Eric Duminil Nov 11 '21 at 15:07
  • 2
    @EricDuminil on my mouse in work the scroll wheel does this for the very lightest of touches, so disabling could be quite handy – Chris H Nov 11 '21 at 16:42
  • @ChrisH: Thanks for the explanation. – Eric Duminil Nov 11 '21 at 16:58
  • @EricDuminil Many graphical programs use middle mouse to pan the view. – Scorb Nov 11 '21 at 20:50
  • @Scorb: Is there a conflict, though? As far as I know, the programs are still free to decide what to do with a middle click. It's not like those graphical programs pan the view and copy the text somewhere, is it? – Eric Duminil Nov 11 '21 at 21:00
  • @EricDuminil Figma does both. – Scorb Nov 11 '21 at 21:12
  • @Scorb: At exactly the same time? – Eric Duminil Nov 11 '21 at 21:14
  • Yes. When I pan the view in Figma with middle mouse, it also pastes the clipboard contents into the figma view. – Scorb Nov 11 '21 at 21:22
  • 1
    @Scorb That sounds like a bug in the app, then. – Eric Duminil Nov 12 '21 at 08:55

5 Answers5

11

The following solution globally disables paste on middle click for me while retaining all middle mouse button and clipboard functionality:

Follow the steps described in this answer, that is:

  1. Install xbindkeys xsel xdotool

  2. Place this in ~/.xbindkeysrc

    "echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"  
    b:2 + Release
    
  3. Reload xbindkeys -p

In step 2. you may need to remove the + Release part as described in this post, depending on what works on your machine.

Set up xbindkeys to run on startup.

Then open Klipper, e.g. via the clipboard icon in the system tray > right click > Configure Clipboard. Uncheck the option 'Prevent empty clipboard'. Reboot and the problem should be solved.

The latter idea is thanks to milaq's XMousePasteBlock.

  • 2
    For anyone searching the internet for a solution that hasn't stopped working, this one works in 22.04. (Thanks!) – Tachytaenius Dec 12 '22 at 18:49
  • Funnily enough, this actually breaks middle mouse scrolling using a tablet input device. Guess I'm sticking with middle mouse paste after all. – Tachytaenius Dec 12 '22 at 19:05
  • I use gnome and wayland and I thought I needed to do this to fix VSCode middle mouse paste to the vertical selection. Turns out there is a VSCode config that controls it as well, so if you're using VSCode to litmus test, be careful because it will still middle mouse click unless you have set "editor.selectionClipboard": false on your settings – Andrew Knackstedt Feb 27 '23 at 21:34
  • 2 years later, after some new bug I need that tool again. Thx a lot! – Joergi Mar 12 '24 at 09:27
7

Right-click somewhere on the desktop and choose Configure Desktop and Wallpaper... from the context menu. This will open the Desktop Folder Settings window. There you can configure the mouse actions:

Desktop Folder Settings window

mook765
  • 15,925
2

Steps for a solution:

  1. Identify the ID/IDs of your device with

    xinput list 
    
  2. Get the button map with

    xinput get-button-map <ID>
    
  3. Set the button action

    xinput set-button-map <ID> 1 <new action>
    

Repeat the last command for as many IDs as your mouse has. 1 stands for the mapping of left-click, then for middle click, etc. Use for <new action> number 0 to disable middle-click, number 1 if you want to make it equivalent to left-click, etc.

There are other possible methods.

Related:

  1. Any updates on disabling middle-click paste?
  2. How do I disable middle mouse button click paste?
  3. Disable mouse middle button click paste on KDE, keeping that button working
  4. https://bbs.archlinux.org/viewtopic.php?id=100940
  5. https://www.reddit.com/r/kde/comments/7a71fa/disable_middleclick_paste_and_just_paste/
  6. Disabling middle mouse button
0

These random pastes were polluting my source code. I was able to stop them on my Ubuntu 22.04 by setting:

gsettings set org.gnome.desktop.interface gtk-enable-primary-paste false

No restart or additional command was necessary. Source here: https://linuxconfig.org/how-to-disable-middle-mouse-button-click-paste-on-ubuntu-20-04-focal-fossa-linux

Duloren
  • 795
0

I had the middle mouse button paste problem on Kubuntu 23.10.

The only solution that worked for me and was easy to follow is at http://www.humans-enabled.com/2019/03/how-to-disable-mouse-middle-click-in.html