What I meant is a sf::Clipboard::setText() function, sorry for not being clear. You say it takes time to set the clipboard's contents because one first has to get ownership of it, right? What I meant is that you don't immediately do that, but somewhere in the background. Is it not possible to get ownership of the window in a non-blocking way (i.e. asynchronously by requesting it and checking later whether we've already gotten it)?
Has somebody already measured how severe this delay is in practice?
I'm sorry for not being clear, too. Here's my attempt at being clear:
X11 has a thing called
selections. There are three notable ones:
PRIMARY,
SECONDARY and
CLIPBOARD. Most modern applications use the
CLIPBOARD selection.
To
obtain, or
get the
contents of the
CLIPBOARD selection, you must request a
conversion to the desired format to the X server, which forwards that request to
whoever owns the clipboard. Then,
whoever owns the clipboard checks if it's
even possible to convert the
selection to the requested format, and essentially responds directly to the requestor by sending them an event that contains information on the conversion as well as where to get the requested data. This response is usually very quick, so you can expect to receive it in less than one second and almost never miss it.
To
set the contents of the
CLIPBOARD selection, you
must request ownership of the selection. This is
immediate, as the X server does not wait for approval from the current owner to do this. You then update your cached contents of the clipboard, and you're done.
Actually, I lied. You're not done. You're the owner of the clipboard.
Once you own the clipboard, you need to
respond to
all incoming events requesting a
conversion (remember what I mentioned about getting the contents? We're the ones doing the conversion now). This is the main reason for which the function can't be blocking. These events need to be processed often enough that the requestor doesn't lock up waiting for the CLIPBOARD selection's contents (Google Chrome tabs will do this). This is being done in the processEvent function as of writing this.
There are no issues with performance with the current implementation, just look at the benchmarks I did.
The API we're using is completely fine. SDL and GLFW use it, and nobody has ever complained. Yes,
sf::Clipboard::setString() would be nice, but it's pushing things a lot and seriously not worth the effort just because someone isn't happy with SFML's API being
exactly the same as its competitors'.