9

In Linux, clicking with the middle mouse button copies the currently selected text or pastes what was copied previously. It's a separate "slot" than the normal copy and paste. What's worse, it overrides the default middle click behavior. For example in some web apps, pasting whatever text I have selected previously, which is very undesirable.

There are sometimes options in individual programs, such as middlemouse.paste in Firefox, but I'd like a solution that works across the entire system without the need to adjust it individually for every program. How can it be achieved?

7
  • 2
    I'm confused. The "default middle click behavior" is paste :-). it's also kinda hard to do accidentally. Commented May 28 at 8:59
  • 2
    "it overrides the default middle click behavior" - What do you mean by that exactly? What behaviour would you expect from the middle mouse button?
    – marcelm
    Commented May 28 at 9:46
  • 1
    I would expect it, for example, to open a link in a new tab, or engage autoscroll in a web browser, or do other things in other programs. It's really unusual for it to end in a paste in any normal program, especially when it hijacks - and replaces - the usual behavior. Commented May 28 at 21:24
  • Middle-clicking in browsers does open a new tab in Linux. At least, it does in Chromium and Firefox. And in the past, in Galeon, Mozilla, Opera, Netscape, and whatever other browsers I've used. Same for programs like Gimp and Kicad which use the middle mouse button for panning. In my 25 years of using desktop Linux, I've never seen middle-click paste "overriding" anything.
    – marcelm
    Commented May 29 at 21:38
  • 1
    Well, that's not how it works in any other system and it's a very weird functionality that's got to change. Almost anybody who uses Linux daily has pasted some random text somewhere it shouldn't go at least a couple of times because they middle-clicked inside a text field somewhere. God forbid if there's a newline in there. Normal clipboard uses ctrl+c/ctrl+v and that's way harder to do by accident. Commented May 31 at 23:49

2 Answers 2

10

without the need to adjust it individually for every program. How can it be achieved?

It kind of cannot, because it is implemented individually within each program. The primary selection buffer is shared, yes, but the actual association of middle-click event with "paste from primary" is not (and neither is standard Ctrl-V clipboard, for that matter). Firefox handles it on its own, GTK-based apps let GTK handle most events, Qt-based apps let Qt handle them, etc.

So, for example, even if you forced the primary selection to remain always empty, it would not change how the apps behave – middle-clicking in Firefox would still lead to it trying to paste from primary instead of doing whatever else you expect it to do. Maybe it will change behavior if the buffer is empty, but more likely it won't.

(And the way primary selection is usually handled, unfortunately, is that toolkits bind its ownership to the literal "selection" (highlighted text) to visualize its contents. So if you had e.g. a clipboard manager that immediately clears the contents of the primary buffer to prevent paste, it would result in text getting immediately deselected in text editors...)

So your best option, most likely, is to find ways to disable middle-click paste at app or toolkit level. GTK3, for example, has an "enable-primary-paste" setting which can be set through its settings.ini or through GSettings:

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

(In an X11 environment the DE exports this as Gtk/EnablePrimaryPaste through XSETTINGS, so if you're using GTK apps outside of a GNOME-based environment, xsettingsd might be used to publish it – or GTK's settings.ini can be edited directly.)

This option was added for GTK3 and later (GTK2 apps will not recognize it). Nothing for Qt either, unfortunately.

6
  • Firefox has middlemouse.paste in about:config which seems to work Commented Jun 28 at 7:52
  • The question already stated that Firefox has middlemouse.paste. Commented Jun 28 at 10:33
  • This doesn't do anything in Cinnamon 6.0.4. I already have the settings set to false,false, true, in the mentioned order, yet middle click still pastes stuff in FF.
    – Leprechaun
    Commented Jul 11 at 10:54
  • @Leprechaun: Firefox is not a GTK program, which was the entire point of the post! Commented Jul 11 at 10:57
  • @grawity_u1686 But the OP was asking about a system-wide solution, even specifically mentions FF. Your answer is misleading, because you end up with your best option, most likely, is to find ways to disable middle-click paste at app or toolkit level. which doesn't work.
    – Leprechaun
    Commented Jul 11 at 11:02
0

You can use Linux Mint Cinnamon Edition.

In its Mouse and Touchpad applet, look in the General section. Within that section, you will see a toggle for "Paste the current selection when middle-click is pressed". Set that toggle to the off position.

Now middle-clicking will no longer perform the undesired paste operation.

6
  • 1
    Why the downvote, does this not work? It looks specific to Cinnamon, but sounds plausible? Xfce also has mouse and touchpad options but doesn't have anything paste or middle-click related. Actually, maybe the first line could sound like a command: "USE Linux Mint Cinnamon" and maybe that prompted a downvote from someone with a bad taste for Cinnamon
    – Xen2050
    Commented May 28 at 1:10
  • 3
    @Xen2050 Not the downvoter, but I can certainly see why someone's opinion might be that "you can change your entire operating system to get a GUI to configure this" is not a very good answer to the question, if that's how they interpreted "You can use Linux Mint Cinnamon". No need to assume someone is acting out of bias against Cinnamon or whatever.
    – Ben
    Commented May 28 at 5:30
  • 3
    @Xen2050: My guess is that someone thought "use this specific distro" is a bit overkill as this isn't really a Mint-specific or even Cinnamon-specific setting; all that it ultimately does is flip a toggle that GTK3/4 already has built-in regardless of distro or desktop. (It has no effect on non-GTK3/4 apps.) It just happens that Cinnamon displays it prominently whereas GNOME hides it in the "GNOME Tweaks" app (or in the "Linux Regedit" dconf-editor if you want). Commented May 28 at 8:34
  • 1
    Does not work in firefox. It works in the built-in text editor, presumably because it's GTK-3, but not everywhere, like the question asks. grawity's answer seems to hold for Mint too Commented Jun 28 at 7:49
  • 1
    @Zoe I agree with the first part - that toggle turns the feature off in some apps. But grawity's answer does not help with FF in Mint.
    – Leprechaun
    Commented Jul 11 at 10:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .