procedure start_application () begin ... start_a_thread_that_checks_every_1000_milliseconds (); ... end. the_last_selection_owner as Window; procedure a_thread_that_checks_every_1000_milliseconds () begin the_current_selection_owner = XGetSelectionOwner (); if (the_current_selection_owner != the_last_selection_owner) then begin the_last_selection_owner = the_current_selection_owner; get_the_current_clipboard_and_store_it (); end; end;
procedure get_the_current_clipboard_and_store_it() begin ... the_current_clipboard = get_the_current_clipboard; store_this_clipboard(the_current_clipboard); claim_ownership_on_this_clipboard (the_current_clipboard) and_if_i_lose_the_ownership_then(get_the_current_clipboard_and_store_it); ... end;This way, GNOME Clipboard Manager uses the event-model of X to know when it should get a new clipboard. X will inform it's clients when they lost the ownership of the CLIPBOARD. You can know if a new clipboard has been set by getting it each time you lose the ownership and then reclaim the ownership. Of course, for the PRIMARY clipboard this method is not very nice. Why not? Because then the selection will get unselected right after you selected it (think about it a few seconds and you will understand). Anyway, that is why I use a thread for the PRIMARY selection and the X-events for the CLIPBOARD selection.