What’s the difference between Primary Selection and Clipboard Buffer

clipboardx11

I am tweaking in Webkit-browser land in Linux and I come accross the terms "Primary Selection" and "Clipboard selection or buffer" very often.

  • I want to understand what are they and what difference do they have?
  • Where does drag and drop pasting fit in?
  • What is the job of xclip in this matter exactly?

Best Answer

They are part of Selection Atoms, or X Atoms.

The Inter-Client Communication Conventions Manual for X states:

There can be an arbitrary number of selections, each named by an atom. To conform with the inter-client conventions, however, clients need deal with only these three selections:

  • PRIMARY
  • SECONDARY
  • CLIPBOARD

In short:

  • PRIMARY selection is typically used by e.g. terminals when selecting text and pasting it by pressing middle mouse button. As in selected text is in Primary Clipboard without any explicit copy action taking place. Quick-Copy is a good name for it. (Not limited to terminal emulators, but as an example.)
  • CLIPBOARD is primarily used in connection with MS Windows-style clipboard operations. Select+Copy. The data resides in the buffer.

Read more here.

Support for PRIMARY was added to WebKit back in 2008.

xclip, which is a command line interface (tool) for X selections (clipboard), traditionally adds data to Primary Clipboard. Optionally one can choose which one to use by the -clipboard option given argument of either.


Corr.: Drag And Drop resides under Xdnd. There is also a Wikipedia entry on the spec. It uses XdndSelection and should not interfere with PRIMARY.

The protocol is at least implemented by Qt and GTK.