Have Notepad++ support X11 and GTK clipboards?

As I understand it, the two clipboards I am using in Linux Mint are the X11 and GTK clipboards.

Copy to X11 clipboard is automatically done every time I highlight something. Paste from X11 clipboard is with mouse middle-click.

Copy to GTK clipboard is with Ctrl+C or Ctrl+X. Paste from GTK clipboard is Ctrl+V.

Notepad++ can only be used with the GTK clipboard.

I do not want to merge these clipboards, as this can cause problems such as when I want to highlight and replace with clipboard.

Is there a way to get Notepad++ to use these two clipboards independently?


Solution 1:

As I understand it, the two clipboards I am using in Linux Mint are the X11 and GTK clipboards.

No, not exactly.

The buffer used by middle-click paste is called the selection – not the clipboard. There is only one "clipboard", and that's the one you access via Ctrl+C/Ctrl+V.

However, both are a generic X11 feature – both use the same "selection" mechanism under the hood. When you select some text it goes into the PRIMARY X11 selection, and hitting Ctrl+C puts it in the CLIPBOARD selection. That is, 'PRIMARY' is called "the selection" and 'CLIPBOARD' is called "the clipboard". Neither of them is more GTK-specific than the other.

(In fact, when support for the latter was added to GTK in 1997, it was already known as "the X clipboard" at that point, and had already existed for several years before that – e.g. it can be found in Emacs source code as early as 1993.)

But at the same time, both are used explicitly by GTK – neither of them is actually "automatic at X11 level". When you select text, it is GTK – not some X11 magic – that puts it in the 'PRIMARY' selection, and when you middle-click it is also GTK that pastes it from 'PRIMARY', in the exact same way that it handles Ctrl+V to paste from 'CLIPBOARD'. (There is even a GTK setting to disable middle-click paste.) The same applies to Qt, Motif, or any other toolkit.

Is there a way to get Notepad++ to use these two clipboards independently?

No. As mentioned, it is the specific UI toolkit, not X11 as a whole, that must implement the middle-click copy/paste. But because Notepad++ is still a Windows app, it doesn't have any access to X11 selections – the only thing it knows is "the clipboard" that Windows apps use.

Its text widgets haven't been programmed to paste anything on middle-click – and couldn't have been, because there aren't any Win32 API functions to read the "selection", only the clipboard. That means there's nothing that Wine could emulate, either; it would have to invent entirely new functionality to make that happen.

So at best, if Notepad++ is scriptable, you could make it run xsel -o or xclip -o as an external program (I think Wine programs can run native Linux programs?), which will output the contents of the 'PRIMARY' selection, and have Notepad++ insert their output into the current document.

Solution 2:

The "two clipboards" are actually both X11, and not related to GTK, although the GTK GUI and API elements use them.

The one is called the section, and the other is called the clipboard.

Traditionally, the selection can be pasted with the middle mouse button, but some systems use right mouse button for this. I believe there is a GTK option to enable that.

Generally the clipboard uses ctrl-c/ctrl-v or cut/paste menu options or some variation of that.