2

On a deep level, how does copying something to the clipboard work? Is there a file that stores the text or image I copy somewhere?

I found Memory location of clipboard where the question was never answered. I also found a lot of references to xclip. I don't currently have xclip installed, but my clipboard works fine--eg I could copy something from Firefox and paste it into terminal with no issues. So, clearly something must be happening on a different level than xclip. What is that and how does it work?

Kaia
  • 123

1 Answers1

5

X handles the clipboard and you can read about it here. https://specifications.freedesktop.org/clipboards-spec/clipboards-latest.txt

X11 the clipboard which is known as selections are defined in the ICCCM. https://www.x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html

Quoting the above link.

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

These selections are all stored in memory and are not written to the disk.

Worth reading is X Selections, Cut Buffers, and Kill Rings. https://www.jwz.org/doc/x-cut-and-paste.html

Another worthwhile read is Writing a cross-platform clipboard library https://jtanx.github.io/2016/08/19/a-cross-platform-clipboard-library/

If you're interested in how to interact with the X11 selections grammatically then definitely check out the xclip source code on GitHub. https://github.com/astrand/xclip