How do various apps and DEs handle the primary selection?

Jan-Marek Glogowski glogow at
Sun Jul 7 23:07:38 UTC 2019


I'm trying to gather information how various apps handle the primary selection,
so I can fix tdf#104717 [1]. There is already a patch for that in Gerrit[2].

The KDE applications I tested keep the primary alive, while they are running and
just clear it when they close. So I can select some text in kate and it'll stay
in the primary even, if I close the document containing the selected text.

AFAIK at least Writer, Calc and Draw use TransferableHelper::ClearSelection to
clear the selection. Writer clears the selection in many more places then either
Calc or Draw. See

$ git grep -B 5 -A 5 SwTransferable::ClearSelection sw

And Writer clears it when a Shell closes, while Calc (~ScTabView) and Draw
(:~View) clear it when the view is closed. But I'm a bit confused by the terms
Shell and View and then there is even a ViewShell...

IMHO we shouldn't handle the primary selection lifetime different from the
clipboard lifetime. When selecting stuff, the primary should stay alive, even if
I close the document or module, just like the normal clipboard. I don't see a
point of clearing the selection at all, except on application shutdown, when the
application won't be able to serve it anymore.

How do other applications you know handle the primary selection?


P.S. I use

$ watch -n 1 "xclip -selection clipboard -out; echo; xclip -selection primary -out"

to monitor the clibboard status. And if you want to test stuff, be sure to
disable clipboard managers, as these often copy stuff between the different
clipboards, also resulting in tdf#104717.


More information about the LibreOffice mailing list