56

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?
3
  • 7
    Why have a single coherent clipboard when you could have two of them? </sarcasm>
    – LatinSuD
    Commented Jun 25, 2014 at 18:41
  • @LatinSuD why have only one when you could have two (or more)? it can be extremely useful. Commented Sep 29, 2020 at 15:43
  • 4
    Except it isnt. it's a right royal PITA when using gui and terminals.
    – RichieHH
    Commented Nov 18, 2020 at 10:43

2 Answers 2

53

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.

5
  • CLIPBOARD is primarily used in connection with MS Windows-style clipboard operations. Select+Copy. The data resides in the buffer. We just talking about this in linux nowhere else
    – r004
    Commented Jun 25, 2014 at 19:00
  • @r004: What I meant is it is a MS Windows like clipboard (they work close to identically, including, (often), shortcuts etc.)
    – Runium
    Commented Jun 25, 2014 at 19:23
  • … for end-user, that is.
    – Runium
    Commented Jun 25, 2014 at 19:42
  • 22
    What about SECONDARY?
    – e18r
    Commented Nov 20, 2016 at 16:27
  • 13
    @emisilva: That is secondary (pun indented.) Nah. (Unfortunately) seldom used. If you want something more beyond the links in answer, perhaps a quick dive into Charles Lindsey's fight for the secondary selection is to the liking :) You could also test with Emacs – but your WindowManager would likely mess things up ...
    – Runium
    Commented Nov 21, 2016 at 2:19
6

FWIW, on Debian (Kali), here is how the different selections correspond to the various 'paste options':

echo primary | xclip -sel p
echo secondary | xclip -sel s
echo clipboard | xclip -sel c

# Ctrl + Shift + v: clipboard
# Middle click: primary
# Paste selection: (Shift + Insert): primary

# with the -o option, xclip outputs the specified "selection"
# to stdout:

xclip -o -sel p
# stdout output: "primary"

xclip -o -sel s
# stdout output: "secondary"

xclip -o -sel c
# stdout output: "clipboard"

In my case I performed this in a VMWare VM. The selection which the host OS uses/sees/receives from is primary.

If you dont care to use multiple selections, you can alias xclip to use both primary and clipboard selections like so:

xclip

1
  • 5
    Why you are using screenshots for code?
    – s.ouchene
    Commented Sep 10, 2021 at 20:27

You must log in to answer this question.

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