4

ICCCM defined three selections 1)primary 2)secondary 3)clipboard. But in the xlib, xatom.h had defined only XA_PRIMARY and XA_SECONDARY but clipboard has no such atom. So my doubt is whether clipboard is implemented by xlib or has to be implemented by individual applications like primary and secondary ?

If it has to be implemented by individual applications, how different applications would interact with clipboard as in copy from one application's window and paste to another application's window..? How a common buffer is shared by different applications ? Can anybody help with the actual implementation of clipboard in linux..? I had gone through this link . But I dint find much information about the implementation.

santosh kumar
  • 131
  • 2
  • 7
  • Why do you ask? Not using *existing* toolkits is a huge waste of time; you'll need many years of work to make your own, and it won't be better than existing ones. If an existing toolkit don't satisfy you, better extend it (by coding a few additional widgets) than rewriting one from scratch! – Basile Starynkevitch Nov 04 '13 at 06:33
  • 1
    i'm not making my own, i just want to know the implementation of clipboard. I have to develop a small application. @BasileStarynkevitch – santosh kumar Nov 04 '13 at 11:09
  • Then, look at existing implementations. So, if using Qt, look at Qt's source code (and examples' source code). And most toolkits provide an API to deal with the clipboard, e.g. [QClipboard](http://qt-project.org/doc/qt-5.0/qtgui/qclipboard.html) and it is such APIs which should really matter to you. – Basile Starynkevitch Nov 04 '13 at 14:35
  • And which toolkit are you using, if not implementing your own? It does matter, because the answer depends upon the toolkit in practice. See my updated answer for more... – Basile Starynkevitch Nov 04 '13 at 14:41

2 Answers2

4
bash $ xlsatoms | fgrep CLIPBOARD
231     CLIPBOARD
bash $ fgrep -r XA_CLIPBOARD /usr/include/X11
/usr/include/X11/Xmu/Atoms.h:    _XA_CLIPBOARD,
/usr/include/X11/Xmu/Atoms.h:#define XA_CLIPBOARD(d)            XmuInternAtom(d, _XA_CLIPBOARD)

So we have an atom, no problem with that. You can also just intern it by name.

The CLIPBOARD selection is implemented in exactly the same way as the other selections. The only difference is the moment when selection ownership is asserted. For PRIMARY, it's asserted when the user selects something; for CLIPBOARD, it's when the user cuts or copies.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • thanx for the answer. Can you help with the compiler and linker options for xmu of gcc. I have included X11/Xmu/Atoms.h, but it is saying undefined reference to _XA_CLIPBOARD @n.m. – santosh kumar Nov 04 '13 at 11:05
3

The clipboard has to be implemented inside the X11 server (with a lot of supporting code inside the toolkits), simply because it is data shared by all the X11 clients.

It is defined by ICCCM and EWMH conventions and related to the desktop environment. It may use some non-predefined but conventionally named X11 atoms (there are many such conventional atoms not predefined in xatom.h).

You'll better use some existing toolkit like Qt or Gtk (or FOX or FLTK). They are free software, and you could look inside if you really want to. For Qt, look into QClipboard, for GTK, look into GtkClipboard. So you don't really care about which atoms and X11 protocol is used to implement them.

freedesktop.org has a lot of resources, e.g. this, or the wm-spec etc etc etc...

See also wikipages on X Windows selection, X Windows System protocol and architecture, XDND and read the X11 protocol specifications.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547