Selections and clipping in The X11 Window System
One of the many tasks when writing an editor for Linux - which I am with my "edlib" project - is to support sending and received content from other applications for copy/paste operations. The X11 protocol provides support this is with "Selections" and a "clipboard" which are documented in the ICCCM - the Inter-Client Communication Conventions Manual. Unfortunately the big-picture of how this should work is poor described, and consequently different applications can behave quite differently and many, in my opinion, get it wrong.
While the selection mechanism can seem confusing and needlessly complex, it actually makes lot of sense and is easy to work with, providing you look at the right way. The important observation is that the "PRIMARY" selection and the "CLIPBOARD" should NOT provide different content. They are really just different interfaces to essentially the same content. Let me explain ....