Copy, Quit, Paste.
Clipboard persistence is a bug that affects many programs under Ubuntu and other X11-based operating systems. Fixing it is a Google Summer of Code 2010 project.
The problem: data loss on quit
If you copy something from an affected application and then close it, you'll have an empty clipboard.
Workaround: Clipboard Managers
If you want to fix this problem on your machine, you can install a clipboard manager that should solve it. I recommend Parcellite. It's available in the universe repositories, and you can install it with:
sudo apt-get install parcellite
When you restart your computer or run it manually from Programs>Accessories>Parcellite, you'll have a panel applet that quietly saves a history of all your copies. You won't have to go look at the history to resurrect your copied text. Copy, quit, paste should just work.
Parcellite is also available for other distributions.
Similar programs include
- Klipper, a part of KDE
- Glipper, an alternative for the Gnome environment
- Clipman, for XFCE
Why does this happen?
The problem happens because Xorg takes a conservative approach to copying. It copies only a reference to the original data when the user performs a select or copy. It doesn't go and retrieve the actual data from the source program until the user requests a paste. It saves a lot of unneeded transfer of data this way, at the expense of having no way of retrieving data from a closed program that hasn't saved its clipboard somewhere else.
How to fix it: the ClipboardManager spec
Freedesktop's ClipboardManager specification comes to the rescue. Gnome settings daemon, the component of Ubuntu that handles all copying and pasting by default, conforms by allowing applications to explicitly request to save their clipboard contents in a safe place. Applications conform by requesting a save before they exit. Everything gets squared away before a quit and we don't lose any data.
Pure Gnome applications that use standard features like TextViews are automatically supported.
Applications that use GTK+ features can provide persistence by
setting set_can_store on clipboard contents whenever they gain ownership of the clipboard
saving clipboard contents on quit with gtk_clipboard_store
Xlib provides a variety of selection management functions that can be used to store clipboard data. http://michael.toren.net/mirrors/doc/X-copy+paste.txt's a great introduction to Xlib clipboard functions, but be aware that the document is twelve years old and written before the existence of the ClipboardManager specification.
The state of things
There are very few applications that conform to the ClipboardManager standard, and we believe that few developers are even aware of the problem. It has notably been fixed, however, in Firefox, most Gnome applications, Evolution, and Pidgin.
There is currently (2010) a Summer of Code project for Ubuntu devoted to fixing the problem. Please contact SarahStrong for updates.