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?

1
  • 2
    The clipboard is maintained by the graphical user interface. How exactly it does it depends on the specific GUI. In general it works something like this: an application which wants to put something on the clipboard tells the GUI that it has acquired the clipboard. When another application wants to get the contents of the clipboard the GUI tells the first application to render the content, takes the rendered content and gives it to the second application. For details you should read the programming documentation of the specific GUI you are interested in.
    – AlexP
    Dec 3, 2017 at 0:41

1 Answer 1

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

0

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