Disabling primary selection

Linux desktop traditionally has two buffers to copy text and other data between windows: clipboard that you access by using context menu items "Copy" and "Paste" and so-called "primary selection". Primary selection is called after the PRIMARY atom used in X11 and is used by selecting the text to copy it into primary selection and middle-click to paste. I am using Wayland now and don't even have Xorg installed, but primary selection is still emulated on Wayland.

Recently Jordan Petridis made a change to GNOME to disable middle-click paste by default that was merged. He also proposed a patch to disable it by default in Firefox. This change made some news. I don't use GNOME, but because of the news decided to look again at the situation and see if I can disable primary selection on my desktop.

I don't like having multiple buffers because it is difficult to track which contents is in the clipboard and which is in the primary selection. Some software only supports one but not the other, or has an easy way to access only one of the buffers. For example, Alacritty, the terminal emulator that I use, has no context menu, so I can only paste from the primary selection but not the clipboard when using the mouse. Clipboard I can only access using the Ctrl+Shift+C and Ctrl+Shift+V shortcuts.

Niri

One of the comments on the Firefox issue suggested that it should be possible to disable on Wayland compositor level, so this is where I started. Wayland has a primary selection protocol and compositors may not support it or have a way to disable it. I am using using Niri as my Wayland compositor, so I looked in the Niri wiki and found an option to disable primary selection there. I added this section to ~/.config/niri/config.kdl:

clipboard {
    disable-primary
}

Disabling primary selection in the compositor was supposed to be enough, but after testing with Firefox 146.0.1 and GNU Emacs 30.2, I noticed that middle-click still works for pasting. In Firefox selecting in the search bar apparently did nothing, but middle-click started to paste from the clipboard instead of primary selection. In Emacs it even appeared as if primary selection was still used as if it was not disabled: both copying and pasting worked, even between windows (called frames there).

Emacs

I then looked up Emacs documentation and found that Emacs emulates primary selection when it is not available.

I have disabled copying to this emulated primary selection by adding (setq select-active-regions nil) to the config. However, mouse-2 (Emacs name for middle-click) still continued pasting the current state of the primary selection at the time of disabling copying to it. To make it usable, I bound mouse-2 to paste from the clipboard with (global-set-key (kbd "<mouse-2>") 'mouse-yank-at-click).

Alacritty

With the default bindings middle-click in Alacritty 0.16.1 pastes from the primary selection.

To make it usable without the primary selection, I have configured Alacritty to paste from the clipboard on middle-click and also configured Ctrl+Insert and Shift+Insert (in addition to the default Ctrl+Shift+C and Ctrl+Shift+V) to use the clipboard by adding these lines to ~/.config/alacritty/alacritty.toml:

[mouse]
bindings = [
  { mouse = "Middle", action = "Paste" }
]

[keyboard]
bindings = [
  { key = "Insert", mods = "Shift", action = "Paste" },
  { key = "Insert", mods = "Control", action = "Copy" },
]

Firefox

Firefox at this point still continues to paste the clipboard with middle-click, but not copy. This is now consistent with my Emacs and Alacritty setups. I have however checked, there is an option middlemouse.paste in about:config and if I disable it explicitly, pasting via middle-click stops working. So if I decide that I don't want middle-click to paste, I can consistently disable it across Emacs, Alacritty and Firefox. As of 2026-01-11 the issue in Firefox bugtracker about disabling middlemouse.paste by default is still open.