Clipboard in Wayland (Sway Spin): How does it work?

Today I came across the “primary selection” / “clipboard selection” (in regard to Helix registers). I know it has its origin in X11 and it made me wonder whether my Wayland setup with the Sway Spin uses something like this, too. Which led me down a bit of a rabbit hole.

Things I came across:

  • There is wl-clipboard (I think installed by default), which comes with two command: wl-copy and wl-paste. I think it’s no integral part of Wayland and just some CLI utility to access the system clipboard (among other tools with the same purpose).
  • There is Clipman (I think installed by default), which is a “full” clipboard manager. Among other things, it allows for copied text to persist even if the source application closes.
  • ps aux tells me that wl-copy, wl-paste and clipman are running.
  • There are different ways to interact with the clipboard (or various clipboards). wl-copy and wl-paste are a CLI way to do it. Helix register commands another. Many applications have key combinations like CTRL+C and CTRL+V.

What I was not able to figure out:

  • What application or kind of application is starting the clipboard in the first place, thus making it possible for the other applications to do their clipboard work? Is it Sway? Is it the Linux kernel?
  • What application is starting the wl-copy/wl-paste and Clipman processes?
  • What does it even mean for wl-copy and wl-paste to run in the background?
  • If I copy something in (say) LibreOffice by pressing CTRL-C and I paste in (say) Firefox by selecting the option from the right-click menu, I think both are interacting with some “external” clipboard and not with each other?

I wasn’t able to figure out if these things are specific to Fedora Sway (a specific set of pre-installed applications), Sway, or just Wayland in general. I hope this thread isn’t completely off-topic.

In any case, thanks if you took the time to read this lengthy opening post or even to answer a question!

Based on my limited insight:

On a Wayland server, the clipboard is implemented according to the Wayland protocol. It is therefore the Wayland windows compositor that provides the clipboard. So yes, in your case, that will be Sway.

Nobody is except you, if you wish to install and use the program. wl-copy and wl-pasteare just third party tools we fortunatelly have, which allow to manipulate clipboard data from the command line.

The same applies for clipman, a clipboard manager that relies on wl-copy and wl-paste to do (part of) its work.

As soon as you put something on the clipboard with wl-paste, the clip is managed by a resident instance of wl-clipboard. It will return the clip when clipboard contents are requested (either by wl-copy or an application). That instance disappears when the clipboard is replaced (e.g. when copying something in a different program).

As far as I understand, it is the application that gives a pointer about the clipboard contents keeps the information in memory, in many cases in different formats. The system clipboard just points to that data. When the application quits, a (fraction of) that information (typically only the text/plain variant) is transferred to the system clipboard.