- Both X11 and Wayland have
clipboardandprimaryclipboards. Theclipboardclipboard stores the text you copy. Theprimaryclipboard stores the text you select (not copy!) using the mouse. - When you paste using your keyboard, it pastes the text stored in the
clipboardclipboard, but when you paste using middle click, it pastes from theprimaryclipboard. - The idea is to clear the
primaryclipboard, when you middle click so that nothing gets pasted, and we only clear theprimaryclipboard so the text you copied previously will remain as-is.
- Install a key binding daemon that is capable of listening to mouse button clicks (middle click in our case) and executing shell commands. I personally recommend evsieve.
- If you are using X11, make sure
xselis installed. If you are using Wayland, make sure BOTHxsel(for xwayland windows) andwl-clipboard(for native windows) are installed. - Run evsieve with these flags on boot (e.g. in your wm/compositor's config):
Note: Replace /dev/input/by-path/your_mouse with the actual path to your mouse.
evsieve --input /dev/input/by-path/your_mouse grab --hook btn:middle exec-shell="wl-copy -pc && xsel -nc" --output- Restart your wm/compositor (to ensure all applications restart from a fresh slate)
- Try pasting with middle click. If everything went correctly, it should no longer paste anything.