How does clipboard work? [duplicate]
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